Running thunk with parameters?
etodanik opened this issue · 2 comments
etodanik commented
Is it possible to pass parameters to the thunk action? The example doesn't cover that option.
mjarvis commented
Yes, you can always write a function that returns a thunk to pass in parameters.
func thunk(foo: Int) -> Thunk<MyState> {
return Thunk<MyState> { dispatch, getState in
if getState!.loading {
return
}
// Use `foo`
dispatch(RequestStart())
api.getSomething() { something in
if something != nil {
dispatch(RequestSuccess(something))
} else {
dispatch(RequestError())
}
}
}
}
store.dispatch(thunk(foo: 1))
etodanik commented
Thanks :) This is perfect, however, maybe it would be good to have this in README.md? As I imagine this to be a pretty FAQ