Skip to content

Instantly share code, notes, and snippets.

@jaredpalmer
Created March 18, 2016 03:14
Show Gist options
  • Save jaredpalmer/f8c1d620a513bf975f7f to your computer and use it in GitHub Desktop.
Save jaredpalmer/f8c1d620a513bf975f7f to your computer and use it in GitHub Desktop.
Simple Isomorphic React Resolver
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