Closed Paul-Todd closed 4 years ago
Interesting use-case, and understand why it would lead to more readable code.
@johnpryan Whatcha think? Should we do this? The change is simple, but would probably requires a major version bump since it's an API change.
This is an interesting idea - for now, I would like to put a pin in this for a 4.0 release, and include it with other breaking changes that may come up
Thanks guys. I am working on a medium.com article for firebase signin using this approach so it would make the code clearer but I will just reference this request then.
Do you want to close it or let me close it?
@Paul-Todd I think we should leave this open for now. Once this is fixed (pull requests welcome!) we could release it as a "pre-release" (4.0.0-alpha) so that you can use it right away.
Any updates on this ? @johnpryan
I haven't found time to work on this but if someone would like to claim it and make a PR that would be the fastest way.
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.