From 03c1d2c7b92b12894aded1ff203947cf49c8deb3 Mon Sep 17 00:00:00 2001 From: Erik Rasmussen Date: Thu, 30 Jul 2015 17:15:33 +0200 Subject: [PATCH] incorporated PR #67 and added some comments to promise chaining in createTransitionHook() --- src/universalRouter.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/universalRouter.js b/src/universalRouter.js index 65f64720e..0d5b98bac 100755 --- a/src/universalRouter.js +++ b/src/universalRouter.js @@ -11,11 +11,12 @@ const getFetchData = (component={}) => { export function createTransitionHook(store) { return (nextState, transition, callback) => { - Promise.all(nextState.branch - .map(route => route.component) - .filter(getFetchData(component)) - .map(getFetchData) - .map(fetchData => fetchData(store, nextState.params)) + const promises = nextState.branch + .map(route => route.component) // pull out individual route components + .filter((component) => getFetchData(component)) // only look at ones with a static fetchData() + .map(getFetchData) // pull out fetch data methods + .map(fetchData => fetchData(store, nextState.params)); // call fetch data methods and save promises + Promise.all(promises) .then(() => { callback(); // can't just pass callback to then() because callback assumes first param is error }, (error) => {