redux-observable

How to delay one epic until another has emitted a value

余生颓废 提交于 2019-12-09 18:48:01
问题 In redux-observable I need to wait before doing an API request until another epic has completed. Using combineLatest doesn't work, nothing happens after APP_INITIALIZED finishes. I also tried withLatestFrom but neither works. const apiGetRequestEpic = (action$, store) => { return Observable.combineLatest( action$.ofType('APP_INITIALIZED'), action$.ofType('API_GET_REQUEST') .mergeMap((action) => { let url = store.getState().apiDomain + action.payload; return ajax(get(url)) .map(xhr => { return

Debouncing and cancelling with redux-observable

只谈情不闲聊 提交于 2019-12-09 12:09:37
问题 I am trying to create a simple redux-observable epic which debounces and is cancelable. My code: export const apiValidate = action$ => { return action$.ofType(validateRequestAction) .debounceTime(250) .switchMap((action) => ( Observable.ajax({ url: url, method: 'GET', crossDomain: true, headers: { "Content-Type": 'application/json' }, responseType: 'json' }) .map(payload => (new APISuccessValidate())) .takeUntil(action$.ofType(validateCancelAction)) .catch(payload => ([new APIFailureValidate(

Accessing the state from within a redux-observable epic

牧云@^-^@ 提交于 2019-12-08 19:47:37
问题 I am using redux to build a little fusball-manager. Basically it's a page that shows the score of both teams and some buttons to increment them. I have actions like { type:"GOAL_UP", team:"red" } for which the reducer will change the corresponding value (score) in the state. Now I want to add an epic that whenever it encounters a GOAL_UP checks if one of the two teams has won the game. If a team has reached a score of 8, I want it to dispatch a GAME_WON action. My problem is that I have to

Redux-observable: failed jest test for epic

烂漫一生 提交于 2019-12-08 08:16:50
问题 I followed the steps from documentation to test epic. ... store.dispatch({ type: FETCH_USER }); expect(store.getActions()).toEqual([ { type: FETCH_USER }, { type: FETCH_USER_FULFILLED, payload } ]); ... But I get failed because second action is been received some later like following. Test failed Expected value to equal: [{"type": "FETCH_USER"}, {"type": "FETCH_USER_FULFILLED", "payload": [some]}] Received: [{"type": "FETCH_USER"}] Difference: - Expected + Received @@ -1,20 +1,5 @@ Array [

dispatch multiple actions with redux-observable

我只是一个虾纸丫 提交于 2019-12-08 06:56:42
问题 After the user clicks the login button on a form, I want to dispatch an action which will trigger a spinner on the form while the request completes. I've tried the solution posted on this question but I'm getting an error redux-observable dispatch actions Here is the action that's dispatched when the user clicks on the login button: dispatch(startLoginEpic({ login: loginData, from })); Here is my epic: const LoginEpic = (action$, state$) => action$.pipe( ofType(types.START_LOGIN_EPIC), // map

What is the expected behaviour Cancelling async request in Redux-observable using takeUntil

只愿长相守 提交于 2019-12-08 03:50:51
问题 i am new to RXJS, i found Redux-observable canceling async request using takeUntil is very useful. but while i was testing it i found that the actual request is still going on even though we cancel the request.. i have this JSbin code snippet to test. https://jsbin.com/hujosafocu/1/edit?html,js,output here the actual request is not canceling, even if you cancel the request by clicking the cancel (multiple times) button. i am not sure this is how it should be.. if yes, then what does it meant

Chained redux-observable epic only fires correctly once

ぐ巨炮叔叔 提交于 2019-12-08 02:05:18
问题 I've set up an epic that waits for another epic to complete, much like @jayphelps' answer here: Invoking epics from within other epics However I've found that it only seems to run once. After that I can see the CART_CONFIG_READY action in the console but the DO_THE_NEXT_THING action is not triggered. I've tried various combinations of mergeMap and switchMap , with and without take but nothing seems to help. This is (kind of) what my code looks like. import { NgRedux } from '@angular-redux

Return a Promise from Redux Observable

大城市里の小女人 提交于 2019-12-07 15:26:14
问题 Maybe I'm thinking about this wrong, but a common pattern I use with redux-thunk is to return a promise so I can perform some additional actions in the container object when something completes or fails. Using Thunk as an example: Action Creator: const action = ({ data }) => (dispatch) => fetch(`some http url`) .then(response => { if(response.ok) { return response.json(); } return Promise.reject(response); }) Somewhere in the connected component: this.props.action("Some Data") .then(console

RxJS iif arguments are called when shouldn't

人盡茶涼 提交于 2019-12-07 05:39:30
问题 I want to conditionally dispatch some actions using iif utility from RxJS. The problem is that second argument to iif is called even if test function returns false. This throws an error and app crashes immediately. I am new to to the power of RxJS so i probably don't know something. And i am using connected-react-router package if that matters. export const roomRouteEpic: Epic = (action$, state$) => action$.ofType(LOCATION_CHANGE).pipe( pluck('payload'), mergeMap(payload => iif( () => {

Redux-observable: failed jest test for epic

做~自己de王妃 提交于 2019-12-07 03:42:26
I followed the steps from documentation to test epic. ... store.dispatch({ type: FETCH_USER }); expect(store.getActions()).toEqual([ { type: FETCH_USER }, { type: FETCH_USER_FULFILLED, payload } ]); ... But I get failed because second action is been received some later like following. Test failed Expected value to equal: [{"type": "FETCH_USER"}, {"type": "FETCH_USER_FULFILLED", "payload": [some]}] Received: [{"type": "FETCH_USER"}] Difference: - Expected + Received @@ -1,20 +1,5 @@ Array [ Object {"type": "FETCH_USER"}, Object {"type": "FETCH_USER_FULFILLED", "payload": [some]} ] // this is