We can create custom operator easiliy on RxJS
Use with redux-observable
For example, we sometimes use tap
and ignoreElements
for debug.
export const pingEpic = (action$) =>
action$.pipe(
ofType("PING"),
tap(console.log),
ignoreElements()
)
This convert to this.
const debug = () => <T>(source: Observable<T>) =>
source.pipe(
tap(console.log),
ignoreElements()
)
export const pingEpic = (action$) =>
action$.pipe(
ofType("PING"),
debug()
)
If you need custom tap function, you can use arguments
const debug = (tapFn = console.log) => <T>(source: Observable<T>) =>
source.pipe(
tap(tapFn),
ignoreElements()
)
export const pingEpic = (action$) =>
action$.pipe(
ofType("PING"),
debug(item => console.log("This is DEBUG => ", item))
)
Top comments (0)