redux-observable

Dispatch an action in response to cancellation

。_饼干妹妹 提交于 2019-12-22 08:06:33
问题 I started with the cancellation recipe from the redux-observable docs and want to extend it a bit. Basically I have a scenario where after the cancellation is triggered, using takeUntil I want dispatch another action to cleanup, etc. This is what I came up with so far: https://jsbin.com/zemenu/195/edit?js,output Start a "Fetch User Info" and then hit Cancel. I want it to execute actions in this order: - USER/FETCH - REQUEST/STARTED - USER/CANCELLED - REQUEST/CANCELLED This works in the way I

How to chain actions and epics?

送分小仙女□ 提交于 2019-12-21 17:44:08
问题 I'm familiar with React and Redux but quite new to RxJS and redux-observable. I'm working on a flow that I've managed to solve with something that looks like this: const reducer = (state, action) => { switch(action.type) { // some other cases here case Types.LOCATION_GEOCODED: const { address, place_id } = action return {...state, address, place_id } } } const updateLocationEpic = (action$, store) => action$.ofType(Types.UPDATE_LOCATION) .mergeMap((action) => Observable.fromPromise

Composing and sequencing multiple epics in redux-observable

我与影子孤独终老i 提交于 2019-12-21 05:57:01
问题 I have a problem that I don't know how to resolve. I have two epics that do requests to api and update the store: const mapSuccess = actionType => response => ({ type: actionType + SUCCESS, payload: response.response, }); const mapFailure = actionType => error => Observable.of({ type: actionType + FAILURE, error, }); const characterEpic = (action$, store) => action$.ofType(GET_CHARACTER) .mergeMap(({ id }) => { return ajax(api.fetchCharacter(id)) .map(mapSuccess(GET_CHARACTER)) .catch

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

白昼怎懂夜的黑 提交于 2019-12-21 05:48:11
问题 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

Cancel previous requests and only fire the latest request with redux observable

孤街浪徒 提交于 2019-12-18 12:38:42
问题 So I have use case where I update the api request when the map is moved - but it could generate several rapid fire requests with small map movements - and I want to cancel all the inflight requests except for the last one. I can use debounce to only send requests after a delay. However I still want to cancel any old requests if they happen to still be in process. const fetchNearbyStoresEpic = action$ => action$.ofType(FETCH_NEARBY_STORES) .debounceTime(500) .switchMap(action => db.collection(

Use fetch instead of ajax with redux-observable

China☆狼群 提交于 2019-12-17 19:34:23
问题 In redux-observable is it possible to use isomporphic-fetch instead of Rx.DOM.ajax? 回答1: (Note: RX.DOM.ajax is from RxJS v4 , and doesn't work with redux-observable which requires RxJS v5. The equivalent in v5 is Rx.Observable.ajax or import { ajax } from 'rxjs/observable/ajax'; ) It is indeed possible to use fetch() as well as any other AJAX API; though some adapt easier than others! The fetch() API returns a Promise , which RxJS v5 has built-in support for . Most operators that expect an

Redux-Observable multiple actions in single epic

浪尽此生 提交于 2019-12-13 04:13:59
问题 I'm new to this and there are several similar questions such as redux-observable - dispatch multiple redux actions in a single epic but I can't see how they apply to my usecase. I'm using a Subject to emit multiple events based on processing a file and uploading to a server export function UploadSceneWithFile(scene){ const subject$ = new Subject() FileToScenePreview(scene,scene.file).then(res => subject$.next(res)) const uploader = new S3Upload({ .... onError:()=>subject$.next('error'),

Redux Observable: If the same action is dispatched multiple times, how do I cancel one of them?

白昼怎懂夜的黑 提交于 2019-12-13 03:49:16
问题 Say, I have this epic: export const getUserEpic = action$ => action$ .ofType(t.GET_USER) .mergeMap(action => Observable .from(query.findUser(action.uid)) .map(user => ({ type: t.GET_USER_SUCCESS, user })) .takeUntil(action$.ofType(t.GET_USER_CANCELLED)) Then, somewhere I dispatched t.GET_USER multiple times: dispatch({ type: t.GET_USER, uid: 'uid1' }) dispatch({ type: t.GET_USER, uid: 'uid2' }) dispatch({ type: t.GET_USER, uid: 'uid3' }) How do I cancel one of them? For example: dispatch({

Websocket epic that receives connection & message requests and emits messages & connection status updates

南楼画角 提交于 2019-12-13 03:30:56
问题 I am hoping to create an redux-observable epic that can sit separate to the rest of my application. It needs to: Listen for incoming action of { type: "SOCKET_TRY_CONNECT" } , this should also probably disregard any additional SOCKET_TRY_CONNECT events while it is connected. Additionally listen for messages to be sent, maybe { type: "SOCKET_MESSAGE_SEND", data } Emit outgoing actions { type: "SOCKET_CONNECTED" } , { type: "SOCKET_DISCONNECTED", error } and { type: "SOCKET_MESSAGE_RECEIVE",

React + Redux-Observable Timeout Marble Testing

强颜欢笑 提交于 2019-12-12 18:24:09
问题 I am creating a web app using React and Redux Observables and I would like to create a unit test for the timeout scenario of one of my epics. Here is the Epic: export const loginUserEpic = (action$: ActionsObservable<any>, store, { ajax, scheduler }): Observable<Action> => action$.pipe( ofType<LoginAction>(LoginActionTypes.LOGIN_ACTION), switchMap((action: LoginAction) => ajax({ url, method: 'POST', headers: { 'Content-Type': 'application/json' }, body: { email: action.payload.username,