提交 bc185878 编写于 作者: J Jay Phelps 提交者: Tim Neutkens

change mergeMap -> map in redux-observable example (#3794)

Using `mergeMap` with an inner Observable `of` is the same as using `map` by itself, so this is more idiomatic and clear.
上级 0e044828
import { interval } from 'rxjs/observable/interval'
import { of } from 'rxjs/observable/of'
import { takeUntil, mergeMap, catchError } from 'rxjs/operators'
import { takeUntil, mergeMap, catchError, map } from 'rxjs/operators'
import { combineEpics, ofType } from 'redux-observable'
import ajax from 'universal-rx-request' // because standard AjaxObservable only works in browser
......@@ -13,11 +13,9 @@ export const fetchUserEpic = (action$, store) =>
mergeMap(action => {
return interval(3000).pipe(
mergeMap(x =>
of(
actions.fetchCharacter({
isServer: store.getState().isServer
})
)
actions.fetchCharacter({
isServer: store.getState().isServer
})
),
takeUntil(action$.ofType(types.STOP_FETCHING_CHARACTERS))
)
......@@ -31,12 +29,10 @@ export const fetchCharacterEpic = (action$, store) =>
ajax({
url: `https://swapi.co/api/people/${store.getState().nextCharacterId}`
}).pipe(
mergeMap(response =>
of(
actions.fetchCharacterSuccess(
response.body,
store.getState().isServer
)
map(response =>
actions.fetchCharacterSuccess(
response.body,
store.getState().isServer
)
),
catchError(error =>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册