Created
March 18, 2016 03:14
-
-
Save jaredpalmer/f8c1d620a513bf975f7f to your computer and use it in GitHub Desktop.
Simple Isomorphic React Resolver
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
export default function fetchComponentData(dispatch, components, params) { | |
const needs = components.reduce( (prev, current) => { | |
return Object.keys(current).reduce( (acc, key) => { | |
return current[key].hasOwnProperty('needs') ? current[key].needs.concat(acc) : acc | |
}, prev) | |
}, []); | |
const promises = needs.map(need => dispatch(need(params))); | |
return Promise.all(promises); | |
} | |
// 個別元件內部抓取所需資料 | |
export function fetchNeeds( props, needs ){ | |
const { params, dispatch } = props; | |
needs.map( need => dispatch(need(params)) ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment