Skip to content

Instantly share code, notes, and snippets.

@banyan
Last active August 29, 2015 14:05
Show Gist options
  • Save banyan/3671361e75dfc3e03853 to your computer and use it in GitHub Desktop.
Save banyan/3671361e75dfc3e03853 to your computer and use it in GitHub Desktop.
Most of quotation comes from this post: http://www.phpied.com/remarkable-react/

React Overview

  • React isn't an MVC framework.
  • React doesn't use templates.

It's used by

  • Facebook
  • Instagram
  • Khan Academy
  • and more..

Two crazy ideas - Virtual DOM and Synthetic Events

Virtual DOM

  • Most of React's novelty comes from the Virtual DOM

  • Virtual DOM is nothing but simply a JavaScript object with nested key-value pairs

  • Pete Hunt - The Secrets of React's Virtual DOM (FutureJS 2014)

  • Whenever anything may have changed, re-render everything to a Virtual DOM representation

  • Diff the previous representation with the next one (in JavaScript land, which is, of course, much more efficient)

  • Only update the real DOM with what actually what needs to be changed

  • And does it all at once, in most cases in a single tick of the requestAnimationFrame().

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 s tate 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().

Diff Algorithm

Synthetic Events

React uses event delegation to listen way at the top of the React tree.

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).

Tips

Refs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment