rxjs

RxJS observable which emits both previous and current value starting from first emission

故事扮演 提交于 2020-05-25 06:06:33
问题 I have a BehaviorSubject which emits JavaScript objects periodically. I want to construct another observable which will emit both previous and current values of the underlying observable in order to compare two objects and determine the delta. The pairwise() or bufferCount(2, 1) operators are looking like a good fit, but they start emitting only after buffer is filled, but I require this observable to start emitting from the first event of the underlying observable. subject

RxJS observable which emits both previous and current value starting from first emission

徘徊边缘 提交于 2020-05-25 06:05:23
问题 I have a BehaviorSubject which emits JavaScript objects periodically. I want to construct another observable which will emit both previous and current values of the underlying observable in order to compare two objects and determine the delta. The pairwise() or bufferCount(2, 1) operators are looking like a good fit, but they start emitting only after buffer is filled, but I require this observable to start emitting from the first event of the underlying observable. subject

Get current value from Observable without subscribing (just want value one time)

末鹿安然 提交于 2020-05-24 18:06:30
问题 The title says it all really. How can I get the current value from an Observable without subscribing to it? I just want the current value one time and not new values as they are coming in... 回答1: You need to use BehaviorSubject, BehaviorSubject is similar to ReplaySubject except it only remembers the last publication. BehaviorSubject also requires you to provide it a default value of T. This means that all subscribers will receive a value immediately (unless it is already completed). It will

Template binding with function return Observable and async pipe

蓝咒 提交于 2020-05-24 03:38:49
问题 Note this is simplified question of Angular template binding with Observable async pipe issue template: <div>{{foo()$ | async}}</div> source code: import { Component } from "@angular/core"; import { BehaviorSubject, of, Observable } from "rxjs"; import { tap, delay, map, switchMap, concatMap } from "rxjs/operators"; @Component({ selector: "my-app", templateUrl: "./app.component.html", styleUrls: ["./app.component.css"] }) export class AppComponent { private index = 0; foo$(): Observable<any>

How to implement ngOnDestroy() correctly in Angular?

纵然是瞬间 提交于 2020-05-23 09:12:10
问题 I have a child component with a timer, every 2 second I send api call to the server. I need to do this call as long as the user is on the page even if he/she going to a wedding and leave the page (the parent compoent window) open. Here is some code from my component: this.myTimer = Observable.timer(1, 2000); this.myTimer .mergeMapTo(this.myService.doSomeWork(this.myId)) .subscribe((data) => { this.myData = data; }, (errRes)=>{ console.log(errRes); }); And here is the destroy method:

What is observable, observer and subscribe in angular?

穿精又带淫゛_ 提交于 2020-05-22 21:21:50
问题 I am learning angular and i got confuse in these observable, observer and subscribe thing. So please explain. 回答1: Here is a simple visual to see the difference: As seen above ... an Observable is a stream of events or data. They are often returned from Angular methods, such as the http.get and the myinputBox.valueChanges . Subscribing "kicks off" the observable stream. Without a subscribe (or an async pipe) the stream won't start emitting values. It's similar to subscribing to a newspaper or

What is observable, observer and subscribe in angular?

天涯浪子 提交于 2020-05-22 21:14:47
问题 I am learning angular and i got confuse in these observable, observer and subscribe thing. So please explain. 回答1: Here is a simple visual to see the difference: As seen above ... an Observable is a stream of events or data. They are often returned from Angular methods, such as the http.get and the myinputBox.valueChanges . Subscribing "kicks off" the observable stream. Without a subscribe (or an async pipe) the stream won't start emitting values. It's similar to subscribing to a newspaper or

Angular EventEmitter is not emitting in subscriber

泪湿孤枕 提交于 2020-05-17 03:08:22
问题 I have a event emitter that I want to emit an object to a parent component however the event emitter is not emitting in the subscriber function Code categories = []; @Output() filteredCategory = new EventEmitter<any>(); @Output() maxiumPriceEmitter = new EventEmitter<any>(); categorySub: Subscription; formatLabel(value: number) { return 'R' + value; } constructor(private shopService: ShopService) {} ngOnInit() { this.initCategories(); this.filterCategories(); this.updateCategories(); }

Angular EventEmitter is not emitting in subscriber

浪子不回头ぞ 提交于 2020-05-17 03:02:07
问题 I have a event emitter that I want to emit an object to a parent component however the event emitter is not emitting in the subscriber function Code categories = []; @Output() filteredCategory = new EventEmitter<any>(); @Output() maxiumPriceEmitter = new EventEmitter<any>(); categorySub: Subscription; formatLabel(value: number) { return 'R' + value; } constructor(private shopService: ShopService) {} ngOnInit() { this.initCategories(); this.filterCategories(); this.updateCategories(); }

Mongoose Cursor: http bulk request from collection

删除回忆录丶 提交于 2020-05-15 23:33:27
问题 I have a problem which is relevant to rxJS and bulk HTTP requests from the huge collection (1M+ docs) I have the following code, with quite simple logic. I push all the docs from the collection to allplayers array and making bulk 20 HTTP requests to API at once (guess you understand why it's limited) So, the code works fine, but I guess it's time to refactor it from this: const cursor = players_db.find(query).lean().cursor(); cursor.on('data', function(player) { allPlayers.push(player); });