diff --git a/_includes/nav_docs.html b/_includes/nav_docs.html index d6d9e945..1dbd3b5c 100644 --- a/_includes/nav_docs.html +++ b/_includes/nav_docs.html @@ -21,4 +21,11 @@
  • API
  • + + diff --git a/_layouts/docs.html b/_layouts/docs.html index 8df30790..ff0b835a 100644 --- a/_layouts/docs.html +++ b/_layouts/docs.html @@ -20,6 +20,6 @@ sectionid: docs {% endif %} -
    +
    diff --git a/_layouts/post.html b/_layouts/post.html index 656085dc..9aa96b35 100644 --- a/_layouts/post.html +++ b/_layouts/post.html @@ -16,6 +16,6 @@ sectionid: blog
    -
    +
    diff --git a/_posts/2013-06-12-community-roundup.md b/_posts/2013-06-12-community-roundup.md index f5e63a09..d37e3b13 100644 --- a/_posts/2013-06-12-community-roundup.md +++ b/_posts/2013-06-12-community-roundup.md @@ -8,14 +8,14 @@ React was open sourced two weeks ago and it's time for a little round-up of what ## Khan Academy Question Editor -It looks like [Ben Alpert](http://benalpert.com/) is the first person outside of Facebook and Instagram to push React code to production. We are very grateful for his contributions in form of pull requests, bug reports and presence on IRC ([#reactjs on Freenode](irc://chat.freenode.net/reactjs)). Ben wrote about his experience using React on Quora: +It looks like [Ben Alpert](http://benalpert.com/) is the first person outside of Facebook and Instagram to push React code to production. We are very grateful for his contributions in form of pull requests, bug reports and presence on IRC ([#reactjs on Freenode](irc://chat.freenode.net/reactjs)). Ben wrote about his experience using React: > I just rewrote a 2000-line project in React and have now made a handful of pull requests to React. Everything about React I've seen so far seems really well thought-out and I'm proud to be the first non-FB/IG production user of React. > > The project that I rewrote in React (and am continuing to improve) is the Khan Academy question editor which content creators can use to enter questions and hints that will be presented to students: ->
    [![](/react/img/blog/khan-academy-editor.png)](http://www.quora.com/React-JS-Library/How-is-Facebooks-React-JavaScript-library/answer/Ben-Alpert)
    +>
    [![](/react/img/blog/khan-academy-editor.png)](http://benalpert.com/2013/06/09/using-react-to-speed-up-khan-academy.html)
    > -> [Read the full post...](http://www.quora.com/React-JS-Library/How-is-Facebooks-React-JavaScript-library/answer/Ben-Alpert) +> [Read the full post...](http://benalpert.com/2013/06/09/using-react-to-speed-up-khan-academy.html) ## Pimp my Backbone.View (by replacing it with React) diff --git a/_posts/2013-06-19-community-roundup-2.md b/_posts/2013-06-19-community-roundup-2.md new file mode 100644 index 00000000..57b322e1 --- /dev/null +++ b/_posts/2013-06-19-community-roundup-2.md @@ -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. +>
    [![](/react/img/blog/chatapp.png)](http://danialk.github.io/blog/2013/06/16/reactjs-and-socket-dot-io-chat-application/)
    +> +> [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. +>
    [![](/react/img/blog/xreact.png)](http://blog.vjeux.com/2013/javascript/custom-components-react-x-tags.html)
    +> +> [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. +>
    [![](/react/img/blog/todomvc.png)](http://todomvc.com/labs/architecture-examples/react/)
    +> +> [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) diff --git a/_posts/2013-06-21-react-v0-3-3.md b/_posts/2013-06-21-react-v0-3-3.md new file mode 100644 index 00000000..668c83de --- /dev/null +++ b/_posts/2013-06-21-react-v0-3-3.md @@ -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(
    , domNode); React.renderComponent(, 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. diff --git a/_posts/2013-06-27-community-roundup-3.md b/_posts/2013-06-27-community-roundup-3.md new file mode 100644 index 00000000..50fed079 --- /dev/null +++ b/_posts/2013-06-27-community-roundup-3.md @@ -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. + +> [](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. + + + +## 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) diff --git a/docs/api.md b/docs/api.md index 1ae5e97b..337ae869 100644 --- a/docs/api.md +++ b/docs/api.md @@ -3,6 +3,7 @@ id: docs-api title: React API layout: docs prev: mixins.html +next: jsx-is-not-html.html --- ## React diff --git a/docs/component-lifecycle.md b/docs/component-lifecycle.md index 1998f180..8861c187 100644 --- a/docs/component-lifecycle.md +++ b/docs/component-lifecycle.md @@ -22,7 +22,7 @@ In this one simple line, we have accomplished the following: - The component is **mounted** into `document.body`. **Mounting** is the process of initializing a React component by creating its -DOM nodes and inserting the them into a supplied container node. +DOM nodes and inserting them into a supplied container node. At this point, the entire page consists of a single `
    ` with "Hello, world!". diff --git a/docs/getting-started.md b/docs/getting-started.md index 5b732c03..1e62818e 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -88,6 +88,10 @@ React.renderComponent( ); ``` +> Note: +> +> The comment parser is very strict right now, in order for it to pick up the `@jsx` modifier, two conditions are required. The `@jsx` comment block must be the first comment on the file. The comment must start with `/**` (`/*` and `//` will not work). If the parser can't find the `@jsx` comment, it will output the file without transforming it. + Update your HTML file as below: ```html{6,10} diff --git a/docs/jsx-is-not-html.md b/docs/jsx-is-not-html.md new file mode 100644 index 00000000..42013e91 --- /dev/null +++ b/docs/jsx-is-not-html.md @@ -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 +
    {this.props.name} {' '} {this.props.surname}
    +``` + +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 +
    First · Second
    +``` + +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" +
    {'First · Second'}
    +``` + +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 +
    {'First ยท Second'}
    +``` + +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 +
    {'First \u00b7 Second'}
    +
    {'First ' + String.fromCharCode(183) + ' Second'}
    +``` + +You can use mixed arrays with strings and JSX elements. + +```javascript +
    {['First ', ·, ' Second']}
    +``` + +As a last resort, you always have the ability to insert raw HTML. + +```javascript +
    +``` + +## Comments + +JSX supports both single-line and multi-line JavaScript comments within a tag declaration: + +```javascript +
    +``` + +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! +
    + {/* This is a comment */} +
    +``` + +## 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 +
    +``` + +[Web Accessibility](http://www.w3.org/WAI/intro/aria) attributes starting with `aria-` will be rendered properly. + +```javascript +
    +``` diff --git a/docs/syntax.md b/docs/syntax.md index e4b099bd..bb477e9a 100644 --- a/docs/syntax.md +++ b/docs/syntax.md @@ -53,7 +53,7 @@ var app = Nav({color:'blue'}, Profile({}, 'click')); ``` Use the [JSX Compiler](/react/jsx-compiler.html) to try out JSX and see how it -desguars into native JavaScript. +desugars into native JavaScript. If you want to use JSX, the [Getting Started](getting-started.html) guide shows how to setup compilation. diff --git a/docs/tutorial.md b/docs/tutorial.md index 8117b2ba..021ff505 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -262,8 +262,8 @@ So far we've been inserting the comments directly in the source code. Instead, l ```javascript // tutorial8.js var data = [ - {author: 'Pete Hunt', text: 'This is one comment'}, - {author: 'Jordan Walke', text: 'This is *another* comment'} + {author: "Pete Hunt", text: "This is one comment"}, + {author: "Jordan Walke", text: "This is *another* comment"} ]; ``` @@ -357,8 +357,8 @@ When the component is first created, we want to GET some JSON from the server an ```javascript // tutorial13.json [ - {'author': 'Pete Hunt', 'text': 'This is one comment'}, - {'author': 'Jordan Walke', 'text': 'This is *another* comment'} + {"author": "Pete Hunt", "text": "This is one comment"}, + {"author": "Jordan Walke", "text": "This is *another* comment"} ] ``` @@ -435,7 +435,7 @@ React.renderComponent( ``` -All we have done here is move the AJAX call to a separate method and call it when the component is first loaded and every 60 seconds after that. Try running this in your browser and changing the `comments.json` file; within 5 seconds, the changes will show! +All we have done here is move the AJAX call to a separate method and call it when the component is first loaded and every 5 seconds after that. Try running this in your browser and changing the `comments.json` file; within 5 seconds, the changes will show! ## Adding new comments diff --git a/downloads.md b/downloads.md index d35ff4db..2b2a9ad5 100644 --- a/downloads.md +++ b/downloads.md @@ -49,6 +49,8 @@ $ npm install -g react-tools ## Release Notes +**0.3.3** Upgrade `react-tools` dependencies, improve in-browser JSX transformer, make `React.renderComponent` more versatile. [Details...](blog/2013/06/20/react-v0-3-3.html) + **0.3.2** Improve compatibility of JSX Transformer; make `react-tools` compatible with [browserify](https://github.com/substack/node-browserify) **0.3.1** Fix `react-tools` module diff --git a/img/blog/chatapp.png b/img/blog/chatapp.png new file mode 100644 index 00000000..55edf29d Binary files /dev/null and b/img/blog/chatapp.png differ diff --git a/img/blog/propeller-logo.png b/img/blog/propeller-logo.png new file mode 100644 index 00000000..1573d715 Binary files /dev/null and b/img/blog/propeller-logo.png differ diff --git a/img/blog/todomvc.png b/img/blog/todomvc.png new file mode 100644 index 00000000..9c03bc0f Binary files /dev/null and b/img/blog/todomvc.png differ diff --git a/img/blog/xreact.png b/img/blog/xreact.png new file mode 100644 index 00000000..59fbb6f2 Binary files /dev/null and b/img/blog/xreact.png differ