Last active
April 9, 2018 07:48
-
-
Save dbismut/b2e517e6675edac70fbb6dee75798877 to your computer and use it in GitHub Desktop.
Part 1 - The data middleware that will fetch the data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import transitionPath from 'router5-transition-path'; | |
export default routes => router => (toState, fromState) => { | |
const { toActivate } = transitionPath(toState, fromState); | |
const onActivateHandlers = toActivate | |
.map(segment => | |
routes.find(r => r.name === segment).onActivate(toState.params) | |
) | |
.filter(Boolean); | |
return Promise.all(onActivateHandlers).then(data => { | |
const routeData = data.reduce( | |
(accData, rData) => Object.assign(accData, rData), | |
{} | |
); | |
return { ...toState, data: routeData }; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment