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][Any Idea]Invoke action without explicit dispatch call #18

Open
yonekawa opened this issue Dec 15, 2015 · 1 comment
Open

Comments

@yonekawa
Copy link
Owner

Currently, Action needs to call dispatcher.dispatch for async func.
For example.

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.

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

Any idea?

@mortyccp
Copy link

I think the idea of middleware of Redux.js would be useful.

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

No branches or pull requests

2 participants