@@ -67,43 +67,27 @@ var User = React.createClass({
67
67
```
68
68
69
69
But you can get fancier...
70
-
71
70
72
71
``` js
73
72
var User = React .createClass ({
74
-
75
73
mixins: [ Router .AsyncState ],
76
74
77
75
statics: {
78
-
79
76
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!
89
77
var buffer = ' ' ;
90
-
91
- return {
92
78
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)
95
82
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
96
86
buffer += chunk;
97
-
98
- // Notify of progress.
99
- setState ({
100
- streamBuffer: buffer
101
- });
87
+ setState ({ streamBuffer: buffer });
102
88
})
103
-
104
89
};
105
90
}
106
-
107
91
},
108
92
109
93
getInitialState : function () {
0 commit comments