Skip to content

Proposal: async actions #3

@Conrad2134

Description

@Conrad2134

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions