diff --git a/blog/2013/06/02/jsfiddle-integration.html b/blog/2013/06/02/jsfiddle-integration.html index d22b1262b4f3c..84166e66591e2 100644 --- a/blog/2013/06/02/jsfiddle-integration.html +++ b/blog/2013/06/02/jsfiddle-integration.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/06/05/why-react.html b/blog/2013/06/05/why-react.html index 6e282cc93032c..b47816a895c1b 100644 --- a/blog/2013/06/05/why-react.html +++ b/blog/2013/06/05/why-react.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/06/12/community-roundup.html b/blog/2013/06/12/community-roundup.html index cbe1a610a8b3f..83150e3fb24e5 100644 --- a/blog/2013/06/12/community-roundup.html +++ b/blog/2013/06/12/community-roundup.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/06/19/community-roundup-2.html b/blog/2013/06/19/community-roundup-2.html index ccc1f643afed8..9b4eebb94bee8 100644 --- a/blog/2013/06/19/community-roundup-2.html +++ b/blog/2013/06/19/community-roundup-2.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/06/21/react-v0-3-3.html b/blog/2013/06/21/react-v0-3-3.html index 0c4d98cf51df0..a57345fa00d4b 100644 --- a/blog/2013/06/21/react-v0-3-3.html +++ b/blog/2013/06/21/react-v0-3-3.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/06/27/community-roundup-3.html b/blog/2013/06/27/community-roundup-3.html index 039b4f23bde57..07f1f686ccf7b 100644 --- a/blog/2013/06/27/community-roundup-3.html +++ b/blog/2013/06/27/community-roundup-3.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/07/02/react-v0-4-autobind-by-default.html b/blog/2013/07/02/react-v0-4-autobind-by-default.html index baac57030eb18..d23dbc7ad4f4e 100644 --- a/blog/2013/07/02/react-v0-4-autobind-by-default.html +++ b/blog/2013/07/02/react-v0-4-autobind-by-default.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/07/03/community-roundup-4.html b/blog/2013/07/03/community-roundup-4.html index de42fa8bce79e..581b37e351029 100644 --- a/blog/2013/07/03/community-roundup-4.html +++ b/blog/2013/07/03/community-roundup-4.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/07/11/react-v0-4-prop-validation-and-default-values.html b/blog/2013/07/11/react-v0-4-prop-validation-and-default-values.html index 725da74e782e0..a3b308b042049 100644 --- a/blog/2013/07/11/react-v0-4-prop-validation-and-default-values.html +++ b/blog/2013/07/11/react-v0-4-prop-validation-and-default-values.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/07/17/react-v0-4-0.html b/blog/2013/07/17/react-v0-4-0.html index 9798dfc70113c..7875dd0161569 100644 --- a/blog/2013/07/17/react-v0-4-0.html +++ b/blog/2013/07/17/react-v0-4-0.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/07/23/community-roundup-5.html b/blog/2013/07/23/community-roundup-5.html index dbee7a27a8e7c..cfc231f9f6029 100644 --- a/blog/2013/07/23/community-roundup-5.html +++ b/blog/2013/07/23/community-roundup-5.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/07/26/react-v0-4-1.html b/blog/2013/07/26/react-v0-4-1.html index ab48193a04eaa..243a342ca62a6 100644 --- a/blog/2013/07/26/react-v0-4-1.html +++ b/blog/2013/07/26/react-v0-4-1.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/07/30/use-react-and-jsx-in-ruby-on-rails.html b/blog/2013/07/30/use-react-and-jsx-in-ruby-on-rails.html index d08e6c6ca7148..b2910f720d229 100644 --- a/blog/2013/07/30/use-react-and-jsx-in-ruby-on-rails.html +++ b/blog/2013/07/30/use-react-and-jsx-in-ruby-on-rails.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/08/05/community-roundup-6.html b/blog/2013/08/05/community-roundup-6.html index 4b19a103ca8f7..585deaae84453 100644 --- a/blog/2013/08/05/community-roundup-6.html +++ b/blog/2013/08/05/community-roundup-6.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/08/19/use-react-and-jsx-in-python-applications.html b/blog/2013/08/19/use-react-and-jsx-in-python-applications.html index 190b164282cb2..2ee4eddcc4ba4 100644 --- a/blog/2013/08/19/use-react-and-jsx-in-python-applications.html +++ b/blog/2013/08/19/use-react-and-jsx-in-python-applications.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/08/26/community-roundup-7.html b/blog/2013/08/26/community-roundup-7.html index 80e0460eb80f2..efcc9ce6a8186 100644 --- a/blog/2013/08/26/community-roundup-7.html +++ b/blog/2013/08/26/community-roundup-7.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/09/24/community-roundup-8.html b/blog/2013/09/24/community-roundup-8.html index 08bc49f15f911..faca9ced58b7d 100644 --- a/blog/2013/09/24/community-roundup-8.html +++ b/blog/2013/09/24/community-roundup-8.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/10/03/community-roundup-9.html b/blog/2013/10/03/community-roundup-9.html index 1e92b2fb38e2f..94ae33d6e0834 100644 --- a/blog/2013/10/03/community-roundup-9.html +++ b/blog/2013/10/03/community-roundup-9.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/10/16/react-v0.5.0.html b/blog/2013/10/16/react-v0.5.0.html index c376ccdd78b97..66d84f7077d59 100644 --- a/blog/2013/10/16/react-v0.5.0.html +++ b/blog/2013/10/16/react-v0.5.0.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/10/29/react-v0-5-1.html b/blog/2013/10/29/react-v0-5-1.html index c24a66aa92b54..1bf21108c302f 100644 --- a/blog/2013/10/29/react-v0-5-1.html +++ b/blog/2013/10/29/react-v0-5-1.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/11/05/thinking-in-react.html b/blog/2013/11/05/thinking-in-react.html index 8e3c0c2f4572f..b03464647321e 100644 --- a/blog/2013/11/05/thinking-in-react.html +++ b/blog/2013/11/05/thinking-in-react.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/11/06/community-roundup-10.html b/blog/2013/11/06/community-roundup-10.html index 61f2d30772fd1..362c424946615 100644 --- a/blog/2013/11/06/community-roundup-10.html +++ b/blog/2013/11/06/community-roundup-10.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/11/18/community-roundup-11.html b/blog/2013/11/18/community-roundup-11.html index 079511282032d..942feef9abb87 100644 --- a/blog/2013/11/18/community-roundup-11.html +++ b/blog/2013/11/18/community-roundup-11.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/12/18/react-v0.5.2-v0.4.2.html b/blog/2013/12/18/react-v0.5.2-v0.4.2.html index bd921fd3cdc4e..8fac6718fcb07 100644 --- a/blog/2013/12/18/react-v0.5.2-v0.4.2.html +++ b/blog/2013/12/18/react-v0.5.2-v0.4.2.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/12/19/react-v0.8.0.html b/blog/2013/12/19/react-v0.8.0.html index d8994ee42bba7..d39b6204b52ae 100644 --- a/blog/2013/12/19/react-v0.8.0.html +++ b/blog/2013/12/19/react-v0.8.0.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/12/23/community-roundup-12.html b/blog/2013/12/23/community-roundup-12.html index 9c436666df8d8..8d1e5c04c62ae 100644 --- a/blog/2013/12/23/community-roundup-12.html +++ b/blog/2013/12/23/community-roundup-12.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/12/30/community-roundup-13.html b/blog/2013/12/30/community-roundup-13.html new file mode 100644 index 0000000000000..ff24329ba5855 --- /dev/null +++ b/blog/2013/12/30/community-roundup-13.html @@ -0,0 +1,216 @@ + + + + + + React | Community Round-up #13 + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+ + +
+

Community Round-up #13

+

December 30, 2013 by Vjeux

+ +
+ +
+

Happy holidays! This blog post is a little-late Christmas present for all the React users. Hopefully it will inspire you to write awesome web apps in 2014!

+

React Touch #

+

Pete Hunt wrote three demos showing that React can be used to run 60fps native-like experiences on mobile web. A frosted glass effect, an image gallery with 3d animations and an infinite scroll view.

+ +
+ +

Try out the demos!

+

Introduction to React #

+

Stoyan Stefanov talked at Joe Dev On Tech about React. He goes over all the features of the library and ends with a concrete example.

+ +
+

JSX: E4X The Good Parts #

+

JSX is often compared to the now defunct E4X, Vjeux went over all the E4X features and explained how JSX is different and hopefully doesn't repeat the same mistakes.

+ +
+

E4X (ECMAScript for XML) is a Javascript syntax extension and a runtime to manipulate XML. It was promoted by Mozilla but failed to become mainstream and is now deprecated. JSX was inspired by E4X. In this article, I'm going to go over all the features of E4X and explain the design decisions behind JSX.

+ +

Historical Context

+ +

E4X has been created in 2002 by John Schneider. This was the golden age of XML where it was being used for everything: data, configuration files, code, interfaces (DOM) ... E4X was first implemented inside of Rhino, a Javascript implementation from Mozilla written in Java.

+ +

Continue reading ...

+
+

React + Socket.io #

+

Geert Pasteels made a small experiment with Socket.io. He wrote a very small mixin that synchronizes React state with the server. Just include this mixin to your React component and it is now live!

+
changeHandler: function (data) {
+  if (!_.isEqual(data.state, this.state) && this.path === data.path) {
+    this.setState(data.state);
+  }
+},
+componentDidMount: function (root) {
+  this.path = utils.nodePath(root);
+  socket.on('component-change', this.changeHandler);
+},
+componentWillUpdate: function (props, state) {
+  socket.emit('component-change', { path: this.path, state: state });
+},
+componentWillUnmount: function () {
+  socket.removeListener('component-change', this.change);
+}
+
+

Check it out on GitHub...

+

cssobjectify #

+

Andrey Popp implemented a source transform that takes a CSS file and converts it to JSON. This integrates pretty nicely with React.

+
/* style.css */
+MyComponent {
+  font-size: 12px;
+  background-color: red;
+}
+
+/* myapp.js */
+var React = require('react-tools/build/modules/React');
+var Styles = require('./styles.css');
+
+var MyComponent = React.createClass({
+  render: function() {
+    return (
+      <div style={Styles.MyComponent}>
+        Hello, world!
+      </div>
+    )
+  }
+});
+
+

Check it out on GitHub...

+

ngReact #

+

David Chang working at HasOffer wanted to speed up his Angular app and replaced Angular primitives by React at different layers. When using React naively it is 67% faster, but when combining it with angular's transclusion it is 450% slower.

+ +
+

Rendering this takes 803ms for 10 iterations, hovering around 35 and 55ms for each data reload (that's 67% faster). You'll notice that the first load takes a little longer than successive loads, and the second load REALLY struggles - here, it's 433ms, which is more than half of the total time! +

+ +

Read the full article...

+
+

vim-jsx #

+

Max Wang made a vim syntax highlighting and indentation plugin for vim.

+ +
+

Syntax highlighting and indenting for JSX. JSX is a JavaScript syntax transformer which translates inline XML document fragments into JavaScript objects. It was developed by Facebook alongside React.

+ +

This bundle requires pangloss's vim-javascript syntax highlighting.

+ +

Vim support for inline XML in JS is remarkably similar to the same for PHP.

+ +

View on GitHub...

+
+

Random Tweet #

+

+ +
+ +
+
+
+
+ + + +
+
+ + + + diff --git a/blog/all.html b/blog/all.html index 8efcac714483b..114aed303d619 100644 --- a/blog/all.html +++ b/blog/all.html @@ -56,6 +56,8 @@

All Posts

+

Community Round-up #13 on December 30, 2013 by Vjeux

+

Community Round-up #12 on December 23, 2013 by Vjeux

React v0.8 on December 19, 2013 by Paul O'Shannessy

diff --git a/blog/index.html b/blog/index.html index caaeb3947ac44..50457c4403d0e 100644 --- a/blog/index.html +++ b/blog/index.html @@ -58,6 +58,8 @@

Recent posts

@@ -85,6 +85,103 @@

Recent posts

+
+

Community Round-up #13

+

December 30, 2013 by Vjeux

+
+
+

Happy holidays! This blog post is a little-late Christmas present for all the React users. Hopefully it will inspire you to write awesome web apps in 2014!

+

React Touch #

+

Pete Hunt wrote three demos showing that React can be used to run 60fps native-like experiences on mobile web. A frosted glass effect, an image gallery with 3d animations and an infinite scroll view.

+ +
+ +

Try out the demos!

+

Introduction to React #

+

Stoyan Stefanov talked at Joe Dev On Tech about React. He goes over all the features of the library and ends with a concrete example.

+ +
+

JSX: E4X The Good Parts #

+

JSX is often compared to the now defunct E4X, Vjeux went over all the E4X features and explained how JSX is different and hopefully doesn't repeat the same mistakes.

+ +
+

E4X (ECMAScript for XML) is a Javascript syntax extension and a runtime to manipulate XML. It was promoted by Mozilla but failed to become mainstream and is now deprecated. JSX was inspired by E4X. In this article, I'm going to go over all the features of E4X and explain the design decisions behind JSX.

+ +

Historical Context

+ +

E4X has been created in 2002 by John Schneider. This was the golden age of XML where it was being used for everything: data, configuration files, code, interfaces (DOM) ... E4X was first implemented inside of Rhino, a Javascript implementation from Mozilla written in Java.

+ +

Continue reading ...

+
+

React + Socket.io #

+

Geert Pasteels made a small experiment with Socket.io. He wrote a very small mixin that synchronizes React state with the server. Just include this mixin to your React component and it is now live!

+
changeHandler: function (data) {
+  if (!_.isEqual(data.state, this.state) && this.path === data.path) {
+    this.setState(data.state);
+  }
+},
+componentDidMount: function (root) {
+  this.path = utils.nodePath(root);
+  socket.on('component-change', this.changeHandler);
+},
+componentWillUpdate: function (props, state) {
+  socket.emit('component-change', { path: this.path, state: state });
+},
+componentWillUnmount: function () {
+  socket.removeListener('component-change', this.change);
+}
+
+

Check it out on GitHub...

+

cssobjectify #

+

Andrey Popp implemented a source transform that takes a CSS file and converts it to JSON. This integrates pretty nicely with React.

+
/* style.css */
+MyComponent {
+  font-size: 12px;
+  background-color: red;
+}
+
+/* myapp.js */
+var React = require('react-tools/build/modules/React');
+var Styles = require('./styles.css');
+
+var MyComponent = React.createClass({
+  render: function() {
+    return (
+      <div style={Styles.MyComponent}>
+        Hello, world!
+      </div>
+    )
+  }
+});
+
+

Check it out on GitHub...

+

ngReact #

+

David Chang working at HasOffer wanted to speed up his Angular app and replaced Angular primitives by React at different layers. When using React naively it is 67% faster, but when combining it with angular's transclusion it is 450% slower.

+ +
+

Rendering this takes 803ms for 10 iterations, hovering around 35 and 55ms for each data reload (that's 67% faster). You'll notice that the first load takes a little longer than successive loads, and the second load REALLY struggles - here, it's 433ms, which is more than half of the total time! +

+ +

Read the full article...

+
+

vim-jsx #

+

Max Wang made a vim syntax highlighting and indentation plugin for vim.

+ +
+

Syntax highlighting and indenting for JSX. JSX is a JavaScript syntax transformer which translates inline XML document fragments into JavaScript objects. It was developed by Facebook alongside React.

+ +

This bundle requires pangloss's vim-javascript syntax highlighting.

+ +

Vim support for inline XML in JS is remarkably similar to the same for PHP.

+ +

View on GitHub...

+
+

Random Tweet #

+

+ +
+
+

Community Round-up #12

December 23, 2013 by Vjeux

@@ -315,123 +412,6 @@

Random Tweet

-
-

Community Round-up #10

-

November 6, 2013 by Vjeux

-
-
-

This is the 10th round-up already and React has come quite far since it was open sourced. Almost all new web projects at Khan Academy, Facebook, and Instagram are being developed using React. React has been deployed in a variety of contexts: a Chrome extension, a Windows 8 application, mobile websites, and desktop websites supporting Internet Explorer 8! Language-wise, React is not only being used within JavaScript but also CoffeeScript and ClojureScript.

- -

The best part is that no drastic changes have been required to support all those use cases. Most of the efforts were targeted at polishing edge cases, performance improvements, and documentation.

-

Khan Academy - Officially moving to React #

-

Joel Burget announced at Hack Reactor that new front-end code at Khan Academy should be written in React!

- -
-

How did we get the rest of the team to adopt React? Using interns as an attack vector! Most full-time devs had already been working on their existing projects for a while and weren't looking to try something new at the time, but our class of summer interns was just arriving. For whatever reason, a lot of them decided to try React for their projects. Then mentors became exposed through code reviews or otherwise touching the new code. In this way React knowledge diffused to almost the whole team over the summer.

- -

Since the first React checkin on June 5, we've somehow managed to accumulate 23500 lines of jsx (React-flavored js) code. Which is terrifying in a way - that's a lot of code - but also really exciting that it was picked up so quickly.

- -

We held three meetings about how we should proceed with React. At the first two we decided to continue experimenting with React and deferred a final decision on whether to adopt it. At the third we adopted the policy that new code should be written in React.

- -

I'm excited that we were able to start nudging code quality forward. However, we still have a lot of work to do! One of the selling points of this transition is adopting a uniform frontend style. We're trying to upgrade all the code from (really old) pure jQuery and (regular old) Backbone views / Handlebars to shiny React. At the moment all we've done is introduce more fragmentation. We won't be gratuitously updating working code (if it ain't broke, don't fix it), but are seeking out parts of the codebase where we can shoot two birds with one stone by rewriting in React while fixing bugs or adding functionality.

- -

Read the full article

-
-

React: Rethinking best practices #

-

Pete Hunt's talk at JSConf EU 2013 is now available in video.

- -
-

Server-side React with PHP #

-

Stoyan Stefanov's series of articles on React has two new entries on how to execute React on the server to generate the initial page load.

- -
-

This post is an initial hack to have React components render server-side in PHP.

- -
    -
  • Problem: Build web UIs
  • -
  • Solution: React
  • -
  • Problem: UI built in JS is anti-SEO (assuming search engines are still noscript) and bad for perceived performance (blank page till JS arrives)
  • -
  • Solution: React page to render the first view
  • -
  • Problem: Can't host node.js apps / I have tons of PHP code
  • -
  • Solution: Use PHP then!
  • -
- -

Read part 1 ...

- -

Read part 2 ...

- -

Rendered markup on the server: -

-
-

TodoMVC Benchmarks #

-

Webkit has a TodoMVC Benchmark that compares different frameworks. They recently included React and here are the results (average of 10 runs in Chrome 30):

- -
    -
  • AngularJS: 4043ms
  • -
  • AngularJSPerf: 3227ms
  • -
  • BackboneJS: 1874ms
  • -
  • EmberJS: 6822ms
  • -
  • jQuery: 14628ms
  • -
  • React: 2864ms
  • -
  • VanillaJS: 5567ms
  • -
- -

Try it yourself!

- -

Please don't take those numbers too seriously, they only reflect one very specific use case and are testing code that wasn't written with performance in mind.

- -

Even though React scores as one of the fastest frameworks in the benchmark, the React code is simple and idiomatic. The only performance tweak used is the following function:

-
/**
- * This is a completely optional performance enhancement that you can implement
- * on any React component. If you were to delete this method the app would still
- * work correctly (and still be very performant!), we just use it as an example
- * of how little code it takes to get an order of magnitude performance improvement.
- */
-shouldComponentUpdate: function (nextProps, nextState) {
-  return (
-    nextProps.todo.id !== this.props.todo.id ||
-    nextProps.todo !== this.props.todo ||
-    nextProps.editing !== this.props.editing ||
-    nextState.editText !== this.state.editText
-  );
-},
-
-

By default, React "re-renders" all the components when anything changes. This is usually fast enough that you don't need to care. However, you can provide a function that can tell whether there will be any change based on the previous and next states and props. If it is faster than re-rendering the component, then you get a performance improvement.

- -

The fact that you can control when components are rendered is a very important characteristic of React as it gives you control over its performance. We are going to talk more about performance in the future, stay tuned.

-

Guess the filter #

-

Connor McSheffrey implemented a small game using React. The goal is to guess which filter has been used to create the Instagram photo. -

-

React vs FruitMachine #

-

Andrew Betts, director of the Financial Times Labs, posted an article comparing FruitMachine and React.

- -
-

Eerily similar, no? Maybe Facebook was inspired by Fruit Machine (after all, we got there first), but more likely, it just shows that this is a pretty decent way to solve the problem, and great minds think alike. We're graduating to a third phase in the evolution of web best practice - from intermingling of markup, style and behaviour, through a phase in which those concerns became ever more separated and encapsulated, and finally to a model where we can do that separation at a component level. Developments like Web Components show the direction the web community is moving, and frameworks like React and Fruit Machine are in fact not a lot more than polyfills for that promised behaviour to come.

- -

Read the full article...

-
- -

Even though we weren't inspired by FruitMachine (React has been used in production since before FruitMachine was open sourced), it's great to see similar technologies emerging and becoming popular.

-

React Brunch #

-

Matthew McCray implemented react-brunch, a JSX compilation step for Brunch.

- -
-

Adds React support to brunch by automatically compiling *.jsx files.

- -

You can configure react-brunch to automatically insert a react header (/** @jsx React.DOM */) into all *.jsx files. Disabled by default.

- -

Install the plugin via npm with npm install --save react-brunch.

- -

Read more...

-
-

Random Tweet #

-

I'm going to start adding a tweet at the end of each round-up. We'll start with this one:

- - - -
-
- @@ -85,6 +85,123 @@

Recent posts

+
+

Community Round-up #10

+

November 6, 2013 by Vjeux

+
+
+

This is the 10th round-up already and React has come quite far since it was open sourced. Almost all new web projects at Khan Academy, Facebook, and Instagram are being developed using React. React has been deployed in a variety of contexts: a Chrome extension, a Windows 8 application, mobile websites, and desktop websites supporting Internet Explorer 8! Language-wise, React is not only being used within JavaScript but also CoffeeScript and ClojureScript.

+ +

The best part is that no drastic changes have been required to support all those use cases. Most of the efforts were targeted at polishing edge cases, performance improvements, and documentation.

+

Khan Academy - Officially moving to React #

+

Joel Burget announced at Hack Reactor that new front-end code at Khan Academy should be written in React!

+ +
+

How did we get the rest of the team to adopt React? Using interns as an attack vector! Most full-time devs had already been working on their existing projects for a while and weren't looking to try something new at the time, but our class of summer interns was just arriving. For whatever reason, a lot of them decided to try React for their projects. Then mentors became exposed through code reviews or otherwise touching the new code. In this way React knowledge diffused to almost the whole team over the summer.

+ +

Since the first React checkin on June 5, we've somehow managed to accumulate 23500 lines of jsx (React-flavored js) code. Which is terrifying in a way - that's a lot of code - but also really exciting that it was picked up so quickly.

+ +

We held three meetings about how we should proceed with React. At the first two we decided to continue experimenting with React and deferred a final decision on whether to adopt it. At the third we adopted the policy that new code should be written in React.

+ +

I'm excited that we were able to start nudging code quality forward. However, we still have a lot of work to do! One of the selling points of this transition is adopting a uniform frontend style. We're trying to upgrade all the code from (really old) pure jQuery and (regular old) Backbone views / Handlebars to shiny React. At the moment all we've done is introduce more fragmentation. We won't be gratuitously updating working code (if it ain't broke, don't fix it), but are seeking out parts of the codebase where we can shoot two birds with one stone by rewriting in React while fixing bugs or adding functionality.

+ +

Read the full article

+
+

React: Rethinking best practices #

+

Pete Hunt's talk at JSConf EU 2013 is now available in video.

+ +
+

Server-side React with PHP #

+

Stoyan Stefanov's series of articles on React has two new entries on how to execute React on the server to generate the initial page load.

+ +
+

This post is an initial hack to have React components render server-side in PHP.

+ +
    +
  • Problem: Build web UIs
  • +
  • Solution: React
  • +
  • Problem: UI built in JS is anti-SEO (assuming search engines are still noscript) and bad for perceived performance (blank page till JS arrives)
  • +
  • Solution: React page to render the first view
  • +
  • Problem: Can't host node.js apps / I have tons of PHP code
  • +
  • Solution: Use PHP then!
  • +
+ +

Read part 1 ...

+ +

Read part 2 ...

+ +

Rendered markup on the server: +

+
+

TodoMVC Benchmarks #

+

Webkit has a TodoMVC Benchmark that compares different frameworks. They recently included React and here are the results (average of 10 runs in Chrome 30):

+ +
    +
  • AngularJS: 4043ms
  • +
  • AngularJSPerf: 3227ms
  • +
  • BackboneJS: 1874ms
  • +
  • EmberJS: 6822ms
  • +
  • jQuery: 14628ms
  • +
  • React: 2864ms
  • +
  • VanillaJS: 5567ms
  • +
+ +

Try it yourself!

+ +

Please don't take those numbers too seriously, they only reflect one very specific use case and are testing code that wasn't written with performance in mind.

+ +

Even though React scores as one of the fastest frameworks in the benchmark, the React code is simple and idiomatic. The only performance tweak used is the following function:

+
/**
+ * This is a completely optional performance enhancement that you can implement
+ * on any React component. If you were to delete this method the app would still
+ * work correctly (and still be very performant!), we just use it as an example
+ * of how little code it takes to get an order of magnitude performance improvement.
+ */
+shouldComponentUpdate: function (nextProps, nextState) {
+  return (
+    nextProps.todo.id !== this.props.todo.id ||
+    nextProps.todo !== this.props.todo ||
+    nextProps.editing !== this.props.editing ||
+    nextState.editText !== this.state.editText
+  );
+},
+
+

By default, React "re-renders" all the components when anything changes. This is usually fast enough that you don't need to care. However, you can provide a function that can tell whether there will be any change based on the previous and next states and props. If it is faster than re-rendering the component, then you get a performance improvement.

+ +

The fact that you can control when components are rendered is a very important characteristic of React as it gives you control over its performance. We are going to talk more about performance in the future, stay tuned.

+

Guess the filter #

+

Connor McSheffrey implemented a small game using React. The goal is to guess which filter has been used to create the Instagram photo. +

+

React vs FruitMachine #

+

Andrew Betts, director of the Financial Times Labs, posted an article comparing FruitMachine and React.

+ +
+

Eerily similar, no? Maybe Facebook was inspired by Fruit Machine (after all, we got there first), but more likely, it just shows that this is a pretty decent way to solve the problem, and great minds think alike. We're graduating to a third phase in the evolution of web best practice - from intermingling of markup, style and behaviour, through a phase in which those concerns became ever more separated and encapsulated, and finally to a model where we can do that separation at a component level. Developments like Web Components show the direction the web community is moving, and frameworks like React and Fruit Machine are in fact not a lot more than polyfills for that promised behaviour to come.

+ +

Read the full article...

+
+ +

Even though we weren't inspired by FruitMachine (React has been used in production since before FruitMachine was open sourced), it's great to see similar technologies emerging and becoming popular.

+

React Brunch #

+

Matthew McCray implemented react-brunch, a JSX compilation step for Brunch.

+ +
+

Adds React support to brunch by automatically compiling *.jsx files.

+ +

You can configure react-brunch to automatically insert a react header (/** @jsx React.DOM */) into all *.jsx files. Disabled by default.

+ +

Install the plugin via npm with npm install --save react-brunch.

+ +

Read more...

+
+

Random Tweet #

+

I'm going to start adding a tweet at the end of each round-up. We'll start with this one:

+ + + +
+
+

Thinking in React

November 5, 2013 by Pete Hunt

@@ -389,68 +506,6 @@

Reactive Table -

Community Round-up #8

-

September 24, 2013 by Vjeux

-
-
-

A lot has happened in the month since our last update. Here are some of the more interesting things we've found. But first, we have a couple updates before we share links.

- -

First, we are organizing a React Hackathon in Facebook's Seattle office on Saturday September 28. If you want to hack on React, meet some of the team or win some prizes, feel free to join us!

- -

We've also reached a point where there are too many questions for us to handle directly. We're encouraging people to ask questions on StackOverflow using the tag [reactjs]. Many members of the team and community have subscribed to the tag, so feel free to ask questions there. We think these will be more discoverable than Google Groups archives or IRC logs.

-

Javascript Jabber #

-

Pete Hunt and Jordan Walke were interviewed on Javascript Jabber for an hour. They go over many aspects of React such as 60 FPS, Data binding, Performance, Diffing Algorithm, DOM Manipulation, Node.js support, server-side rendering, JSX, requestAnimationFrame and the community. This is a gold mine of information about React.

- -
-

PETE: So React was designed all around that. Conceptually, how you build a React app is that every time your data changes, it's like hitting the refresh button in a server-rendered app. What we do is we conceptually throw out all of the markup and event handlers that you've registered and we reset the whole page and then we redraw the entire page. If you're writing a server-rendered app, handling updates is really easy because you hit the refresh button and you're pretty much guaranteed to get what you expect.

- -

MERRICK: That's true. You don't get into these odd states.

- -

PETE: Exactly, exactly. In order to implement that, we communicate it as a fake DOM. What we'll do is rather than throw out the actual browser html and event handlers, we have an internal representation of what the page looks like and then we generate a brand new representation of what we want the page to look like. Then we perform this really, really fast diffing algorithm between those two page representations, DOM representations. Then React will compute the minimum set of DOM mutations it needs to make to bring the page up to date.

- -

Then to finally get to answer your question, that set of DOM mutations then goes into a queue and we can plug in arbitrary flushing strategies for that. For example, when we originally launched React in open source, every setState would immediately trigger a flush to the DOM. That wasn't part of the contract of setState, but that was just our strategy and it worked pretty well. Then this totally awesome open source contributor Ben Alpert at Khan Academy built a new batching strategy which would basically queue up every single DOM update and state change that happened within an event tick and would execute them in bulk at the end of the event tick.

- -

Read the full conversation ...

-
-

JSXTransformer Trick #

-

While this is not going to work for all the attributes since they are camelCased in React, this is a pretty cool trick.

- -
- - -

Remarkable React #

-

Stoyan Stefanov gave a talk at BrazilJS about React and wrote an article with the content of the presentation. He goes through the difficulties of writting active apps using the DOM API and shows how React handles it.

- -
-

So how does exactly React deal with it internally? Two crazy ideas - virtual DOM and synthetic events.

- -

You define you components in React. It builds a virtual DOM in JavaScript land which is way more efficient. Then it updates the DOM. (And "virtual DOM" is a very big name for what is simply a JavaScript object with nested key-value pairs)

- -

Data changes. React computes a diff (in JavaScript land, which is, of course, much more efficient) and updates the single table cell that needs to change. React replicates the state of the virtual DOM into the actual DOM only when and where it's necessary. And does it all at once, in most cases in a single tick of the requestAnimationFrame().

- -

What about event handlers? They are synthetic. React uses event delegation to listen way at the top of the React tree. So removing a node in the virtual DOM has no effect on the event handling.

- -

The events are automatically cross-browser (they are React events). They are also much closer to W3C than any browser. That means that for example e.target works, no need to look for the event object or checking whether it's e.target or e.srcElement (IE). Bubbling and capturing phases also work cross browser. React also takes the liberty of making some small fixes, e.g. the event <input onChange> fires when you type, not when blur away from the input. And of course, event delegation is used as the most efficient way to handle events. You know that "thou shall use event delegation" is also commonly given advice for making web apps snappy.

- -

The good thing about the virtual DOM is that it's all in JavaScript land. You build all your UI in JavaScript. Which means it can be rendered on the server side, so you initial view is fast (and any SEO concerns are addressed). Also, if there are especially heavy operations they can be threaded into WebWorkers, which otherwise have no DOM access.

- -

Read More ...

-
-

Markdown in React #

-

Ben Alpert converted marked, a Markdown Javascript implementation, in React: marked-react. Even without using JSX, the HTML generation is now a lot cleaner. It is also safer as forgetting a call to escape will not introduce an XSS vulnerability. -

-

Unite from BugBusters #

-

Renault John Lecoultre wrote Unite, an interactive tool for analyzing code dynamically using React. It integrates with CodeMirror. -

-

#reactjs IRC Logs #

-

Vjeux re-implemented the display part of the IRC logger in React. Just 130 lines are needed for a performant infinite scroll with timestamps and color-coded author names.

- - - -
-

- @@ -85,6 +85,68 @@

Recent posts

+
+

Community Round-up #8

+

September 24, 2013 by Vjeux

+
+
+

A lot has happened in the month since our last update. Here are some of the more interesting things we've found. But first, we have a couple updates before we share links.

+ +

First, we are organizing a React Hackathon in Facebook's Seattle office on Saturday September 28. If you want to hack on React, meet some of the team or win some prizes, feel free to join us!

+ +

We've also reached a point where there are too many questions for us to handle directly. We're encouraging people to ask questions on StackOverflow using the tag [reactjs]. Many members of the team and community have subscribed to the tag, so feel free to ask questions there. We think these will be more discoverable than Google Groups archives or IRC logs.

+

Javascript Jabber #

+

Pete Hunt and Jordan Walke were interviewed on Javascript Jabber for an hour. They go over many aspects of React such as 60 FPS, Data binding, Performance, Diffing Algorithm, DOM Manipulation, Node.js support, server-side rendering, JSX, requestAnimationFrame and the community. This is a gold mine of information about React.

+ +
+

PETE: So React was designed all around that. Conceptually, how you build a React app is that every time your data changes, it's like hitting the refresh button in a server-rendered app. What we do is we conceptually throw out all of the markup and event handlers that you've registered and we reset the whole page and then we redraw the entire page. If you're writing a server-rendered app, handling updates is really easy because you hit the refresh button and you're pretty much guaranteed to get what you expect.

+ +

MERRICK: That's true. You don't get into these odd states.

+ +

PETE: Exactly, exactly. In order to implement that, we communicate it as a fake DOM. What we'll do is rather than throw out the actual browser html and event handlers, we have an internal representation of what the page looks like and then we generate a brand new representation of what we want the page to look like. Then we perform this really, really fast diffing algorithm between those two page representations, DOM representations. Then React will compute the minimum set of DOM mutations it needs to make to bring the page up to date.

+ +

Then to finally get to answer your question, that set of DOM mutations then goes into a queue and we can plug in arbitrary flushing strategies for that. For example, when we originally launched React in open source, every setState would immediately trigger a flush to the DOM. That wasn't part of the contract of setState, but that was just our strategy and it worked pretty well. Then this totally awesome open source contributor Ben Alpert at Khan Academy built a new batching strategy which would basically queue up every single DOM update and state change that happened within an event tick and would execute them in bulk at the end of the event tick.

+ +

Read the full conversation ...

+
+

JSXTransformer Trick #

+

While this is not going to work for all the attributes since they are camelCased in React, this is a pretty cool trick.

+ +
+ + +

Remarkable React #

+

Stoyan Stefanov gave a talk at BrazilJS about React and wrote an article with the content of the presentation. He goes through the difficulties of writting active apps using the DOM API and shows how React handles it.

+ +
+

So how does exactly React deal with it internally? Two crazy ideas - virtual DOM and synthetic events.

+ +

You define you components in React. It builds a virtual DOM in JavaScript land which is way more efficient. Then it updates the DOM. (And "virtual DOM" is a very big name for what is simply a JavaScript object with nested key-value pairs)

+ +

Data changes. React computes a diff (in JavaScript land, which is, of course, much more efficient) and updates the single table cell that needs to change. React replicates the state of the virtual DOM into the actual DOM only when and where it's necessary. And does it all at once, in most cases in a single tick of the requestAnimationFrame().

+ +

What about event handlers? They are synthetic. React uses event delegation to listen way at the top of the React tree. So removing a node in the virtual DOM has no effect on the event handling.

+ +

The events are automatically cross-browser (they are React events). They are also much closer to W3C than any browser. That means that for example e.target works, no need to look for the event object or checking whether it's e.target or e.srcElement (IE). Bubbling and capturing phases also work cross browser. React also takes the liberty of making some small fixes, e.g. the event <input onChange> fires when you type, not when blur away from the input. And of course, event delegation is used as the most efficient way to handle events. You know that "thou shall use event delegation" is also commonly given advice for making web apps snappy.

+ +

The good thing about the virtual DOM is that it's all in JavaScript land. You build all your UI in JavaScript. Which means it can be rendered on the server side, so you initial view is fast (and any SEO concerns are addressed). Also, if there are especially heavy operations they can be threaded into WebWorkers, which otherwise have no DOM access.

+ +

Read More ...

+
+

Markdown in React #

+

Ben Alpert converted marked, a Markdown Javascript implementation, in React: marked-react. Even without using JSX, the HTML generation is now a lot cleaner. It is also safer as forgetting a call to escape will not introduce an XSS vulnerability. +

+

Unite from BugBusters #

+

Renault John Lecoultre wrote Unite, an interactive tool for analyzing code dynamically using React. It integrates with CodeMirror. +

+

#reactjs IRC Logs #

+

Vjeux re-implemented the display part of the IRC logger in React. Just 130 lines are needed for a performant infinite scroll with timestamps and color-coded author names.

+ + + +
+
+

Community Round-up #7

August 26, 2013 by Vjeux

@@ -318,31 +380,6 @@

Installation

-
-

React v0.4.1

-

July 26, 2013 by Paul O'Shannessy

-
-
-

React v0.4.1 is a small update, mostly containing correctness fixes. Some code has been restructured internally but those changes do not impact any of our public APIs.

-

React #

-
    -
  • setState callbacks are now executed in the scope of your component.
  • -
  • click events now work on Mobile Safari.
  • -
  • Prevent a potential error in event handling if Object.prototype is extended.
  • -
  • Don't set DOM attributes to the string "undefined" on update when previously defined.
  • -
  • Improved support for <iframe> attributes.
  • -
  • Added checksums to detect and correct cases where server-side rendering markup mismatches what React expects client-side.
  • -
-

JSXTransformer #

-
    -
  • Improved environment detection so it can be run in a non-browser environment.
  • -
- -

Download it now!

- -
-
- @@ -85,6 +85,31 @@

Recent posts

+
+

React v0.4.1

+

July 26, 2013 by Paul O'Shannessy

+
+
+

React v0.4.1 is a small update, mostly containing correctness fixes. Some code has been restructured internally but those changes do not impact any of our public APIs.

+

React #

+
    +
  • setState callbacks are now executed in the scope of your component.
  • +
  • click events now work on Mobile Safari.
  • +
  • Prevent a potential error in event handling if Object.prototype is extended.
  • +
  • Don't set DOM attributes to the string "undefined" on update when previously defined.
  • +
  • Improved support for <iframe> attributes.
  • +
  • Added checksums to detect and correct cases where server-side rendering markup mismatches what React expects client-side.
  • +
+

JSXTransformer #

+
    +
  • Improved environment detection so it can be run in a non-browser environment.
  • +
+ +

Download it now!

+ +
+
+

Community Round-up #5

July 23, 2013 by Vjeux

@@ -344,46 +369,6 @@

Snake in React -

New in React v0.4: Autobind by Default

-

July 2, 2013 by Paul O'Shannessy

-
-
-

React v0.4 is very close to completion. As we finish it off, we'd like to share with you some of the major changes we've made since v0.3. This is the first of several posts we'll be making over the next week.

-

What is React.autoBind? #

-

If you take a look at most of our current examples, you'll see us using React.autoBind for event handlers. This is used in place of Function.prototype.bind. Remember that in JS, function calls are late-bound. That means that if you simply pass a function around, the this used inside won't necessarily be the this you expect. Function.prototype.bind creates a new, properly bound, function so that when called, this is exactly what you expect it to be.

- -

Before we launched React, we would write this:

-
React.createClass({
-  onClick: function(event) {/* do something with this */},
-  render: function() {
-    return <button onClick={this.onClick.bind(this)} />;
-  }
-});
-
-

We wrote React.autoBind as a way to cache the function creation and save on memory usage. Since render can get called multiple times, if you used this.onClick.bind(this) you would actually create a new function on each pass. With React v0.3 you were able to write this instead:

-
React.createClass({
-  onClick: React.autoBind(function(event) {/* do something with this */}),
-  render: function() {
-    return <button onClick={this.onClick} />;
-  }
-});
-

What's Changing in v0.4? #

-

After using React.autoBind for a few weeks, we realized that there were very few times that we didn't want that behavior. So we made it the default! Now all methods defined within React.createClass will already be bound to the correct instance.

- -

Starting with v0.4 you can just write this:

-
React.createClass({
-  onClick: function(event) {/* do something with this */},
-  render: function() {
-    return <button onClick={this.onClick} />;
-  }
-});
-
-

For v0.4 we will simply be making React.autoBind a no-op — it will just return the function you pass to it. Most likely you won't have to change your code to account for this change, though we encourage you to update. We'll publish a migration guide documenting this and other changes that come along with React v0.4.

- -
-

- @@ -85,6 +85,46 @@

Recent posts

+
+

New in React v0.4: Autobind by Default

+

July 2, 2013 by Paul O'Shannessy

+
+
+

React v0.4 is very close to completion. As we finish it off, we'd like to share with you some of the major changes we've made since v0.3. This is the first of several posts we'll be making over the next week.

+

What is React.autoBind? #

+

If you take a look at most of our current examples, you'll see us using React.autoBind for event handlers. This is used in place of Function.prototype.bind. Remember that in JS, function calls are late-bound. That means that if you simply pass a function around, the this used inside won't necessarily be the this you expect. Function.prototype.bind creates a new, properly bound, function so that when called, this is exactly what you expect it to be.

+ +

Before we launched React, we would write this:

+
React.createClass({
+  onClick: function(event) {/* do something with this */},
+  render: function() {
+    return <button onClick={this.onClick.bind(this)} />;
+  }
+});
+
+

We wrote React.autoBind as a way to cache the function creation and save on memory usage. Since render can get called multiple times, if you used this.onClick.bind(this) you would actually create a new function on each pass. With React v0.3 you were able to write this instead:

+
React.createClass({
+  onClick: React.autoBind(function(event) {/* do something with this */}),
+  render: function() {
+    return <button onClick={this.onClick} />;
+  }
+});
+

What's Changing in v0.4? #

+

After using React.autoBind for a few weeks, we realized that there were very few times that we didn't want that behavior. So we made it the default! Now all methods defined within React.createClass will already be bound to the correct instance.

+ +

Starting with v0.4 you can just write this:

+
React.createClass({
+  onClick: function(event) {/* do something with this */},
+  render: function() {
+    return <button onClick={this.onClick} />;
+  }
+});
+
+

For v0.4 we will simply be making React.autoBind a no-op — it will just return the function you pass to it. Most likely you won't have to change your code to account for this change, though we encourage you to update. We'll publish a migration guide documenting this and other changes that come along with React v0.4.

+ +
+
+

Community Round-up #3

June 27, 2013 by Vjeux

@@ -317,98 +357,6 @@

Origins of React -

Why did we build React?

-

June 5, 2013 by Pete Hunt

-
-
-

There are a lot of JavaScript MVC frameworks out there. Why did we build React -and why would you want to use it?

-

React isn't an MVC framework. #

-

React is a library for building composable user interfaces. It encourages -the creation of reusable UI components which present data that changes over -time.

-

React doesn't use templates. #

-

Traditionally, web application UIs are built using templates or HTML directives. -These templates dictate the full set of abstractions that you are allowed to use -to build your UI.

- -

React approaches building user interfaces differently by breaking them into -components. This means React uses a real, full featured programming language -to render views, which we see as an advantage over templates for a few reasons:

- -
    -
  • JavaScript is a flexible, powerful programming language with the ability -to build abstractions. This is incredibly important in large applications.
  • -
  • By unifying your markup with its corresponding view logic, React can actually -make views easier to extend and maintain.
  • -
  • By baking an understanding of markup and content into JavaScript, there's -no manual string concatenation and therefore less surface area for XSS -vulnerabilities.
  • -
- -

We've also created JSX, an optional -syntax extension, in case you prefer the readability of HTML to raw JavaScript.

-

Reactive updates are dead simple. #

-

React really shines when your data changes over time.

- -

In a traditional JavaScript application, you need to look at what data changed -and imperatively make changes to the DOM to keep it up-to-date. Even AngularJS, -which provides a declarative interface via directives and data binding requires -a linking function to manually update DOM nodes.

- -

React takes a different approach.

- -

When your component is first initialized, the render method is called, -generating a lightweight representation of your view. From that representation, -a string of markup is produced, and injected into the document. When your data -changes, the render method is called again. In order to perform updates as -efficiently as possible, we diff the return value from the previous call to -render with the new one, and generate a minimal set of changes to be applied -to the DOM.

- -
-

The data returned from render is neither a string nor a DOM node -- it's a -lightweight description of what the DOM should look like.

-
- -

We call this process reconciliation. Check out -this jsFiddle to see an example of -reconciliation in action.

- -

Because this re-render is so fast (around 1ms for TodoMVC), the developer -doesn't need to explicitly specify data bindings. We've found this approach -makes it easier to build apps.

-

HTML is just the beginning. #

-

Because React has its own lightweight representation of the document, we can do -some pretty cool things with it:

- -
    -
  • Facebook has dynamic charts that render to <canvas> instead of HTML.
  • -
  • Instagram is a "single page" web app built entirely with React and -Backbone.Router. Designers regularly contribute React code with JSX.
  • -
  • We've built internal prototypes that run React apps in a web worker and use -React to drive native iOS views via an Objective-C bridge.
  • -
  • You can run React -on the server -for SEO, performance, code sharing and overall flexibility.
  • -
  • Events behave in a consistent, standards-compliant way in all browsers -(including IE8) and automatically use -event delegation.
  • -
- -

Head on over to -facebook.github.io/react to check -out what we have built. Our documentation is geared towards building -apps with the framework, but if you are interested in the -nuts and bolts -get in touch with us!

- -

Thanks for reading!

- -
-

- @@ -85,6 +85,98 @@

Recent posts

+
+

Why did we build React?

+

June 5, 2013 by Pete Hunt

+
+
+

There are a lot of JavaScript MVC frameworks out there. Why did we build React +and why would you want to use it?

+

React isn't an MVC framework. #

+

React is a library for building composable user interfaces. It encourages +the creation of reusable UI components which present data that changes over +time.

+

React doesn't use templates. #

+

Traditionally, web application UIs are built using templates or HTML directives. +These templates dictate the full set of abstractions that you are allowed to use +to build your UI.

+ +

React approaches building user interfaces differently by breaking them into +components. This means React uses a real, full featured programming language +to render views, which we see as an advantage over templates for a few reasons:

+ +
    +
  • JavaScript is a flexible, powerful programming language with the ability +to build abstractions. This is incredibly important in large applications.
  • +
  • By unifying your markup with its corresponding view logic, React can actually +make views easier to extend and maintain.
  • +
  • By baking an understanding of markup and content into JavaScript, there's +no manual string concatenation and therefore less surface area for XSS +vulnerabilities.
  • +
+ +

We've also created JSX, an optional +syntax extension, in case you prefer the readability of HTML to raw JavaScript.

+

Reactive updates are dead simple. #

+

React really shines when your data changes over time.

+ +

In a traditional JavaScript application, you need to look at what data changed +and imperatively make changes to the DOM to keep it up-to-date. Even AngularJS, +which provides a declarative interface via directives and data binding requires +a linking function to manually update DOM nodes.

+ +

React takes a different approach.

+ +

When your component is first initialized, the render method is called, +generating a lightweight representation of your view. From that representation, +a string of markup is produced, and injected into the document. When your data +changes, the render method is called again. In order to perform updates as +efficiently as possible, we diff the return value from the previous call to +render with the new one, and generate a minimal set of changes to be applied +to the DOM.

+ +
+

The data returned from render is neither a string nor a DOM node -- it's a +lightweight description of what the DOM should look like.

+
+ +

We call this process reconciliation. Check out +this jsFiddle to see an example of +reconciliation in action.

+ +

Because this re-render is so fast (around 1ms for TodoMVC), the developer +doesn't need to explicitly specify data bindings. We've found this approach +makes it easier to build apps.

+

HTML is just the beginning. #

+

Because React has its own lightweight representation of the document, we can do +some pretty cool things with it:

+ +
    +
  • Facebook has dynamic charts that render to <canvas> instead of HTML.
  • +
  • Instagram is a "single page" web app built entirely with React and +Backbone.Router. Designers regularly contribute React code with JSX.
  • +
  • We've built internal prototypes that run React apps in a web worker and use +React to drive native iOS views via an Objective-C bridge.
  • +
  • You can run React +on the server +for SEO, performance, code sharing and overall flexibility.
  • +
  • Events behave in a consistent, standards-compliant way in all browsers +(including IE8) and automatically use +event delegation.
  • +
+ +

Head on over to +facebook.github.io/react to check +out what we have built. Our documentation is geared towards building +apps with the framework, but if you are interested in the +nuts and bolts +get in touch with us!

+ +

Thanks for reading!

+ +
+
+

JSFiddle Integration

June 2, 2013 by Christopher Chedeau

diff --git a/docs/jsx-in-depth.html b/docs/jsx-in-depth.html index 6c197e74f25b8..3e014bbb6cf28 100644 --- a/docs/jsx-in-depth.html +++ b/docs/jsx-in-depth.html @@ -346,6 +346,14 @@

JSX in Depth

JSX is a JavaScript XML syntax transform recommended for use with React.

+ +
+

Note:

+ +

Don't forget the /** @jsx React.DOM */ pragma at the beginning of your file! This tells JSX to process the file for React.

+ +

If you don't include the pragma, your source will remain untouched, so it's safe to run the JSX transformer on all JS files in your codebase if you want to.

+

Why JSX? #

React works out of the box without JSX. Simply construct your markup using the functions on React.DOM. For example, here's how to construct a simple link:

diff --git a/docs/tutorial.html b/docs/tutorial.html index e4372f4376abb..b2e60caa0395e 100644 --- a/docs/tutorial.html +++ b/docs/tutorial.html @@ -379,6 +379,7 @@

Getting started /** * @jsx React.DOM */ + // The above declaration must remain intact at the top of the script. // Your code here </script> </body> @@ -639,21 +640,27 @@

Updating state {"author": "Jordan Walke", "text": "This is *another* comment"} ]

-

We will use jQuery to help make an asynchronous request to the server.

+

We'll use jQuery to help make an asynchronous request to the server.

Note: because this is becoming an AJAX application you'll need to develop your app using a web server rather than as a file sitting on your file system. The easiest way to do this is to run python -m SimpleHTTPServer in your application's directory.

-

The key is the call to this.setState(). We replace the old array of comments with the new one from the server and the UI automatically updates itself. Because of this reactivity, it is trivial to add live updates. We will use simple polling here but you could easily use WebSockets or other technologies.

+

Here, componentWillMount is a method called automatically by React before a component is rendered. The key to dynamic updates is the call to this.setState(). We replace the old array of comments with the new one from the server and the UI automatically updates itself. Because of this reactivity, it is trivial to add live updates. We will use simple polling here but you could easily use WebSockets or other technologies.

// tutorial14.js
 var CommentBox = React.createClass({
   loadCommentsFromServer: function() {
@@ -678,11 +685,11 @@ 

Updating state getInitialState: function() { return {data: []}; }, - componentWillMount: function() { - this.loadCommentsFromServer(); + componentWillMount: function() { + this.loadCommentsFromServer(); setInterval(this.loadCommentsFromServer, this.props.pollInterval); - }, - render: function() { + }, + render: function() { return ( <div className="commentBox"> <h1>Comments</h1> diff --git a/feed.xml b/feed.xml index 2409e8734bac4..7fd9377f1bbb9 100644 --- a/feed.xml +++ b/feed.xml @@ -6,6 +6,102 @@ http://facebook.github.io/react + + Community Round-up #13 + <p>Happy holidays! This blog post is a little-late Christmas present for all the React users. Hopefully it will inspire you to write awesome web apps in 2014!</p> +<h2><a class="anchor" name="react-touch"></a>React Touch <a class="hash-link" href="#react-touch">#</a></h2> +<p><a href="http://www.petehunt.net/">Pete Hunt</a> wrote three demos showing that React can be used to run 60fps native-like experiences on mobile web. A frosted glass effect, an image gallery with 3d animations and an infinite scroll view.</p> + +<figure><iframe src="//player.vimeo.com/video/79659941" width="220" height="400" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></figure> + +<p><a href="http://petehunt.github.io/react-touch/">Try out the demos!</a></p> +<h2><a class="anchor" name="introduction-to-react"></a>Introduction to React <a class="hash-link" href="#introduction-to-react">#</a></h2> +<p><a href="http://www.phpied.com/">Stoyan Stefanov</a> talked at Joe Dev On Tech about React. He goes over all the features of the library and ends with a concrete example.</p> + +<figure><iframe width="560" height="315" src="//www.youtube.com/embed/SMMRJif5QW0" frameborder="0" allowfullscreen></iframe></figure> +<h2><a class="anchor" name="jsx-e4x-the-good-parts"></a>JSX: E4X The Good Parts <a class="hash-link" href="#jsx-e4x-the-good-parts">#</a></h2> +<p>JSX is often compared to the now defunct E4X, <a href="http://blog.vjeux.com/">Vjeux</a> went over all the E4X features and explained how JSX is different and hopefully doesn&#39;t repeat the same mistakes.</p> + +<blockquote> +<p>E4X (ECMAScript for XML) is a Javascript syntax extension and a runtime to manipulate XML. It was promoted by Mozilla but failed to become mainstream and is now deprecated. JSX was inspired by E4X. In this article, I&#39;m going to go over all the features of E4X and explain the design decisions behind JSX.</p> + +<p><strong>Historical Context</strong></p> + +<p>E4X has been created in 2002 by John Schneider. This was the golden age of XML where it was being used for everything: data, configuration files, code, interfaces (DOM) ... E4X was first implemented inside of Rhino, a Javascript implementation from Mozilla written in Java.</p> + +<p><a href="http://blog.vjeux.com/2013/javascript/jsx-e4x-the-good-parts.html">Continue reading ...</a></p> +</blockquote> +<h2><a class="anchor" name="react--socket.io"></a>React + Socket.io <a class="hash-link" href="#react--socket.io">#</a></h2> +<p><a href="http://enome.be/nl">Geert Pasteels</a> made a small experiment with Socket.io. He wrote a very small mixin that synchronizes React state with the server. Just include this mixin to your React component and it is now live!</p> +<div class="highlight"><pre><code class="javascript language-javascript" data-lang="javascript"><span class="nx">changeHandler</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">data</span><span class="p">)</span> <span class="p">{</span> + <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">_</span><span class="p">.</span><span class="nx">isEqual</span><span class="p">(</span><span class="nx">data</span><span class="p">.</span><span class="nx">state</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">state</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="k">this</span><span class="p">.</span><span class="nx">path</span> <span class="o">===</span> <span class="nx">data</span><span class="p">.</span><span class="nx">path</span><span class="p">)</span> <span class="p">{</span> + <span class="k">this</span><span class="p">.</span><span class="nx">setState</span><span class="p">(</span><span class="nx">data</span><span class="p">.</span><span class="nx">state</span><span class="p">);</span> + <span class="p">}</span> +<span class="p">},</span> +<span class="nx">componentDidMount</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">root</span><span class="p">)</span> <span class="p">{</span> + <span class="k">this</span><span class="p">.</span><span class="nx">path</span> <span class="o">=</span> <span class="nx">utils</span><span class="p">.</span><span class="nx">nodePath</span><span class="p">(</span><span class="nx">root</span><span class="p">);</span> + <span class="nx">socket</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s1">&#39;component-change&#39;</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">changeHandler</span><span class="p">);</span> +<span class="p">},</span> +<span class="nx">componentWillUpdate</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">props</span><span class="p">,</span> <span class="nx">state</span><span class="p">)</span> <span class="p">{</span> + <span class="nx">socket</span><span class="p">.</span><span class="nx">emit</span><span class="p">(</span><span class="s1">&#39;component-change&#39;</span><span class="p">,</span> <span class="p">{</span> <span class="nx">path</span><span class="o">:</span> <span class="k">this</span><span class="p">.</span><span class="nx">path</span><span class="p">,</span> <span class="nx">state</span><span class="o">:</span> <span class="nx">state</span> <span class="p">});</span> +<span class="p">},</span> +<span class="nx">componentWillUnmount</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> + <span class="nx">socket</span><span class="p">.</span><span class="nx">removeListener</span><span class="p">(</span><span class="s1">&#39;component-change&#39;</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">change</span><span class="p">);</span> +<span class="p">}</span> +</code></pre></div> +<p><a href="https://github.com/Enome/react.io">Check it out on GitHub...</a></p> +<h2><a class="anchor" name="cssobjectify"></a>cssobjectify <a class="hash-link" href="#cssobjectify">#</a></h2> +<p><a href="http://andreypopp.com/">Andrey Popp</a> implemented a source transform that takes a CSS file and converts it to JSON. This integrates pretty nicely with React.</p> +<div class="highlight"><pre><code class="javascript language-javascript" data-lang="javascript"><span class="cm">/* style.css */</span> +<span class="nx">MyComponent</span> <span class="p">{</span> + <span class="nx">font</span><span class="o">-</span><span class="nx">size</span><span class="o">:</span> <span class="mi">12</span><span class="nx">px</span><span class="p">;</span> + <span class="nx">background</span><span class="o">-</span><span class="nx">color</span><span class="o">:</span> <span class="nx">red</span><span class="p">;</span> +<span class="p">}</span> + +<span class="cm">/* myapp.js */</span> +<span class="kd">var</span> <span class="nx">React</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;react-tools/build/modules/React&#39;</span><span class="p">);</span> +<span class="kd">var</span> <span class="nx">Styles</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./styles.css&#39;</span><span class="p">);</span> + +<span class="kd">var</span> <span class="nx">MyComponent</span> <span class="o">=</span> <span class="nx">React</span><span class="p">.</span><span class="nx">createClass</span><span class="p">({</span> + <span class="nx">render</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span> + <span class="k">return</span> <span class="p">(</span> + <span class="o">&lt;</span><span class="nx">div</span> <span class="nx">style</span><span class="o">=</span><span class="p">{</span><span class="nx">Styles</span><span class="p">.</span><span class="nx">MyComponent</span><span class="p">}</span><span class="o">&gt;</span> + <span class="nx">Hello</span><span class="p">,</span> <span class="nx">world</span><span class="o">!</span> + <span class="o">&lt;</span><span class="err">/div&gt;</span> + <span class="p">)</span> + <span class="p">}</span> +<span class="p">});</span> +</code></pre></div> +<p><a href="https://github.com/andreypopp/cssobjectify">Check it out on GitHub...</a></p> +<h2><a class="anchor" name="ngreact"></a>ngReact <a class="hash-link" href="#ngreact">#</a></h2> +<p><a href="http://davidandsuzi.com/">David Chang</a> working at <a href="http://www.hasoffers.com/">HasOffer</a> wanted to speed up his Angular app and replaced Angular primitives by React at different layers. When using React naively it is 67% faster, but when combining it with angular&#39;s transclusion it is 450% slower.</p> + +<blockquote> +<p>Rendering this takes 803ms for 10 iterations, hovering around 35 and 55ms for each data reload (that&#39;s 67% faster). You&#39;ll notice that the first load takes a little longer than successive loads, and the second load REALLY struggles - here, it&#39;s 433ms, which is more than half of the total time! +<figure><a href="http://davidandsuzi.com/ngreact-react-components-in-angular/"><img src="/react/img/blog/ngreact.png" alt=""></a></figure></p> + +<p><a href="http://davidandsuzi.com/ngreact-react-components-in-angular/">Read the full article...</a></p> +</blockquote> +<h2><a class="anchor" name="vim-jsx"></a>vim-jsx <a class="hash-link" href="#vim-jsx">#</a></h2> +<p><a href="https://github.com/mxw">Max Wang</a> made a vim syntax highlighting and indentation plugin for vim.</p> + +<blockquote> +<p>Syntax highlighting and indenting for JSX. JSX is a JavaScript syntax transformer which translates inline XML document fragments into JavaScript objects. It was developed by Facebook alongside React.</p> + +<p>This bundle requires pangloss&#39;s <a href="https://github.com/pangloss/vim-javascript">vim-javascript</a> syntax highlighting.</p> + +<p>Vim support for inline XML in JS is remarkably similar to the same for PHP.</p> + +<p><a href="https://github.com/mxw/vim-jsx">View on GitHub...</a></p> +</blockquote> +<h2><a class="anchor" name="random-tweet"></a>Random Tweet <a class="hash-link" href="#random-tweet">#</a></h2> +<p><center><blockquote class="twitter-tweet" lang="en"><p>I may be starting to get annoying with this, but ReactJS is really exciting. I truly feel the virtual DOM is a game changer.</p>&mdash; Eric Florenzano (@ericflo) <a href="https://twitter.com/ericflo/statuses/413842834974732288">December 20, 2013</a></blockquote></center></p> + + 2013-12-30T00:00:00+01:00 + http://facebook.github.io/react/blog/2013/12/30/community-roundup-13.html + http://facebook.github.io/react/blog/2013/12/30/community-roundup-13.html + + Community Round-up #12 <p>React got featured on the front-page of Hacker News thanks to the Om library. If you try it out for the first time, take a look at the <a href="/react/docs/getting-started.html">docs</a> and do not hesitate to ask questions on the <a href="http://groups.google.com/group/reactjs">Google Group</a>, <a href="irc://chat.freenode.net/reactjs">IRC</a> or <a href="http://stackoverflow.com/questions/tagged/reactjs">Stack Overflow</a>. We are trying our best to help you out!</p> @@ -648,66 +744,5 @@ Is this some sort of template language? Specifically no. This might have been th http://facebook.github.io/react/blog/2013/10/03/community-roundup-9.html - - Community Round-up #8 - <p>A lot has happened in the month since our last update. Here are some of the more interesting things we&#39;ve found. But first, we have a couple updates before we share links.</p> - -<p>First, we are organizing a <a href="http://reactjshack-a-thon.splashthat.com/">React Hackathon</a> in Facebook&#39;s Seattle office on Saturday September 28. If you want to hack on React, meet some of the team or win some prizes, feel free to join us!</p> - -<p>We&#39;ve also reached a point where there are too many questions for us to handle directly. We&#39;re encouraging people to ask questions on <a href="http://stackoverflow.com/questions/tagged/reactjs">StackOverflow</a> using the tag <a href="http://stackoverflow.com/questions/tagged/reactjs">[reactjs]</a>. Many members of the team and community have subscribed to the tag, so feel free to ask questions there. We think these will be more discoverable than Google Groups archives or IRC logs.</p> -<h2><a class="anchor" name="javascript-jabber"></a>Javascript Jabber <a class="hash-link" href="#javascript-jabber">#</a></h2> -<p><a href="http://www.petehunt.net/">Pete Hunt</a> and <a href="https://github.com/jordwalke">Jordan Walke</a> were interviewed on <a href="http://javascriptjabber.com/073-jsj-react-with-pete-hunt-and-jordan-walke/">Javascript Jabber</a> for an hour. They go over many aspects of React such as 60 FPS, Data binding, Performance, Diffing Algorithm, DOM Manipulation, Node.js support, server-side rendering, JSX, requestAnimationFrame and the community. This is a gold mine of information about React.</p> - -<blockquote> -<p><strong>PETE:</strong> So React was designed all around that. Conceptually, how you build a React app is that every time your data changes, it&#39;s like hitting the refresh button in a server-rendered app. What we do is we conceptually throw out all of the markup and event handlers that you&#39;ve registered and we reset the whole page and then we redraw the entire page. If you&#39;re writing a server-rendered app, handling updates is really easy because you hit the refresh button and you&#39;re pretty much guaranteed to get what you expect.</p> - -<p><strong>MERRICK:</strong> That&#39;s true. You don&#39;t get into these odd states.</p> - -<p><strong>PETE:</strong> Exactly, exactly. In order to implement that, we communicate it as a fake DOM. What we&#39;ll do is rather than throw out the actual browser html and event handlers, we have an internal representation of what the page looks like and then we generate a brand new representation of what we want the page to look like. Then we perform this really, really fast diffing algorithm between those two page representations, DOM representations. Then React will compute the minimum set of DOM mutations it needs to make to bring the page up to date.</p> - -<p>Then to finally get to answer your question, that set of DOM mutations then goes into a queue and we can plug in arbitrary flushing strategies for that. For example, when we originally launched React in open source, every setState would immediately trigger a flush to the DOM. That wasn&#39;t part of the contract of setState, but that was just our strategy and it worked pretty well. Then this totally awesome open source contributor Ben Alpert at Khan Academy built a new batching strategy which would basically queue up every single DOM update and state change that happened within an event tick and would execute them in bulk at the end of the event tick.</p> - -<p><a href="http://javascriptjabber.com/073-jsj-react-with-pete-hunt-and-jordan-walke/">Read the full conversation ...</a></p> -</blockquote> -<h2><a class="anchor" name="jsxtransformer-trick"></a>JSXTransformer Trick <a class="hash-link" href="#jsxtransformer-trick">#</a></h2> -<p>While this is not going to work for all the attributes since they are camelCased in React, this is a pretty cool trick.</p> - -<div style="margin-left: 74px;"><blockquote class="twitter-tweet"><p>Turn any DOM element into a React.js function: JSXTransformer.transform(&quot;/** <a href="https://twitter.com/jsx">@jsx</a> React.DOM */&quot; + element.innerHTML).code</p>&mdash; Ross Allen (@ssorallen) <a href="https://twitter.com/ssorallen/statuses/377105575441489920">September 9, 2013</a></blockquote></div> - -<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script> -<h2><a class="anchor" name="remarkable-react"></a>Remarkable React <a class="hash-link" href="#remarkable-react">#</a></h2> -<p><a href="http://www.phpied.com/">Stoyan Stefanov</a> gave a talk at <a href="http://braziljs.com.br/">BrazilJS</a> about React and wrote an article with the content of the presentation. He goes through the difficulties of writting <em>active apps</em> using the DOM API and shows how React handles it.</p> - -<blockquote> -<p>So how does exactly React deal with it internally? Two crazy ideas - virtual DOM and synthetic events.</p> - -<p>You define you components in React. It builds a virtual DOM in JavaScript land which is way more efficient. Then it updates the DOM. (And &quot;virtual DOM&quot; is a very big name for what is simply a JavaScript object with nested key-value pairs)</p> - -<p>Data changes. React computes a diff (in JavaScript land, which is, of course, much more efficient) and updates the single table cell that needs to change. React replicates the state of the virtual DOM into the actual DOM only when and where it&#39;s necessary. And does it all at once, in most cases in a single tick of the <code>requestAnimationFrame()</code>.</p> - -<p>What about event handlers? They are synthetic. React uses event delegation to listen way at the top of the React tree. So removing a node in the virtual DOM has no effect on the event handling.</p> - -<p>The events are automatically cross-browser (they are React events). They are also much closer to W3C than any browser. That means that for example <code>e.target</code> works, no need to look for the event object or checking whether it&#39;s <code>e.target</code> or <code>e.srcElement</code> (IE). Bubbling and capturing phases also work cross browser. React also takes the liberty of making some small fixes, e.g. the event <code>&lt;input onChange&gt;</code> fires when you type, not when blur away from the input. And of course, event delegation is used as the most efficient way to handle events. You know that &quot;thou shall use event delegation&quot; is also commonly given advice for making web apps snappy.</p> - -<p>The good thing about the virtual DOM is that it&#39;s all in JavaScript land. You build all your UI in JavaScript. Which means it can be rendered on the server side, so you initial view is fast (and any SEO concerns are addressed). Also, if there are especially heavy operations they can be threaded into WebWorkers, which otherwise have no DOM access.</p> - -<p><a href="http://www.phpied.com/remarkable-react/">Read More ...</a></p> -</blockquote> -<h2><a class="anchor" name="markdown-in-react"></a>Markdown in React <a class="hash-link" href="#markdown-in-react">#</a></h2> -<p><a href="http://benalpert.com/">Ben Alpert</a> converted <a href="https://github.com/chjj/marked">marked</a>, a Markdown Javascript implementation, in React: <a href="https://github.com/spicyj/marked-react">marked-react</a>. Even without using JSX, the HTML generation is now a lot cleaner. It is also safer as forgetting a call to <code>escape</code> will not introduce an XSS vulnerability. -<figure><a href="https://github.com/spicyj/marked-react/commit/cb70c9df6542c7c34ede9efe16f9b6580692a457"><img src="/react/img/blog/markdown_refactor.png" alt=""></a></figure></p> -<h2><a class="anchor" name="unite-from-bugbusters"></a>Unite from BugBusters <a class="hash-link" href="#unite-from-bugbusters">#</a></h2> -<p><a href="https://twitter.com/renajohn">Renault John Lecoultre</a> wrote <a href="https://www.bugbuster.com/">Unite</a>, an interactive tool for analyzing code dynamically using React. It integrates with CodeMirror. -<figure><a href="https://unite.bugbuster.com/"><img src="/react/img/blog/unite.png" alt=""></a></figure></p> -<h2><a class="anchor" name="reactjs-irc-logs"></a>#reactjs IRC Logs <a class="hash-link" href="#reactjs-irc-logs">#</a></h2> -<p><a href="http://blog.vjeux.com/">Vjeux</a> re-implemented the display part of the IRC logger in React. Just 130 lines are needed for a performant infinite scroll with timestamps and color-coded author names.</p> - -<iframe width="100%" height="300" src="http://jsfiddle.net/vjeux/QL9tz/embedded/" allowfullscreen="allowfullscreen" frameborder="0"></iframe> - - 2013-09-24T00:00:00+02:00 - http://facebook.github.io/react/blog/2013/09/24/community-roundup-8.html - http://facebook.github.io/react/blog/2013/09/24/community-roundup-8.html - - diff --git a/img/blog/ngreact.png b/img/blog/ngreact.png new file mode 100644 index 0000000000000..7dcd9a297b85e Binary files /dev/null and b/img/blog/ngreact.png differ