Ben Alpert
12 years ago
18 changed files with 307 additions and 12 deletions
@ -0,0 +1,71 @@ |
|||||
|
--- |
||||
|
title: "Community Round-up #2" |
||||
|
layout: post |
||||
|
author: Vjeux |
||||
|
--- |
||||
|
|
||||
|
Since the launch we have received a lot of feedback and are actively working on React 0.4. In the meantime, here are the highlights of this week. |
||||
|
|
||||
|
## Some quick thoughts on React |
||||
|
|
||||
|
[Andrew Greig](http://www.andrewgreig.com/) made a blog post that gives a high level description of what React is. |
||||
|
|
||||
|
> I have been using Facebooks recently released Javascript framework called React.js for the last few days and have managed to obtain a rather high level understanding of how it works and formed a good perspective on how it fits in to the entire javascript framework ecosystem. |
||||
|
> |
||||
|
> Basically, React is not an MVC framework. It is not a replacement for Backbone or Knockout or Angular, instead it is designed to work with existing frameworks and help extend their functionality. |
||||
|
> |
||||
|
> It is designed for building big UIs. The type where you have lots of reusable components that are handling events and presenting and changing some backend data. In a traditional MVC app, React fulfils the role of the View. So you would still need to handle the Model and Controller on your own. |
||||
|
> |
||||
|
> I found the best way to utilise React was to pair it with Backbone, with React replacing the Backbone View, or to write your own Model/Data object and have React communicate with that. |
||||
|
> |
||||
|
> [Read the full post...](http://www.andrewgreig.com/637/) |
||||
|
|
||||
|
## React and Socket.IO Chat Application |
||||
|
|
||||
|
[Danial Khosravi](http://danialk.github.io/) made a real-time chat application that interacts with the back-end using Socket.IO. |
||||
|
|
||||
|
> A week ago I was playing with AngularJS and [this little chat application](https://github.com/btford/angular-socket-io-im) which uses socket.io and nodejs for realtime communication. Yesterday I saw a post about ReactJS in [EchoJS](http://www.echojs.com/) and started playing with this UI library. After playing a bit with React, I decided to write and chat application using React and I used Bran Ford's Backend for server side of this little app. |
||||
|
> <figure>[![](/react/img/blog/chatapp.png)](http://danialk.github.io/blog/2013/06/16/reactjs-and-socket-dot-io-chat-application/)</figure> |
||||
|
> |
||||
|
> [Read the full post...](http://danialk.github.io/blog/2013/06/16/reactjs-and-socket-dot-io-chat-application/) |
||||
|
|
||||
|
## React and Other Frameworks |
||||
|
|
||||
|
[Pete Hunt](http://www.petehunt.net/blog/) wrote an answer on Quora comparing React and Angular directives. At the end, he explains how you can make an Angular directive that is in fact being rendered with React. |
||||
|
|
||||
|
> To set the record straight: React components are far more powerful than Angular templates; they should be compared with Angular's directives instead. So I took the first Google hit for "AngularJS directive tutorial" (AngularJS Directives Tutorial - Fundoo Solutions), rewrote it in React and compared them. [...] |
||||
|
> |
||||
|
> We've designed React from the beginning to work well with other libraries. Angular is no exception. Let's take the original Angular example and use React to implement the fundoo-rating directive. |
||||
|
> |
||||
|
> [Read the full post...](http://www.quora.com/Pete-Hunt/Posts/Facebooks-React-vs-AngularJS-A-Closer-Look) |
||||
|
|
||||
|
In the same vein, [Markov Twain](https://twitter.com/markov_twain/status/345702941845499906) re-implemented the examples on the front-page [with Ember](http://jsbin.com/azihiw/2/edit) and [Vlad Yazhbin](https://twitter.com/vla) re-implemented the tutorial [with Angular](http://jsfiddle.net/vla/Cdrse/). |
||||
|
|
||||
|
## Web Components: React & x-tags |
||||
|
|
||||
|
Mozilla and Google are actively working on Web Components. [Vjeux](http://blog.vjeux.com/) wrote a proof of concept that shows how to implement them using React. |
||||
|
|
||||
|
> Using [x-tags](http://www.x-tags.org/) from Mozilla, we can write custom tags within the DOM. This is a great opportunity to be able to write reusable components without being tied to a particular library. I wrote [x-react](https://github.com/vjeux/react-xtags/) to have them being rendered in React. |
||||
|
> <figure>[![](/react/img/blog/xreact.png)](http://blog.vjeux.com/2013/javascript/custom-components-react-x-tags.html)</figure> |
||||
|
> |
||||
|
> [Read the full post...](http://blog.vjeux.com/2013/javascript/custom-components-react-x-tags.html) |
||||
|
|
||||
|
## React TodoMVC Example |
||||
|
|
||||
|
[TodoMVC.com](http://todomvc.com/) is a website that collects various implementations of the same basic Todo app. [Pete Hunt](http://www.petehunt.net/blog/) wrote an idiomatic React version. |
||||
|
|
||||
|
> Developers these days are spoiled with choice when it comes to selecting an MV* framework for structuring and organizing their JavaScript web apps. |
||||
|
> |
||||
|
> To help solve this problem, we created TodoMVC - a project which offers the same Todo application implemented using MV* concepts in most of the popular JavaScript MV* frameworks of today. |
||||
|
> <figure>[![](/react/img/blog/todomvc.png)](http://todomvc.com/labs/architecture-examples/react/)</figure> |
||||
|
> |
||||
|
> [Read the source code...](https://github.com/tastejs/todomvc/tree/gh-pages/labs/architecture-examples/react) |
||||
|
|
||||
|
## JSX is not HTML |
||||
|
|
||||
|
Many of you pointed out differences between JSX and HTML. In order to clear up some confusion, we have added some documentation that covers the four main differences: |
||||
|
|
||||
|
- [Whitespace removal](http://facebook.github.io/react/docs/jsx-is-not-html.html) |
||||
|
- [HTML Entities](http://facebook.github.io/react/docs/jsx-is-not-html.html) |
||||
|
- [Comments](http://facebook.github.io/react/docs/jsx-is-not-html.html) |
||||
|
- [Custom HTML Attributes](http://facebook.github.io/react/docs/jsx-is-not-html.html) |
@ -0,0 +1,24 @@ |
|||||
|
--- |
||||
|
title: "React v0.3.3" |
||||
|
layout: post |
||||
|
author: Paul O'Shannessy |
||||
|
--- |
||||
|
|
||||
|
We have a ton of great stuff coming in v0.4, but in the meantime we're releasing v0.3.3. This release addresses some small issues people were having and simplifies our tools to make them easier to use. |
||||
|
|
||||
|
|
||||
|
## react-tools |
||||
|
|
||||
|
* Upgrade Commoner so `require` statements are no longer relativized when passing through the transformer. This was a feature needed when building React, but doesn't translate well for other consumers of `bin/jsx`. |
||||
|
* Upgraded our dependencies on Commoner and Recast so they use a different directory for their cache. |
||||
|
* Freeze our esprima dependency. |
||||
|
|
||||
|
|
||||
|
## React |
||||
|
|
||||
|
* Allow reusing the same DOM node to render different components. e.g. `React.renderComponent(<div/>, domNode); React.renderComponent(<span/>, domNode);` will work now. |
||||
|
|
||||
|
|
||||
|
## JSXTransformer |
||||
|
|
||||
|
* Improved the in-browser transformer so that transformed scripts will execute in the expected scope. The allows components to be defined and used from separate files. |
@ -0,0 +1,91 @@ |
|||||
|
--- |
||||
|
title: "Community Round-up #3" |
||||
|
layout: post |
||||
|
author: Vjeux |
||||
|
--- |
||||
|
|
||||
|
The highlight of this week is that an interaction-heavy app has been ported to React. React components are solving issues they had with nested views. |
||||
|
|
||||
|
## Moving From Backbone To React |
||||
|
|
||||
|
[Clay Allsopp](http://twitter.com/clayallsopp) successfuly ported [Propeller](http://usepropeller.com/blog/posts/from-backbone-to-react/), a fairly big, interaction-heavy JavaScript app, to React. |
||||
|
|
||||
|
> [<img style="float: right; margin: 0 0 10px 10px;" src="/react/img/blog/propeller-logo.png" />](http://usepropeller.com/blog/posts/from-backbone-to-react/)Subviews involve a lot of easy-to-forget boilerplate that Backbone (by design) doesn't automate. Libraries like Backbone.Marionette offer more abstractions to make view nesting easier, but they're all limited by the fact that Backbone delegates how and went view-document attachment occurs to the application code. |
||||
|
> |
||||
|
> React, on the other hand, manages the DOM and only exposes real nodes at select points in its API. The "elements" you code in React are actually objects which wrap DOM nodes, not the actual objects which get inserted into the DOM. Internally, React converts those abstractions into actual DOMElements and fills out the document accordingly. [...] |
||||
|
> |
||||
|
> We moved about 20 different Backbone view classes to React over the past few weeks, including the live-preview pane that you see in our little iOS demo. Most importantly, it's allowed us to put energy into making each component work great on its own, instead of spending extra cycles to ensure they function in unison. For that reason, we think React is a more scalable way to build view-intensive apps than Backbone alone, and it doesn't require you to drop-everything-and-refactor like a move to Ember or Angular would demand. |
||||
|
> |
||||
|
> [Read the full post...](http://usepropeller.com/blog/posts/from-backbone-to-react/) |
||||
|
|
||||
|
## Grunt Task for JSX |
||||
|
|
||||
|
[Eric Clemmons](http://ericclemmons.github.io/) wrote a task for [Grunt](http://gruntjs.com/) that applies the JSX transformation to your Javascript files. It also works with [Browserify](http://browserify.org/) if you want all your files to be concatenated and minified together. |
||||
|
|
||||
|
> Grunt task for compiling Facebook React's .jsx templates into .js |
||||
|
> |
||||
|
> ```javascript |
||||
|
grunt.initConfig({ |
||||
|
react: { |
||||
|
app: { |
||||
|
options: { extension: 'js' }, |
||||
|
files: { 'path/to/output/dir': 'path/to/jsx/templates/dir' } |
||||
|
``` |
||||
|
> |
||||
|
> It also works great with `grunt-browserify`! |
||||
|
> |
||||
|
> ```javascript |
||||
|
browserify: { |
||||
|
options: { |
||||
|
transform: [ require('grunt-react').browserify ] |
||||
|
}, |
||||
|
app: { |
||||
|
src: 'path/to/source/main.js', |
||||
|
dest: 'path/to/target/output.js' |
||||
|
``` |
||||
|
> |
||||
|
> [Check out the project ...](https://github.com/ericclemmons/grunt-react) |
||||
|
|
||||
|
## Backbone/Handlebars Nested Views |
||||
|
|
||||
|
[Joel Burget](http://joelburget.com/) wrote a blog post talking about the way we would write React-like components in Backbone and Handlebars. |
||||
|
|
||||
|
> The problem here is that we're trying to maniplate a tree, but there's a textual layer we have to go through. Our views are represented as a tree - the subviews are children of CommentCollectionView - and they end up as part of a tree in the DOM. But there's a Handlebars layer in the middle (which deals in flat strings), so the hierarchy must be destructed and rebuilt when we render. |
||||
|
> |
||||
|
> What does it take to render a collection view? In the Backbone/Handlebars view of the world you have to render the template (with stubs), render each subview which replaces a stub, and keep a reference to each subview (or anything within the view that could change in the future). |
||||
|
> |
||||
|
> So while our view is conceptually hierarchical, due to the fact that it has to go through a flat textual representation, we need to do a lot of extra work to reassemble that structure after rendering. |
||||
|
> |
||||
|
> [Read the full post...](http://joelburget.com/react/) |
||||
|
|
||||
|
## JSRomandie Meetup |
||||
|
|
||||
|
[Renault John Lecoultre](https://twitter.com/renajohn/) from [BugBuster](http://www.bugbuster.com) did a React introduction talk at a JS meetup called [JS Romandie](https://twitter.com/jsromandie) last week. |
||||
|
|
||||
|
<script async class="speakerdeck-embed" data-id="888a9d50c01b01300df36658d0894ac1" data-ratio="1.33333333333333" src="//speakerdeck.com/assets/embed.js"></script> |
||||
|
|
||||
|
## CoffeeScript integration |
||||
|
|
||||
|
[Vjeux](http://blog.vjeux.com/) used the fact that JSX is just a syntactic sugar on-top of regular JS to rewrite the React front-page examples in CoffeeScript. |
||||
|
|
||||
|
> Multiple people asked what's the story about JSX and CoffeeScript. There is no JSX pre-processor for CoffeeScript and I'm not aware of anyone working on it. Fortunately, CoffeeScript is pretty expressive and we can play around the syntax to come up with something that is usable. |
||||
|
> |
||||
|
> ```javascript |
||||
|
{div, h3, textarea} = React.DOM |
||||
|
(div {className: 'MarkdownEditor'}, [ |
||||
|
(h3 {}, 'Input'), |
||||
|
(textarea {onKeyUp: @handleKeyUp, ref: 'textarea'}, |
||||
|
@state.value |
||||
|
) |
||||
|
]) |
||||
|
``` |
||||
|
> |
||||
|
> [Read the full post...](http://blog.vjeux.com/2013/javascript/react-coffeescript.html) |
||||
|
|
||||
|
## Tutorial in Plain Javascript |
||||
|
|
||||
|
We've seen a lot of people comparing React with various frameworks. [Ricardo Tomasi](http://ricardo.cc/) decided to re-implement the tutorial without any framework, just plain Javascript. |
||||
|
|
||||
|
> Facebook & Instagram launched the React framework and an accompanying tutorial. Developer Vlad Yazhbin decided to rewrite that using AngularJS. The end result is pretty neat, but if you're like me you will not actually appreciate the HTML speaking for itself and doing all the hard work. So let's see what that looks like in plain javascript. |
||||
|
> |
||||
|
> [Read the full post...](http://ricardo.cc/2013/06/07/react-tutorial-rewritten-in-plain-javascript.html) |
@ -0,0 +1,95 @@ |
|||||
|
--- |
||||
|
id: docs-jsx-is-not-html |
||||
|
title: JSX is not HTML |
||||
|
description: Differences between JSX and HTML. |
||||
|
layout: docs |
||||
|
prev: api.html |
||||
|
--- |
||||
|
|
||||
|
JSX looks like HTML but there are some important differences you may run into. |
||||
|
|
||||
|
## Whitespace removal |
||||
|
|
||||
|
JSX doesn't follow the same whitespace elimination rules as HTML. JSX removes all whitespace between two curly braces expressions. If you want to have whitespace, simply add `{' '}`. |
||||
|
|
||||
|
```javascript |
||||
|
<div>{this.props.name} {' '} {this.props.surname}</div> |
||||
|
``` |
||||
|
|
||||
|
Follow [Issue #65](https://github.com/facebook/react/issues/65) for discussion on this behavior. |
||||
|
|
||||
|
## HTML Entities |
||||
|
|
||||
|
You can insert HTML entities within literal text in JSX: |
||||
|
|
||||
|
```javascript |
||||
|
<div>First · Second</div> |
||||
|
``` |
||||
|
|
||||
|
If you want to display an HTML entity within dynamic content, you will run into double escaping issues as React escapes all the strings you are displaying in order to prevent a wide range of XSS attacks by default. |
||||
|
|
||||
|
```javascript |
||||
|
// Bad: It displays "First · Second" |
||||
|
<div>{'First · Second'}</div> |
||||
|
``` |
||||
|
|
||||
|
There are various ways to work-around this issue. The easiest one is to write unicode character directly in Javascript. You need to make sure that the file is saved as UTF-8 and that the proper UTF-8 directives are set so the browser will display it correctly. |
||||
|
|
||||
|
```javascript |
||||
|
<div>{'First · Second'}</div> |
||||
|
``` |
||||
|
|
||||
|
A safer alternative is to find the [unicode number corresponding to the entity](http://www.fileformat.info/info/unicode/char/b7/index.htm) and use it inside of a JavaScript string. |
||||
|
|
||||
|
```javascript |
||||
|
<div>{'First \u00b7 Second'}</div> |
||||
|
<div>{'First ' + String.fromCharCode(183) + ' Second'}</div> |
||||
|
``` |
||||
|
|
||||
|
You can use mixed arrays with strings and JSX elements. |
||||
|
|
||||
|
```javascript |
||||
|
<div>{['First ', <span>·</span>, ' Second']}</div> |
||||
|
``` |
||||
|
|
||||
|
As a last resort, you always have the ability to insert raw HTML. |
||||
|
|
||||
|
```javascript |
||||
|
<div dangerouslySetInnerHTML={{'{{'}}__html: 'First · Second'}} /> |
||||
|
``` |
||||
|
|
||||
|
## Comments |
||||
|
|
||||
|
JSX supports both single-line and multi-line JavaScript comments within a tag declaration: |
||||
|
|
||||
|
```javascript |
||||
|
<div // This is a single-line comment: |
||||
|
/* |
||||
|
And a multi-line |
||||
|
comment |
||||
|
*/ |
||||
|
/> |
||||
|
``` |
||||
|
|
||||
|
As of React 0.3, there is no good way to insert comments within the children section. [Issue #82](https://github.com/facebook/react/issues/82) is tracking progress to enable the following: |
||||
|
|
||||
|
```javascript |
||||
|
// Note: This is not implemented yet! |
||||
|
<div> |
||||
|
{/* This is a comment */} |
||||
|
</div> |
||||
|
``` |
||||
|
|
||||
|
## Custom HTML Attributes |
||||
|
|
||||
|
If you pass properties to native HTML elements that do not exist in the HTML specification, React will not render them. If you want to use a custom attribute, you should prefix it with `data-`. |
||||
|
|
||||
|
```javascript |
||||
|
<div data-custom-attribute="foo" /> |
||||
|
``` |
||||
|
|
||||
|
[Web Accessibility](http://www.w3.org/WAI/intro/aria) attributes starting with `aria-` will be rendered properly. |
||||
|
|
||||
|
```javascript |
||||
|
<div aria-hidden={true} /> |
||||
|
``` |
After Width: | Height: | Size: 27 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 51 KiB |
After Width: | Height: | Size: 7.7 KiB |
Loading…
Reference in new issue