Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to dispatch child async tasks #92

Open
arasmussen opened this issue Dec 3, 2016 · 2 comments
Open

Provide a way to dispatch child async tasks #92

arasmussen opened this issue Dec 3, 2016 · 2 comments
Labels

Comments

@arasmussen
Copy link

I have a container component that renders several other container components. Some of those children container components don't show up in the router match but still have data they need to load. It'd be great if there was some way I could explicitly specify in the parent's asyncConnect to call its children's async tasks.

@arasmussen
Copy link
Author

arasmussen commented Dec 3, 2016

Maybe I could do something like:

const asyncFetch = {
  promise: ({store: {dispatch, getState}}) => {
    return dispatch(loadViewer());
  },
};

@asyncConnect([asyncFetch])
export default class ChildContainer extends Component {
  static asyncFetch = asyncFetch;
  // ...
};
import ChildContainer from './ChildContainer';

@asyncConnect([
  ChildContainer.asyncFetch,
]);
export default class ParentContainer extends Component {
  // ...
};

This way if the ChildContainer is in the route match, then it'll trigger the asyncConnect. If not, then the parent must know this and explicitly add it to its own asyncConnect. Works for me, any feedback on this method?

@AVVS
Copy link
Member

AVVS commented Jan 6, 2017

This could work as long as you make sure not to forget this :)

@AVVS AVVS added the question label Jan 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants