ReSwift/ReSwift-Thunk

Running thunk with parameters?

etodanik opened this issue · 2 comments

Is it possible to pass parameters to the thunk action? The example doesn't cover that option.

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))

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