redux-observable

RxJs How to set default request headers?

亡梦爱人 提交于 2019-12-12 09:19:52
问题 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 =>

ReduxObservable cancellation based on action type and its data

我的梦境 提交于 2019-12-11 16:54:47
问题 I have React app which uses redux-observable with typescript. In this scenario, FetchAttribute Action gets triggered with a id and then make an ajax call. In certain case, I would want to cancel the ajax request if "FETCH_ATTRIBUTE_CANCEL" action was triggered with the same id as of "FetchAttributeAction" action. action$.ofType(FETCH_ATTRIBUTE) .switchMap((request: FetchAttributeAction) => { return ajax.getJSON(`/api/fetch-attribute?id=${request.id}`) .flatMap((fetchUrl) => { // return new

Redux-observable: how to wait for multiple async requests then perform action in an epic

让人想犯罪 __ 提交于 2019-12-11 16:15:26
问题 I'd like to wait for the two http requests below to finish before triggering another action. However, the http requests were not fired. Only the DASHBOARD_INIT action was triggered: export const dashboardInitEpic = (action$: any) => action$.ofType(InitActionTypes.DASHBOARD_INIT) .switchMap((action: ActionDashboardInit) => zip$( of$(fetchConfig(action.payload)), of$(fetchPermission(action.payload)) ).switchMap(() => zip$( action$.ofType(ActionTypes.FETCH_CONFIG_FULFILLED).take(1), action$

rxjs - How to retry after catching and processing an error with emitting something

青春壹個敷衍的年華 提交于 2019-12-11 15:12:15
问题 I'm using rxjs v5.4.3 , redux-observable v0.16.0 . in my application, I'd like to achieve below: an user has auth token, and refresh token to regenerate auth token. the user requests with auth token. (by emitting REQUEST action) if it failed, request regenerating auth token with refresh token. if refreshed, emit TOKEN_REFRESHED action to update auth token, and do not emit REQUEST_FAILURE. if refreshing failed, emit REQUEST_FAILURE after refreshing(and updating auth token reducer), retry

How to compare actions data in Observable stream?

只谈情不闲聊 提交于 2019-12-11 15:08:59
问题 I'm using Redux and have problem with RxJs. Let's say that one action was fired 3 times (type: 'OPEN') during 2 secs. Action is sending some data to Redux state. First and third fired are bringing the same data, but second not. All of them have delays before coming to bring some effects. I want Observable to notice, that action 1 and action 3 have the same data and change the order of output. From 1, 2, 3 => 2, 3. The first one should be deleted because of action nr 3. const

In redux-observable, how can I measure the epics duration time when running complete?

送分小仙女□ 提交于 2019-12-11 05:35:33
问题 In the majority situation, epics listen an action and emit an action, many async task in it. I want to measure the duration of epics between the action in and action out. How can I do this? 回答1: You can measure the time between tasks using Performance.now() : var t0 = performance.now(); doSomething(); var t1 = performance.now(); console.log("Call to doSomething took " + (t1 - t0) + " milliseconds."); In the context of your actions and epics, you could include the timestamp in the initial

Proper Use of Redux-Ovservable ajax http methods: put, delete, post

核能气质少年 提交于 2019-12-11 05:14:50
问题 I'm new to Redux and Redux-Observable. I'm having success in getting information from a rest API with GET and GET(ID), but I cannot get the Delete and Post to work. Sample code below that is issuing a GET request: [EPIC File] import { debounceTime, Observable } from 'rxjs'; import { ajax } from 'rxjs/observable/dom/ajax'; import ActionTypes from '../actions/ActionTypes'; import { receiveFeedBack, receiveDeleteFeedBackId, receiveFeedBackId } from '../actions/FeedBackActions'; export const

RxJS: takeUntil with multiple actions and different filters?

烈酒焚心 提交于 2019-12-11 04:46:34
问题 I have an Observable that I want to continue executing until: 1) the uploadActions.MARK_UPLOAD_AS_COMPLETE action is called with a certain payload OR 2) the uploadActions.UPLOAD_FAILURE action is called with any payload This is as far as I could get (and doesn't work): return Observable.interval(5000) .takeUntil( action$ .ofType( uploadActions.UPLOAD_FAILURE, uploadActions.MARK_UPLOAD_AS_COMPLETE ) .filter(a => { // <---- this filter only applies to uploadActions.MARK_UPLOAD_AS_COMPLETE const

How to create generic async request epics that uses typesafe-actions AsyncCreator to simplify handling api request flows in Redux

元气小坏坏 提交于 2019-12-11 01:14:04
问题 I am a newbie struggling to understand the best architecture for relating epics to async actions in Typescript redux environment.... Is it possible to create a generic async request epic for a given typesafe-actions AsyncCreator instance? I have had a try with the code below but lose type information on the action payload....only the type property is recognised on the filtered action....The transpilation error that I receive is... Property 'payload' does not exist on type 'ReturnType<

Independent chain cancellation in redux-observable?

删除回忆录丶 提交于 2019-12-10 10:06:32
问题 I'm new to RxJS. In my app I need independent cancellation of deferred action. Here's a working example (the delay is 3 seconds). But when I choose to delete multiple items and cancel one of them, then canceled all at once. Epic code: const itemsEpic = action$ => action$.ofType('WILL_DELETE') .flatMap(action => Observable.of({type: 'DELETE', id: action.id}) .delay(3000) .takeUntil(action$.ofType('UNDO_DELETE')) ) I think I need to pass an id to takeUntil operator, but I don't know how to do