Skip to content

Commit cc7fed3

Browse files
committed
updated AsyncState example
1 parent 151811f commit cc7fed3

File tree

1 file changed

+7
-23
lines changed

1 file changed

+7
-23
lines changed

docs/api/mixins/AsyncState.md

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,43 +67,27 @@ var User = React.createClass({
6767
```
6868

6969
But you can get fancier...
70-
7170

7271
```js
7372
var User = React.createClass({
74-
7573
mixins: [ Router.AsyncState ],
7674

7775
statics: {
78-
7976
getInitialAsyncState: function (params, query, setState) {
80-
// Return a hash with keys named after the state variables
81-
// you want to set, as you normally do in getInitialState,
82-
// except the values may be immediate values or promises.
83-
// The state is automatically updated as promises resolve.
84-
return {
85-
user: getUserByID(params.userID) // may be a promise
86-
};
87-
88-
// Or, use the setState function to stream data!
8977
var buffer = '';
90-
91-
return {
9278

93-
// Same as above, the stream state variable is set to the
94-
// value returned by this promise when it resolves.
79+
return {
80+
user: getUserByID(params.userID) // may be a promise
81+
activity: {}, // an immediate value (not a promise)
9582
stream: getStreamingData(params.userID, function (chunk) {
83+
// `getStreamingData` returns a promise, but also calls back as
84+
// data is received, giving use a chance to update the UI with
85+
// progress
9686
buffer += chunk;
97-
98-
// Notify of progress.
99-
setState({
100-
streamBuffer: buffer
101-
});
87+
setState({ streamBuffer: buffer });
10288
})
103-
10489
};
10590
}
106-
10791
},
10892

10993
getInitialState: function () {

0 commit comments

Comments
 (0)