Re:Understanding redux-saga: From action creators to sagas
by willriker on Thursday October 12, 2017 @12:58PM
(#15459393)
One key advantage of redux-saga is testability-- since sagas are essentially functions with their arguments passed in by the saga middleware, it is easy to inject mocked dependencies in a test environment.
[ Parent
| on HN ]
Re:Understanding redux-saga: From action creators to sagas
by rhinoceraptor on Thursday October 12, 2017 @01:46PM
(#15459755)
It isn't hard to create easily testable redux actions using redux-thunk. When you configure the redux store you can use `thunk.withExtraArgument` to provide a service object to your actions, so you can write something like this:
const getDog = dogId => (dispatch, getState, { DogApi }) => {
dispatch(fetchingDog(dogId))
DogApi.getDogById(dogId, (err, dog) => {
dispatch(err ? dogFetchError(err) : fetchedDog(dog))
})
}
...
dispatch(getDog(123))