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

Proposal: async actions #3

Closed
Conrad2134 opened this issue Dec 6, 2017 · 2 comments
Closed

Proposal: async actions #3

Conrad2134 opened this issue Dec 6, 2017 · 2 comments

Comments

@Conrad2134
Copy link

Conrad2134 commented Dec 6, 2017

Currently, if you have an asynchronous action, you are in charge of calling store.setState manually, while synchronous actions can just return the state update, and setState is called after the return. What if actions could return Promises and setState was called after the Promise resolves? Something like this:

// Action
async incrementAsync(state) {
  const response = await fetch("data.json");
  const data = await response.json();
  return { data };
}

// Mapped action
// https://github.com/developit/unistore/blob/master/unistore.js#L78
Promise.resolve(actions[i](store.getState(), ...args)).then(store.setState);
@NekR
Copy link

NekR commented Dec 6, 2017

Sounds exactly how it had to be.

@developit
Copy link
Owner

developit commented Dec 6, 2017

Added and released in 2.2.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants