From 6c61658bbaeb2c3f9e1dc20210226fd16b601dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Wed, 29 May 2013 13:54:54 -0700 Subject: [PATCH] Updated to latest master build --- docs/api.html | 88 +++++++++++++++++++------------------ docs/event-handling.html | 94 ++++++++++++++++++++++++++++++++++++++++ docs/syntax.html | 2 +- index.html | 4 +- js/examples/timer.js | 2 +- 5 files changed, 143 insertions(+), 47 deletions(-) diff --git a/docs/api.html b/docs/api.html index a93aa661bc..0e5c7ca870 100644 --- a/docs/api.html +++ b/docs/api.html @@ -82,16 +82,18 @@

React is the entry point to the React framework. If you're using one of the prebuilt packages it's available as a global; if you're using CommonJS modules you can require() it.

-

DOM

+

React.DOM

React.DOM provides all of the standard HTML tags needed to build a React app. You generally don't use it directly; instead, just include it as part of the /** @jsx React.DOM */ docblock.

-

initializeTouchEvents(boolean shouldUseTouch)

- +

React.initializeTouchEvents

+
initializeTouchEvents(boolean shouldUseTouch)
+

Configure React's event system to handle touch events on mobile devices.

-

function autoBind(function method)

- +

React.autoBind

+
function autoBind(function method)
+

Marks the provided function to be automatically bound to each React component instance created. This allows React components to define automatically bound methods and ensure that when called they will always reference their current instance.

Example:

@@ -105,12 +107,14 @@ } }); -

function createClass(object specification)

- +

React.createClass

+
function createClass(object specification)
+

Creates a component given a specification. A component implements a render method which returns a single child. That child may have an arbitrarily deep child structure. One thing that makes components different than a standard prototypal classes is that you don't need to call new on them. They are convenience wrappers that construct backing instances (via new) for you.

-

ReactComponent renderComponent(ReactComponent container, DOMElement mountPoint)

- +

React.renderComponent

+
ReactComponent renderComponent(ReactComponent container, DOMElement mountPoint)
+

Renders a React component into the DOM in the supplied container.

If the React component was previously rendered into container, this will perform an update on it and only mutate the DOM as necessary to reflect the latest React component.

@@ -125,61 +129,59 @@

Component classses created by createClass() return instances of ReactComponent when called. Most of the time when you're using React you're either creating or consuming ReactComponents.

-

DOMElement getDOMNode()

- +

getDOMNode

+
DOMElement getDOMNode()
+

If this component has been mounted into the DOM, this returns the corresponding native browser DOM element. This method is useful for reading values out of the DOM, such as form field values and performing DOM measurements.

-

setProps(object nextProps)

- +

setProps

+
setProps(object nextProps)
+

When you're integrating with an external JavaScript application you may want to signal a change to a React component rendered with renderComponent(). Simply call setProps() to change its properties and trigger a re-render.

Note: This method can only be called on a root-level component. That is, it's only available on the component passed directly to renderComponent() and none of its children. If you're inclined to use setProps() on a child component, instead take advantage of reactive updates and pass the new prop to the child component when it's created in render().

-

replaceProps(object nextProps)

- +

replaceProps

+
replaceProps(object nextProps)
+

Like setProps() but deletes any pre-existing props that are not in nextProps.

-

ReactComponent transferPropsTo(ReactComponent targetComponent)

- +

transferPropsTo

+
ReactComponent transferPropsTo(ReactComponent targetComponent)
+

Transfer properties from this component to a target component that have not already been set on the target component. This is usually used to pass down properties to the returned root component. targetComponent, now updated with some new props is returned as a convenience.

-

setState(object nextState)

- +

setState

+
setState(object nextState)
+

Merges nextState with the current state. This is the primary method you use to trigger UI updates from event handlers and server request callbacks.

Note: NEVER mutate this.state directly. As calling setState() afterwards may replace the mutation you made. Treat this.state as if it were immutable.

Note: setState() does not immediately mutate this.state but creates a pending state transition. Accessing this.state after calling this method can potentially return the existing value.

-

replaceState(object nextState)

- +

replaceState

+
replaceState(object nextState)
+

Like setState() but deletes any pre-existing state keys that are not in nextState.

-

forceUpdate()

- +

forceUpdate()

+
forceUpdate()
+

If your render() method reads from something other than this.props or this.state you'll need to tell React when it needs to re-run render(). Use forceUpdate() to cause React to automatically re-render. This will cause render() to be called on the component and all of its children but React will only update the DOM if the markup changes.

Normally you should try to avoid all uses of forceUpdate() and only read from this.props and this.state in render(). This makes your application much simpler and more efficient.

- -

object getInitialState()

- -

componentWillMount()

- -

componentDidMount(DOMElement domNode)

- -

componentWillReceiveProps(object nextProps)

- -

boolean shouldComponentUpdate(object nextProps, object nextState)

- -

componentWillUpdate(object nextProps, object nextState)

- -

ReactComponent render()

- -

componentDidUpdate(object prevProps, object prevState, DOMElement domNode)

- -

componentWillUnmount()

- -

These are overridable lifecycle methods; see the lifecycle methods documentation for more information.

+
object getInitialState()
+componentWillMount()
+componentDidMount(DOMElement domNode)
+componentWillReceiveProps(object nextProps)
+boolean shouldComponentUpdate(object nextProps, object nextState)
+componentWillUpdate(object nextProps, object nextState)
+ReactComponent render()
+componentDidUpdate(object prevProps, object prevState, DOMElement domNode)
+componentWillUnmount()
+
+

See the advanced components documentation for more details on these lifecycle methods.

diff --git a/docs/event-handling.html b/docs/event-handling.html index 8922245376..5bfd2832bb 100644 --- a/docs/event-handling.html +++ b/docs/event-handling.html @@ -183,6 +183,100 @@ implementation.

}; var myToggleLink = <ToggleLink onToggle={handleToggle} />;
+

Common Patterns

+ +

With React your event handlers should be quite small. Large event handlers may +be symptomatic of code that should be moved into helpers or into render(). +Here are some common usage patterns for event handlers.

+ +

Updating State

+ +

The most common thing to do in response to a user action is to call +this.setState() to update the component's state, which will in turn trigger +an update to the rendered component.

+ +

Server Requests

+ +

Many event handlers will issue a server request to read or write some data in +response to an event. The response handler for the request will often call +this.setState().

+ +

Invoke a Callback

+ +

Your component will often be a small, reusable building block that does not know +how to respond to a user action. In these situations, we delegate the +responsibility to the owner by exposing a handler on this.props. This is what +the ToggleLink example above is doing.

+ +

Inter-component Communication

+ +

A common scenario involves communicating to Component A that a user action +has occurred on Component B. To solve this problem, a common parent to +both components should listen for the event on Component B, update its +internal state, and pass that data into Component A.

+ +

For example, say we have two components: Clicker, a component that fires an +onCountChange custom event, and ClickCountLabel, a component that displays +the number of clicks that have happened:

+
var Clicker = React.createClass({
+  getInitialState: function() {
+    return {count: 0};
+  },
+  render: function() {
+    return <span onClick={this.handleClick}>Click me!</span>;
+  },
+  handleClick: React.autoBind(function() {
+    this.setState({count: this.state.count + 1});
+    if (this.props.onCountChange) {
+      this.props.onCountChange(this.state.count);
+    }
+  })
+});
+
+var ClickCountLabel = React.createClass({
+  render: function() {
+    return <p>You have clicked <strong>{this.props.count}</strong> times.</p>;
+  }
+});
+
+var ClickApp = React.createClass({
+  render: function() {
+    var count = 0;
+    return (
+      <div>
+        <Clicker onCountChange={this.handleCountChange} />
+        <ClickCountLabel count={count} />
+      </div>
+    );
+  },
+  handleCountChange: React.autoBind(function(count) {
+    // Somehow update `count`.
+  })
+});
+
+

In order to communicate the click count from Clicker to ClickCountLabel, we +modify ClickApp to maintain state that will be passed into ClickCountLabel:

+
var ClickApp = React.createClass({
+  getInitialState: function() {
+    return {count: 0};
+  },
+  render: function() {
+    var count = this.state.count;
+    return (
+      <div>
+        <Clicker onCountChange={this.handleCountChange} />
+        <ClickCountLabel count={count} />
+      </div>
+    );
+  },
+  handleCountChange: React.autoBind(function(count) {
+    this.setState({count: count});
+  })
+});
+
+

Now when Clicker fires the onCountChange event, the ClickCountLabel will +get updated!

+
diff --git a/docs/syntax.html b/docs/syntax.html index 63b71bc09f..52a81eb177 100644 --- a/docs/syntax.html +++ b/docs/syntax.html @@ -81,7 +81,7 @@

JSX is a JavaScript XML syntax extension recommended (but not required) for use with React.

-

JSX makes code that deeply nested React components more readable, and writing it +

JSX makes code that deeply nests React components more readable, and writing it feels like writing HTML. React documentation examples make use of JSX.

The Transform

diff --git a/index.html b/index.html index 30abecf94f..74a4d9f392 100644 --- a/index.html +++ b/index.html @@ -139,8 +139,8 @@

diff --git a/js/examples/timer.js b/js/examples/timer.js index 5d4d0b7c6b..4fee8b23ee 100644 --- a/js/examples/timer.js +++ b/js/examples/timer.js @@ -17,7 +17,7 @@ var Timer = React.createClass({\n\ render: function() {\n\ return (\n\
\n\ - {'Seconds Ellapsed: ' + this.state.secondsElapsed}\n\ + {'Seconds Elapsed: ' + this.state.secondsElapsed}\n\
\n\ );\n\ }\n\