Skip to content

Instantly share code, notes, and snippets.

@turadg
Created September 24, 2015 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save turadg/aebe1b4db2a4b0885507 to your computer and use it in GitHub Desktop.
Save turadg/aebe1b4db2a4b0885507 to your computer and use it in GitHub Desktop.
/**
* The router runs this navigate action once a new route is resolved.
* This returns a promise that must be satisfied before the render
* starts. The promise consists of all actions that each handler
* in the route declares that it needs before navigating.
*
* WHEN we upgrade react-router to 1.0, we should revisit this design
* https://github.com/rackt/react-router/pull/1158
*
* @return {Promise} to satisfy all the dependencies of the route
*/
navigate: (actionContext, payload) => {
actionContext.dispatch('CHANGE_ROUTE', payload);
var handlers = payload.routes.map((route) => route.handler);
var allActionDependencies = _(handlers.map((h) => h.navigateActionDependencies)).
chain().flatten().compact().value();
var allPromises = allActionDependencies.map(
// pass the payload from this navigate action
(action) => actionContext.executeAction(action, payload)
);
// navigation ready once all dependent promises are satisifed
return Q.all(allPromises);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment