From ffa032b1464592c358d5146600dedbb0bcbdf23b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Fri, 31 Oct 2014 11:24:54 -0700 Subject: [PATCH] Update to latest Includes #2419, #2428, #2418, #2443, #2433 --- docs/interactivity-and-dynamic-uis.html | 4 ++-- docs/jsx-spread.html | 2 +- docs/transferring-props.html | 4 ++-- docs/tutorial.html | 2 +- js/jsfiddle-integration.js | 11 +++++++++++ tips/if-else-in-JSX.html | 2 +- 6 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 js/jsfiddle-integration.js diff --git a/docs/interactivity-and-dynamic-uis.html b/docs/interactivity-and-dynamic-uis.html index 969ec0e836..edb30fa39d 100644 --- a/docs/interactivity-and-dynamic-uis.html +++ b/docs/interactivity-and-dynamic-uis.html @@ -406,9 +406,9 @@

If you'd like to use React on a touch device such as a phone or tablet, simply call React.initializeTouchEvents(true); to enable touch event handling.

Under the Hood: Autobinding and Event Delegation #

-

Under the hood React does a few things to keep your code performant and easy to understand.

+

Under the hood, React does a few things to keep your code performant and easy to understand.

-

Autobinding: When creating callbacks in JavaScript you usually need to explicitly bind a method to its instance such that the value of this is correct. With React, every method is automatically bound to its component instance. React caches the bound method such that it's extremely CPU and memory efficient. It's also less typing!

+

Autobinding: When creating callbacks in JavaScript, you usually need to explicitly bind a method to its instance such that the value of this is correct. With React, every method is automatically bound to its component instance. React caches the bound method such that it's extremely CPU and memory efficient. It's also less typing!

Event delegation: React doesn't actually attach event handlers to the nodes themselves. When React starts up, it starts listening for all events at the top level using a single event listener. When a component is mounted or unmounted, the event handlers are simply added or removed from an internal mapping. When an event occurs, React knows how to dispatch it using this mapping. When there are no event handlers left in the mapping, React's event handlers are simple no-ops. To learn more about why this is fast, see David Walsh's excellent blog post.

Components are Just State Machines #

diff --git a/docs/jsx-spread.html b/docs/jsx-spread.html index a7872e8307..49382e4311 100644 --- a/docs/jsx-spread.html +++ b/docs/jsx-spread.html @@ -379,7 +379,7 @@
-

If you know all the properties that you want to place on a component a head of time, it is easy to use JSX:

+

If you know all the properties that you want to place on a component ahead of time, it is easy to use JSX:

  var component = <Component foo={x} bar={y} />;
 

Mutating Props is Bad, mkay #

If you don't know which properties you want to set, you might be tempted to add them onto the object later:

diff --git a/docs/transferring-props.html b/docs/transferring-props.html index 6313a2f4a6..4200d00f4e 100644 --- a/docs/transferring-props.html +++ b/docs/transferring-props.html @@ -400,7 +400,7 @@ ); } }); -React.renderComponent( +React.render( <FancyCheckbox checked={true} onClick={console.log}> Hello world! </FancyCheckbox>, @@ -425,7 +425,7 @@ ); } }); -React.renderComponent( +React.render( <FancyCheckbox checked={true} onClick={console.log}> Hello world! </FancyCheckbox>, diff --git a/docs/tutorial.html b/docs/tutorial.html index 9066993ad8..5135a90cd5 100644 --- a/docs/tutorial.html +++ b/docs/tutorial.html @@ -399,7 +399,7 @@

Want to skip all this and just see the source? #

It's all on GitHub.

Getting started #

-

For this tutorial we'll use prebuilt JavaScript files on a CDN. Open up your favorite editor and create a new HTML document:

+

For this tutorial, we'll use prebuilt JavaScript files on a CDN. Open up your favorite editor and create a new HTML document:

<!-- template.html -->
 <html>
   <head>
diff --git a/js/jsfiddle-integration.js b/js/jsfiddle-integration.js
new file mode 100644
index 0000000000..ae5a64f42a
--- /dev/null
+++ b/js/jsfiddle-integration.js
@@ -0,0 +1,11 @@
+(function() {
+  var tag = document.querySelector(
+    'script[type="application/javascript;version=1.7"]'
+  );
+  if (!tag || tag.textContent.indexOf('window.onload=function(){') !== -1) {
+    alert('Bad JSFiddle configuration, please fork the original React JSFiddle');
+  }
+  tag.setAttribute('type', 'text/jsx;harmony=true');
+  tag.textContent = tag.textContent.replace(/^\/\/<div id={if (condition) { 'msg' }}>Hello World!</div>
 
 // Is transformed to this JS:
-React.createElement("dov", {id: if (condition) { 'msg' }}, "Hello World!");
+React.createElement("div", {id: if (condition) { 'msg' }}, "Hello World!");
 

That's not valid JS. You probably want to make use of a ternary expression:

React.render(<div id={condition ? 'msg' : ''}>Hello World!</div>, mountNode);