rxjs

How to implement time expiry hot observable in RxJS (or general in Reactive Extensions)

◇◆丶佛笑我妖孽 提交于 2019-12-21 14:59:45
问题 I'd like to implement Time Expiry cache with RxJs. Here is example of "normal" cache: //let this represents "heavy duty job" var data = Rx.Observable.return(Math.random() * 1000).delay(2000); //and we want to cache result var cachedData = new Rx.AsyncSubject(); data.subscribe(cachedData); cachedData.subscribe(function(data){ //after 2 seconds, result is here and data is cached //next subscribe returns immediately data cachedData.subscribe(function(data2){ /*this is "instant"*/ }); }); When

How to implement time expiry hot observable in RxJS (or general in Reactive Extensions)

耗尽温柔 提交于 2019-12-21 14:59:01
问题 I'd like to implement Time Expiry cache with RxJs. Here is example of "normal" cache: //let this represents "heavy duty job" var data = Rx.Observable.return(Math.random() * 1000).delay(2000); //and we want to cache result var cachedData = new Rx.AsyncSubject(); data.subscribe(cachedData); cachedData.subscribe(function(data){ //after 2 seconds, result is here and data is cached //next subscribe returns immediately data cachedData.subscribe(function(data2){ /*this is "instant"*/ }); }); When

Rx debounce operator with first and last

南笙酒味 提交于 2019-12-21 11:28:10
问题 Is there any combination of rx operators so as to get the first and last debounced event? This is going to be used in master detail scenarios (or even seach scenarios) where we want immediate loading of first selected item and the last after user stops changing selection. This would prevent the debounce time to be injected when the user navigates slowly but also prevent bursts of changes. If debounce operator had an option "immediate" like underscore.js debounce functoin then a merge of the 2

What is the difference between finally and finalize in rxjs

ぐ巨炮叔叔 提交于 2019-12-21 10:16:43
问题 I am using RxJS and I can see there are 2 function in RxJS 5.5.2 available. Is the .finally will be removed and it will be placed in side pipe() from RxJS 6.0.0 on wards is the reason or there are any other changes? Are they both same and now final call is inside pipe() ? Or they have any notable difference? finalize method() .pipe( finalize(() => { // do some operation }) ) finally method() .finally(() => { // do your operation }) 回答1: Both are same functionality wise both does same

What is the difference between finally and finalize in rxjs

只谈情不闲聊 提交于 2019-12-21 10:16:20
问题 I am using RxJS and I can see there are 2 function in RxJS 5.5.2 available. Is the .finally will be removed and it will be placed in side pipe() from RxJS 6.0.0 on wards is the reason or there are any other changes? Are they both same and now final call is inside pipe() ? Or they have any notable difference? finalize method() .pipe( finalize(() => { // do some operation }) ) finally method() .finally(() => { // do your operation }) 回答1: Both are same functionality wise both does same

A forkJoin alternative for uncompleted observables?

限于喜欢 提交于 2019-12-21 09:56:04
问题 constructor( private route: ActivatedRoute, private http: Http ){ // Observe parameter changes let paramObs = route.paramMap; // Fetch data once let dataObs = http.get('...'); // Subscribe to both observables, // use both resolved values at the same level } Is there something similar to forkJoin that triggers whenever a parameter change is emitted? forkJoin only works when all observables have completed. I just need to avoid callback hell, any alternative that complies is welcome. 回答1: There

A forkJoin alternative for uncompleted observables?

老子叫甜甜 提交于 2019-12-21 09:55:13
问题 constructor( private route: ActivatedRoute, private http: Http ){ // Observe parameter changes let paramObs = route.paramMap; // Fetch data once let dataObs = http.get('...'); // Subscribe to both observables, // use both resolved values at the same level } Is there something similar to forkJoin that triggers whenever a parameter change is emitted? forkJoin only works when all observables have completed. I just need to avoid callback hell, any alternative that complies is welcome. 回答1: There

Angular - what is the preferred way to terminate Observables?

谁都会走 提交于 2019-12-21 09:33:50
问题 From my understanding of Angular and RxJs there are two ways to terminate Observables. You can unsubscribe() from them or use takeUntil() and complete() . Below are examples of each approach (in pseudocode). The unsubscribe() approach private _id: number; private _subscriptions: Subscription[] = []; constructor(private _route: ActivatedRoute) { this._getId(); } public ngOnDestroy(): void { this._subscriptions.forEach( subscription => subscription.unsubscribe() ); } private _getId(): void {

Angular 2 way to get item from Observable<Xyz[]>

夙愿已清 提交于 2019-12-21 09:33:24
问题 Given the following Typescript in an Angular 2 service: getLanguages () { return this.http.get(this._languagesUrl) .map(res => <Language[]> res.json().data) .catch(this.handleError); I'm having difficulty using this in circumstances where I need to lookup a specific item from the array. For example, I can't do the following because filter expects an Observable<Language> rather than an the Observable<Language[]> that is being returned. getLanguages().filter(language => language.id == 3) //

Making polling request in Angular 2 using Observable

无人久伴 提交于 2019-12-21 09:07:47
问题 I have the following code to make a polling GET request in AngularJS 2: makeHtpGetRequest(){ let url ="http://bento/supervisor/info"; return Observable.interval(2000) .map(res => res.json()) //Error here .switchMap(() => this.http.get(url)); /* This portion works well return this.http.get(url) .map(res =>res.json());*/ } TypeScript is giving me an error make the response in JSON format (check comment in the code. TypeError: res.json is not a function Surprisingly, it was working for some time