Open yonekawa opened 8 years ago
Currently, Action needs to call dispatcher.dispatch for async func. For example.
Action
dispatcher.dispatch
func invoke(dispatcher: Dispatcher) { dispatcher.dispatch(self, result: Result(value: result)) }
It has some problem. There is possibilities which developer forgets call dispatch. And I want to hide dispatcher instance from action.
dispatch
This is my ideal.
func invoke() -> Payload { let payload = anyFunc() return payload }
This approach is more robust because compiler warns about missing return value and its type. However, it is difficult because async func can't return value immediately.
My idea is this.
struct ActionA: Action { typealias Payload = Todo func invoke() throws -> Payload { return Todo() } } struct ActionB: AsyncAction { typealias Payload = Todo func invoke() -> Promise<Payload> { return Promise { fulfill, reject in asyncCall() { (todo) in fulfill(todo) } } } }
So, divide action to normal and async. Action can return payload immediately. AsyncAction action uses Promise like as PromiseKit
AsyncAction
Any idea?
I think the idea of middleware of Redux.js would be useful.
Redux.js
Currently,
Action
needs to calldispatcher.dispatch
for async func. For example.It has some problem. There is possibilities which developer forgets call
dispatch
. And I want to hide dispatcher instance from action.This is my ideal.
This approach is more robust because compiler warns about missing return value and its type. However, it is difficult because async func can't return value immediately.
My idea is this.
So, divide action to normal and async.
Action
can return payload immediately.AsyncAction
action uses Promise like as PromiseKitAny idea?