pipe( ofType(initActions.type), mergeMap(() => [ listOutdatedPackagesListener(), searchPackagesListener(), viewPackageListener(), installPackageListener(), updatePackagesListener(), uninstallPackagesListener(), npmAuditListener(), npmDoctorListener(), npmInitListener(), npmDedupeListener(), npmCacheListener() ]) )
/** * Send ipc event to main process to handle npm-dedupe */ const npmRunDedupeEpic = (action$, state$) => action$.pipe( ofType(runDedupe.type), tap(({ payload }) => { const { common: { mode, directory } } = state$.value; ipcRenderer.send('npm-dedupe', { ...payload, mode, directory }); }), mergeMap(() => [ updateLoader({ loading: true, message: iMessage('info', 'deduping') })]), )
runCache.type ), mergeMap(({ payload }) => { const { packages, cmd } = payload || {}; const [runningCommand] = cmd;
ofType(addNotification.type), withLatestFrom(state$), mergeMap(values => { const [notification, state] = values; const {
const initEpic = (action$, state$) => action$.pipe( ofType(setPackagesStart.type), mergeMap(({ payload: { channel, options } }) => { const { ui: { paused },
source .pipe( delay(5000), mergeMap(val => of(`Delayed by ${val}ms`).pipe(delay(val))), ) .subscribe(val => console.log(`With mergeMap: ${val}`))
const pipeIf = (predicate, ...operators) => { predicate = _.isFunction(predicate) ? predicate : _.constant(predicate); return observable => observable.pipe( // @ts-ignore mergeMap(v => (predicate(v) ? of(v).pipe(...operators) : of(v))) ); }
this.query$.pipe( first(), mergeMap(value => from(request(value))) ).subscribe({ next: response => { this.setFetching(false) if (response.status !== 200) { this.setData(response.data.message) } else { this.setData(response.data) } } })
source.pipe( mergeMap(val => { //throw error for demonstration if (val > 5) return throwError('Error!'); return of(val); }), //retry 2 times on error retry(2), )
const commentsFetchEpic: Epic<IPayloadAction> = (actions$) => actions$.pipe( ofType(commentsActions.fetch.started.type), mergeMap((action: IPayloadAction) => concat( of(commentsActions.loading({ isLoading: true })), ajax.getJSON(action.payload.url).pipe( map((comments: IComments[]) => commentsActions.fetch.done({ params: action.payload.url, result: { comments } })), catchError(_ => of(commentsActions.fetch.failed({ params: action.payload.url, error: { hasError: true } }))), ), of(commentsActions.loading({ isLoading: false })), )), )
// using mergeMap Rx.from([1,2,3,4]).pipe( Operators.mergeMap((param) => { if(counter++%2 == 0){ return getData1(param) }else{ return getData2(param) } }) ).subscribe(val => console.log(val));
const userEpic = action$ => action$.pipe( ofType(FETCH_USER), mergeMap(action => ajax.getJSON(`https://api.github.com/users/${action.payload}`).pipe( map(response => fetchUserSuccess(response)) )) )
const fetchStatsEpic = action$ => action$.pipe( ofType(actions.FETCH_STATS), mergeMap(action => { return ajax({ method: 'GET', url: '/motionstats' }).pipe( map(json => fetchStatsFulfilled(json.response.aggregations)) ) } ) )
/** * Send ipc event to main process to handle npm-cache */ const npmRunCacheEpic = (action$, state$) => action$.pipe( ofType(runCache.type), tap(({ payload }) => { const { common: { mode, directory } } = state$.value; ipcRenderer.send('npm-cache', { ...payload, mode, directory }); }), mergeMap(() => [ updateLoader({ loading: true, message: iMessage('info', 'cacheRunning', { '%action%': 'verify' }) })]), )
source .pipe( delay(5000), mergeMap(val => of(`Delayed by ${val}ms`).pipe(delay(val))), ) .subscribe(val => console.log(`With mergeMap: ${val}`))