redux-observable

redux-observable Promise is not getting resolved in unit test

别说谁变了你拦得住时间么 提交于 2019-12-06 17:21:09
问题 I am trying to test this epic https://github.com/zarcode/unsplashapp/blob/master/src/epics/photos.js . Problem is that map never happens when I run test (which I assume means that Promise never resolves), so photosSuccess action never happens also: export const loadPhotosToList = (action$: Observable<Action>, state$: Object): Observable<Action> => { const state = (photosFilter: PhotosFilter) => state$.value.photos[photosFilter]; return action$ // .ofType(ACTION.FETCH_PHOTOS_REQUESTED) .pipe(

Implementing fromSubscriber in rxjs

♀尐吖头ヾ 提交于 2019-12-06 08:43:06
问题 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

Chained redux-observable epic only fires correctly once

拈花ヽ惹草 提交于 2019-12-06 05:54:11
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/store'; import { Observable } from 'rxjs/Observable'; import { ActionsObservable } from 'redux-observable'

Return a Promise from Redux Observable

别等时光非礼了梦想. 提交于 2019-12-06 01:44:23
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.log) .catch(error => console.error("ERROR")); Is there a clean way of doing something similar in Redux

RxJS iif arguments are called when shouldn't

ε祈祈猫儿з 提交于 2019-12-05 09:53:59
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( () => { console.log('NOT LOGGED'); return /^\/room\/\d+$/.test(payload.location.pathname); // set as '/login' },

Invoking epics from within other epics

 ̄綄美尐妖づ 提交于 2019-12-05 05:26:19
问题 First of all many props for this awesome library! I am still struggling with an use case though. I would like to call another epic first and wait till it completes before continuing the current epic. Let's say I have a form where an user can change things. Before loading other data into the form, I want to save the current changes first. Any thoughts on this? 回答1: Sounds like you want: if one epic would like to kick off another epics work and wait for it to complete before proceeding. One

redux-observable Promise is not getting resolved in unit test

限于喜欢 提交于 2019-12-04 22:56:58
I am trying to test this epic https://github.com/zarcode/unsplashapp/blob/master/src/epics/photos.js . Problem is that map never happens when I run test (which I assume means that Promise never resolves), so photosSuccess action never happens also: export const loadPhotosToList = (action$: Observable<Action>, state$: Object): Observable<Action> => { const state = (photosFilter: PhotosFilter) => state$.value.photos[photosFilter]; return action$ // .ofType(ACTION.FETCH_PHOTOS_REQUESTED) .pipe( filter((a: Action) => a.type === ACTION.FETCH_PHOTOS_REQUESTED && ((state(a.filter).loadingState ===

RxJs How to set default request headers?

做~自己de王妃 提交于 2019-12-04 19:21:58
Not sure is there any way to set default request headers in rxjs like we do with axios js as- axios.defaults.headers.common['Authorization'] = 'c7b9392955ce63b38cf0901b7e523efbf7613001526117c79376122b7be2a9519d49c5ff5de1e217db93beae2f2033e9'; Here is my epic code where i want to set request headers - export default function epicFetchProducts(action$, store) { return action$.ofType(FETCH_PRODUCTS_REQUEST) .mergeMap(action => ajax.get(`http://localhost/products?${action.q}`) .map(response => doFetchProductsFulfilled(response)) ); } Please help. It's not possible to set default headers for all

Composing and sequencing multiple epics in redux-observable

北城以北 提交于 2019-12-04 17:02:04
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(mapFailure(GET_CHARACTER)); }); const planetsEpic = (action$, store) => action$.ofType(GET_PLANET) .mergeMap((

How to delay one epic until another has emitted a value

六月ゝ 毕业季﹏ 提交于 2019-12-04 14:56:48
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 {type: types.API_RESPONSE, payload: xhr.response}; }) .catch(error => { return Observable.of({ type: