rxjs

How to test race condition of a redux observable epic

霸气de小男生 提交于 2020-01-06 05:47:32
问题 I have a use case where I need to cancel an Ajax call and do something else in an epic. There's an example in the redux-observable doc which fits my need exactly. However, when I try to test the racing condition in my epic, the "cancelation" doesn't seem to work. The example code is like: import { ajax } from 'rxjs/ajax'; const fetchUserEpic = action$ => action$.pipe( ofType(FETCH_USER), mergeMap(action => race( ajax.getJSON(`/api/users/${action.payload}`).pipe( map(response =>

Catch circular dependency between observables

拈花ヽ惹草 提交于 2020-01-06 04:12:07
问题 I have a user-programming scenario where user can end up creating two observables that depend on each other. RxJS does not allow circular dependencies, as far as I can see, the memory or stack reaches its limits and the onError callback is triggered with the value true . How to detect the circular dependency explicitly and throw a more descriptive error message? This codes illustrates how to create a circular dependency in RxJS: var obsA, obsB; obsA = Rx.Observable .returnValue(42)

Angular 7 sequntially subscribing

独自空忆成欢 提交于 2020-01-05 11:53:40
问题 I am subscribing two methods on ngonit but the result of the other method getTest() is coming very late. I am also subscribing other methods and the result of those methods are displaying in between the two methods which I had shared below. Can you please help me how to get the result of the two methods sequentially not with any delay. export class SomeComponent implements OnInit { constructor(public _auth: SomeService, private _route: ActivatedRoute, private) { ngOnInit() { this._route

Angular 7 sequntially subscribing

有些话、适合烂在心里 提交于 2020-01-05 11:52:59
问题 I am subscribing two methods on ngonit but the result of the other method getTest() is coming very late. I am also subscribing other methods and the result of those methods are displaying in between the two methods which I had shared below. Can you please help me how to get the result of the two methods sequentially not with any delay. export class SomeComponent implements OnInit { constructor(public _auth: SomeService, private _route: ActivatedRoute, private) { ngOnInit() { this._route

How to handle async function in redux-observable?

。_饼干妹妹 提交于 2020-01-05 09:04:37
问题 I am using RxJS and redux-observable. I am trying to read file in epic. In my case, I have to do it in epic, because some other epic trigger this epic multiple "unknown" times by expand operator. But since FileReader is async, the code below does not work. What is the correct way especially RxJS way to handle this? Thanks export const uploadAttachmentEpic = (action$, store) => action$ .ofType(UPLOAD_ATTACHMENT) .map(action => { const reader = new FileReader(); reader.onload = () => { return {

Preserve order of results when operating asynchronously on a list

与世无争的帅哥 提交于 2020-01-05 08:59:02
问题 I have an asynchronous function that processes requests from a list, but when each request is done, it's not ordered like before declared (since it's async). How can I fetch asynchronously but retain the original ordering? Here's the fiddle http://jsbin.com/papunixume/edit?html,js,console // clear console every single run console.clear() // create promise const cp = (msg, timeout) => { return new Promise(resolve => { setTimeout(() => { resolve(msg) }, timeout) }) } const a = cp('a', 1000)

Preserve order of results when operating asynchronously on a list

萝らか妹 提交于 2020-01-05 08:58:28
问题 I have an asynchronous function that processes requests from a list, but when each request is done, it's not ordered like before declared (since it's async). How can I fetch asynchronously but retain the original ordering? Here's the fiddle http://jsbin.com/papunixume/edit?html,js,console // clear console every single run console.clear() // create promise const cp = (msg, timeout) => { return new Promise(resolve => { setTimeout(() => { resolve(msg) }, timeout) }) } const a = cp('a', 1000)

rxjs first operator is being repeatedly called?

末鹿安然 提交于 2020-01-05 07:44:18
问题 If I use, 2 gets printed to the console every 3 seconds: Rx.Observable.interval(3000) .mergeMap(() => Rx.Observable.of(3)) .concatMap(()=>Rx.Observable.of(2).first(x=>x == 2)) .subscribe((x)=>console.log(x)) If I use, 2 gets printed to the console only one time: Rx.Observable.interval(3000) .mergeMap(() => Rx.Observable.of(3)) .concatMap(()=>Rx.Observable.of(2)) .first(x=>x == 2) .subscribe((x)=>console.log(x)) The difference is where I chained the first operator, but I don't understand the

rxjs first operator is being repeatedly called?

点点圈 提交于 2020-01-05 07:44:11
问题 If I use, 2 gets printed to the console every 3 seconds: Rx.Observable.interval(3000) .mergeMap(() => Rx.Observable.of(3)) .concatMap(()=>Rx.Observable.of(2).first(x=>x == 2)) .subscribe((x)=>console.log(x)) If I use, 2 gets printed to the console only one time: Rx.Observable.interval(3000) .mergeMap(() => Rx.Observable.of(3)) .concatMap(()=>Rx.Observable.of(2)) .first(x=>x == 2) .subscribe((x)=>console.log(x)) The difference is where I chained the first operator, but I don't understand the

angular cli rxjs operator imports

扶醉桌前 提交于 2020-01-05 05:56:59
问题 in my component created with angular cli I never added import 'rxjs/add/operator/first'; however, using this.route.params.first() still worked. why? Is it possible to not have to import lots of operators in every file? 回答1: Imports like import 'rxjs/add/operator/first'; see the operator patched into the Observable prototype. See the source. Such imports do not need to be made on a per-file basis. They only need to be imported once - after which, the operator is callable via the prototype.