1

I am currently trying to manage data dependencies in a react app. Usually I would just use waitFor. That doesnt help here though, since it won't wait for the async data fetching, just for the sync operations.

Depender:

@bind(Actions.showUserForm)
showUserForm(id) {
  const user = UserStore.getState()[id];
  this.setState({form: someAction(user)});
}

Dependee:

@bind(Actions.getUser, showUserForm.showUser)
getUser(id) {
  this.getInstance().getUser(id);
}

@bind(Actions.getUserSucc)
getUserSucc(user) {
  this.setState({ [user.id]: user })
}

Dependee Source

export default {
  getUser: {
    remote: (state, id) => UserAPI.get(id),
    success: Actions.getUserSucc
  },
};

The Depender needs somehow to wait for the Dependees async response with the user data. I could just listen to the success action, though this would trigger the Depender everytime a user is fetched from the backend.

Is there an idiomatic solution for those kind of problems?

MoeSattler
  • 6,684
  • 6
  • 24
  • 44
  • I raised a similar question here: http://stackoverflow.com/questions/35344635/flux-alt-data-dependency-how-to-handle-elegantly-and-idiomatically – Robert Moskal Apr 25 '16 at 14:53

0 Answers0