Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
4 changed files
with
13 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const deprecationsSeen = {}; | ||
|
||
export const deprecate = (typeof console === 'object' && typeof console.warn === 'function') | ||
? msg => { | ||
if (!deprecationsSeen[msg]) { | ||
deprecationsSeen[msg] = true; | ||
console.warn(`redux-observable | DEPRECATION: ${msg}`); | ||
} | ||
} | ||
: () => {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters