Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
fix(store.dispatch): Calling
store.dispatch()
directly in your Epic…
…s is now deprecated (#346) The ability to call `store.dispatch()` inside your Epics was originally provided as an escape hatch, to be used rarely, if ever. Unfortunately in practice we've seen a large number of people using it extensively; there has even been popular tutorials teaching it as how you use redux-observable. Instead, Epics should emit actions through the Observable the Epic returns, using idiomatic RxJS. ```js const somethingEpic = (action$, store) => action$.ofType(SOMETHING) .switchMap(() => ajax('/something') .do(() => store.dispatch({ type: SOMETHING_ELSE })) .map(response => ({ type: SUCCESS, response })) ); ``` ```js const somethingEpic = action$ => action$.ofType(SOMETHING) .switchMap(() => ajax('/something') .mergeMap(response => Observable.of( { type: SOMETHING_ELSE }, { type: SUCCESS, response } )) ); ``` `store.dispatch` will be removed from Epics in v1.0.0 of redux-observable. This is unrelated to usage of `store.dispatch` inside your UI components--you will continue to use it there
- Loading branch information