markdalgleish / redial

Universal data fetching and route lifecycle management for React etc.
1.1k stars 42 forks source link

Ensure rendering order with async trigger calls #14

Closed autarc closed 8 years ago

autarc commented 8 years ago

The updated example solves the previous issue (#13).

autarc commented 8 years ago

@svrcekmichal It does. Since the callback is automatically called after all hooks are resolved - the transition applies just like before. The only difference is the execution order which happens as expected and therefore gets the data before calling rendering.

svrcekmichal commented 8 years ago

@Autarc thats what I am talking about, @markdalgleish don't want to wait for data. He want component to be rendered without data with loading indicators and then fetch data and re-render

look at this issue

jaredpalmer commented 8 years ago

@Autarc I don't think you should use redial for this use case. All you need is little helper function like:

// fetchComponentData.js
export default function fetchComponentData(dispatch, components, params) {
  const needs = components.reduce( (prev, current) => {

    return current ? (current.needs || []).concat(prev) : prev;
  }, []);

  const promises = needs.map(need => dispatch(need(params)));

  return Promise.all(promises);
}

If you search github for 'fetchComponentData', you'll find 5 or 6 repos using this as a resolver.

markdalgleish commented 8 years ago

Sorry, closing this for the same reason as #19.