Skip to content

Proposal - have dispatch return original action #26

@Paul-Todd

Description

@Paul-Todd

I am trying to port some promise based code from node and with redux thunks it was easy to return a promise from the action. What would be helpful would be if the dispatch method on the store returned the action then we could do something like:

With a LoginAction object add a Completer property and also a loginCompleted method that returns a future from the Completer. We intercept the LoginAction in the middleware and do some async stuff then call the completer to complete the action. This would keep the async flow in for example a button handler located in the button handler and allow integration with navigators and the ui in a predictable and easy manner.

class Action {
final completer = new Completer();

loginCompleted() { return completer.future; }
}

store.dispatch(action).loginCompleted().then((result) => print('logged in state $result');

The middleware will take the action and do some async stuff. when the middleware async operation completed the completer.complete will be called and the future completes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions