Skip to content

Commit

Permalink
incorporated PR #67 and added some comments to promise chaining in cr…
Browse files Browse the repository at this point in the history
…eateTransitionHook()
  • Loading branch information
Erik Rasmussen committed Jul 30, 2015
1 parent 3138e30 commit 03c1d2c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/universalRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 03c1d2c

Please sign in to comment.