goatslacker / goatslacker/alt

How to handle data dependencies with Async

Open
#644 0 comments 3 reactions 0 assignees View on GitHub
question
Dominant language
JavaScript
Stars
3.4k
Forks
312
PR merge metrics
No merged PRs in 30d

Description

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

Depender:

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

Dependee:

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

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

Dependee Source

``` JavaScript
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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.