You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update Flux Dispatcher.dispatch and waitFor examples
The previous examples didn't properly work when 1) a Store callback does waitFor on Stores that haven't been reached yet and 2) a Store callback waits on another Store that is already waiting. The updated example uses constructs Promises up front and then asynchronously resolves them.
@@ -583,18 +591,18 @@ Adding Dependency Management to the Dispatcher
583
591
584
592
As I said previously, our Dispatcher implementation is a bit naive. It's pretty good, but it will not suffice for most applications. We need a way to be able to manage dependencies between Stores. Let's add that functionality with a waitFor() method within the main body of the Dispatcher class.
585
593
586
-
We'll need another public method, waitFor().
594
+
We'll need another public method, waitFor(). Note that it return a Promise that can in turn be returned from the Store callback.
587
595
588
596
```javascript
589
597
/**
590
598
* @param{array}promisesIndexes
591
599
* @param{function}callback
592
600
*/
593
601
waitFor:function(promiseIndexes, callback) {
594
-
var selectedPromises =_promises.filter(function(/*object*/_, /*number*/j) {
595
-
returnpromiseIndexes.indexOf(j) !==-1;
602
+
var selectedPromises =promiseIndexes.map(function(index) {
0 commit comments