rxjs

Rxjs - only the first observer can see data from observable.share()

混江龙づ霸主 提交于 2019-12-10 18:32:39
问题 I have some code snippet as following var videosNeedFix = Rx.Observable.fromArray(JSON.parse(fs.readFileSync("videoEntries.json"))).share(); videosNeedFix.count().subscribe(function(count){ //subscrption A console.log(count + " in total"); }); videosNeedFix.subscribe(function(videoEntry){ //subscription B console.log(videoEntry.id, videoEntry.name, videoEntry.customFields); }); The videoEntries.json is a JSON-serialized array of videoEntry object. I'm expecting both subscription A and

Property 'next' does not exist on type 'Observable<{}>'

白昼怎懂夜的黑 提交于 2019-12-10 18:28:06
问题 trying to do the following let o = new Observable() ; o.delay( 3000 ).next( { stuff } ) ; Getting the following error [ts] Property 'next' does not exist on type 'Observable<{}>' also tried Let o = new Subject(); o.delay( 3000 ).next( { stuff } ) ; Still getting [ts] Property 'next' does not exist on type 'Observable<{}>'. 回答1: You need to call next on the Subject instance. The o variable from your example is then the Subject chained with the operator that returns an Observable. const s = new

Making a typing timer in RxJS; Tracking time spent typing

南笙酒味 提交于 2019-12-10 18:08:37
问题 This question is an extension of my previous question that you can find here: How to use RxJS to display a "user is typing" indicator? After having successfully been able to track whether or not the user was typing, I needed to be able to use that particular state as a trigger for a clock. The logic is simple, essentially I want a clock to be run when the user is typing. But when the user stops typing, I need the clock to pause. When the user starts typing again, the clock should continue to

Running async tasks in parallel

旧城冷巷雨未停 提交于 2019-12-10 17:53:33
问题 In RxJS, when you want to run http requests in sequence- you chain them. But I'm not clear on how can I run requests in parallel? I saw in the examples on http://reactive-extensions.github.io/learnrx/ that they use Observable.zip() to run 2 requests in parallel. But how would you run 5 requests in parallel? More specifically, how can I setup so that my function is called: when all 5 complete? when first complete? 回答1: This is a quite old question but without an accepted answer. The answer you

Reactive Extensions SelectMany and Concat

ぐ巨炮叔叔 提交于 2019-12-10 17:51:44
问题 I understand that the behaviour of SelectMany is to effectively merge the results of each value produced into a single stream so the ordering in nondeterministic. How do I do something similar to concatAll in RxJs in C#. var obs = Observable.Range (1, 10).SelectMany (x => { return Observable.Interval (TimeSpan.FromSeconds(10 - x)).Take (3); }).Concat(); This is effectively what I want to do, Given a Range, Wait a bit for each then concat in the order that they started in. Obviously this is a

Observable.forkJoin wrong return type when more than 6 arguments

淺唱寂寞╮ 提交于 2019-12-10 17:47:03
问题 I have an issue with Observable.forkJoin inferring the wrong return type and then causing errors when I pass more than 6 arguments. Observable.forkJoin(service.getType1, service.getType2, service.getType3 ...) .subscribe(x => { this.type1Arr = x[0]; this.type2Arr = x[1]; this.type3Arr = x[2]; Each function call from the service returns an Observable<Array<type>> . The compiler is determining that the return should be Type1[][] when I have more than 6 calls from the service passed in. It works

How to prevent http call in Angular 2 when using observables?

社会主义新天地 提交于 2019-12-10 17:27:28
问题 Several examples demonstrate how to use observables to hook up a control to show data fetched from a http backend, such as this one: http://blog.thoughtram.io/angular/2016/01/06/taking-advantage-of-observables-in-angular2.html Can you prevent that http call in certain situations? For example in the mentioned post there is an autocomplete field - is there a way to prevent the http call in case the user clears the field? I have tried modifying the switchMap function with for example: if(term

How to debug on whether observable is unsubscribe

自古美人都是妖i 提交于 2019-12-10 17:16:54
问题 how can i test whether the observable is unsubscribe after subscription. I am developing in ionic2/angular2. I am expecting typing something like this in chrome developer mode and it will return value: observableName.isSubscribe() 回答1: You can have a subscription and check closed parameter. let subscription = observable.subscribe(() => {}) if (!subscription.closed) { //subscribed } else { //not subscribed } 回答2: As sebaferreras told in the last comment, you can just use the closed property;

Skip programmatic changes in valueChanges of Angular 2 control

守給你的承諾、 提交于 2019-12-10 17:12:03
问题 I'm subscribing to the valueChanges observable of an Angular 2 (2.2.1) control. It's defined in AbstractControl in @angular\forms\src\model.d.ts and it's doc string states that it will yiald changes from the UI as well as programmatic ones: /** * Emits an event every time the value of the control changes, in * the UI or programmatically. */ valueChanges: Observable<any>; How can I filter this down to give me only the changes from the UI and not the programmatic ones? I think that the boolean

Jest not handling errors from expect() in subscribe() of RxJS observable

╄→гoц情女王★ 提交于 2019-12-10 17:08:00
问题 I've been trying to get Jest working with RxJS and am having trouble with Jest not propagating errors from inside the subscribe callback. Here is a sample test I've tried that is not working: import {of} from 'rxjs'; test('should fail', () => { of(false).subscribe(val => { expect(val).toBe(true); }); }); The above test should fail, but it passes. I've googled around and found the following solution: Failing expect() inside subscribe() does not mark test as invalid This suggests using the