mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
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.
This commit is contained in:
parent
0e044828ea
commit
bc185878e8
|
@ -1,6 +1,6 @@
|
||||||
import { interval } from 'rxjs/observable/interval'
|
import { interval } from 'rxjs/observable/interval'
|
||||||
import { of } from 'rxjs/observable/of'
|
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 { combineEpics, ofType } from 'redux-observable'
|
||||||
import ajax from 'universal-rx-request' // because standard AjaxObservable only works in browser
|
import ajax from 'universal-rx-request' // because standard AjaxObservable only works in browser
|
||||||
|
|
||||||
|
@ -13,11 +13,9 @@ export const fetchUserEpic = (action$, store) =>
|
||||||
mergeMap(action => {
|
mergeMap(action => {
|
||||||
return interval(3000).pipe(
|
return interval(3000).pipe(
|
||||||
mergeMap(x =>
|
mergeMap(x =>
|
||||||
of(
|
|
||||||
actions.fetchCharacter({
|
actions.fetchCharacter({
|
||||||
isServer: store.getState().isServer
|
isServer: store.getState().isServer
|
||||||
})
|
})
|
||||||
)
|
|
||||||
),
|
),
|
||||||
takeUntil(action$.ofType(types.STOP_FETCHING_CHARACTERS))
|
takeUntil(action$.ofType(types.STOP_FETCHING_CHARACTERS))
|
||||||
)
|
)
|
||||||
|
@ -31,13 +29,11 @@ export const fetchCharacterEpic = (action$, store) =>
|
||||||
ajax({
|
ajax({
|
||||||
url: `https://swapi.co/api/people/${store.getState().nextCharacterId}`
|
url: `https://swapi.co/api/people/${store.getState().nextCharacterId}`
|
||||||
}).pipe(
|
}).pipe(
|
||||||
mergeMap(response =>
|
map(response =>
|
||||||
of(
|
|
||||||
actions.fetchCharacterSuccess(
|
actions.fetchCharacterSuccess(
|
||||||
response.body,
|
response.body,
|
||||||
store.getState().isServer
|
store.getState().isServer
|
||||||
)
|
)
|
||||||
)
|
|
||||||
),
|
),
|
||||||
catchError(error =>
|
catchError(error =>
|
||||||
of(
|
of(
|
||||||
|
|
Loading…
Reference in a new issue