redux-observable

Implementing fromSubscriber in rxjs

送分小仙女□ 提交于 2019-12-04 12:58:00
I ran into an interesting issue today. I'm working on an app where we have file uploads, and we want to implement a progress bar. The app is written using React/Redux/Redux-Observable. I want to dispatch actions for upload progress. Here's what I did to implement it: withProgress(method, url, body = {}, headers = {}) { const progressSubscriber = Subscriber.create(); return { Subscriber: progressSubscriber, Request: this.ajax({ url, method, body, headers, progressSubscriber }), }; } I have a class that I use to make all my ajax requests. this.ajax calls Observable.ajax with the passed in

Is it an efficient practice to add new epics lazily inside react-router onEnter hooks?

允我心安 提交于 2019-12-03 21:49:33
问题 When using redux-observable with react-router, would it make sense to asynchronously add new epics as per the instructions in the documentation here inside onEnter hooks of react-router during route changes? ./epics/index.js import { BehaviorSubject } from 'rxjs/BehaviorSubject'; import { combineEpics } from 'redux-observable'; import { epic1 } from './epic1' import { epic2 } from './epic2' export const epic$ = new BehaviorSubject(combineEpics(epic1, epic2)); export const rootEpic = (action$,

redux-observable epic that doesn't send any new actions

末鹿安然 提交于 2019-12-03 18:54:20
Might be that I'm a noob and not fully understanding how this stuff should work yet, but I have an epic in redux-observable in which I want to use as a way to create a promise which will dispatch an action and wait for a different action before resolving. I've got it working by mapping the action to '__IGNORE__' but I really don't want to do that. Is there any way to just have an epic handle an action, but not pass anything else on? Here's my code: export const waitFor = (type, action) => new Promise((resolve, reject) => { const waitForResult = action$ => action$.ofType(type).do(() => resolve(

How to handle multiple action types in one epic? Any cons of doing the same?

杀马特。学长 韩版系。学妹 提交于 2019-12-01 02:40:45
Pretty new to redux-observables, rxjs and observables. Wanted to know how can I handle another action, say 'ActionTwo' in the same epic const Epic1 = (action$,store) => { return action$.ofType('ActionOne') .mergeMap((action) => { return ajax({'method': 'GET', 'url': 'someUrl') .map(response => resultActoin(action.userId, response.response)); } ); } Something like const Epic1 = (action$){ if('ActionOne') make a API call. if('ActionTwo') make some other API call. else do nothing. } Is it the same API call? If so, ofType() accepts more than one type. You can just do action$.ofType('ActionOne',

Is it an efficient practice to add new epics lazily inside react-router onEnter hooks?

老子叫甜甜 提交于 2019-11-30 23:41:36
When using redux-observable with react-router, would it make sense to asynchronously add new epics as per the instructions in the documentation here inside onEnter hooks of react-router during route changes? ./epics/index.js import { BehaviorSubject } from 'rxjs/BehaviorSubject'; import { combineEpics } from 'redux-observable'; import { epic1 } from './epic1' import { epic2 } from './epic2' export const epic$ = new BehaviorSubject(combineEpics(epic1, epic2)); export const rootEpic = (action$, store) => epic$.mergeMap(epic => epic(action$, store) ); export { rootEpic }; ...routes/SomePath/index

How to handle multiple action types in one epic? Any cons of doing the same?

元气小坏坏 提交于 2019-11-30 23:13:24
问题 Pretty new to redux-observables, rxjs and observables. Wanted to know how can I handle another action, say 'ActionTwo' in the same epic const Epic1 = (action$,store) => { return action$.ofType('ActionOne') .mergeMap((action) => { return ajax({'method': 'GET', 'url': 'someUrl') .map(response => resultActoin(action.userId, response.response)); } ); } Something like const Epic1 = (action$){ if('ActionOne') make a API call. if('ActionTwo') make some other API call. else do nothing. } 回答1: Is it

How to debug rxjs5?

≡放荡痞女 提交于 2019-11-30 11:30:16
On RxJS - Goals I read that their goal is better debuggability: Goals Provide more debuggable call stacks than preceding versions of RxJS I have just started to use redux-observable which is quite easier for me to understand comparing it to redux-saga as I am already used to the reactive style with lodash and ramda (ok, fp style maybe ;). I was surprised that it's not possible to debug it yet. Is it true? If so, then I gotta switch to redux-saga s maybe or stick with redux-thunk . Edit based on Jay Phelps's answer By debugging I meant: "How to set a breakpoint on e.g. observable.map(...) in a

redux-observable - dispatch multiple redux actions in a single epic

泪湿孤枕 提交于 2019-11-30 04:18:50
I'm looking for way of dispatching multiple redux actions in a single Epic of redux-observable middleware. Let's assume I have following Epic. Everytime when SEARCH event happens, Epic loads data from backend and dispatches RESULTS_LOADED action. searchEpic = (action$) => action$ .ofType('SEARCH') .mergeMap( Observable .fromPromise(searchPromise) .map((data) => { return { type: 'RESULTS_LOADED', results: data } }) ) Now, let's assume that I need dispatch additional action when the searchPromise is resolved. The simplest way of doing so seems to have a second epic that will listen to RESULTS

Why use Redux-Observable over Redux-Saga?

浪子不回头ぞ 提交于 2019-11-29 18:41:24
I have used Redux-Saga . Code written with it is easy to reason so far, except JS generator function is messing up my head from time to time. From my understanding, Redux-Observable can achieve the similar job that handles side effects but without using generator function. However, docs from Redux-Observable does not provide many opinions of why it is superior against Redux-Saga. I would want to know whether not using generator function is the only benefit of using Redux-Observable. And what could be the downsides, gotcha or compromises from using Redux-Observable instead of Redux-Saga? Thanks

How to debug rxjs5?

最后都变了- 提交于 2019-11-29 11:46:05
问题 On RxJS - Goals I read that their goal is better debuggability: Goals Provide more debuggable call stacks than preceding versions of RxJS I have just started to use redux-observable which is quite easier for me to understand comparing it to redux-saga as I am already used to the reactive style with lodash and ramda (ok, fp style maybe ;). I was surprised that it's not possible to debug it yet. Is it true? If so, then I gotta switch to redux-saga s maybe or stick with redux-thunk . Edit based