rxjs6

Why would I use RxJS interval() or timer() polling instead of window.setInterval()?

江枫思渺然 提交于 2020-11-30 06:28:47
问题 Use case: Call a function every minute (60000 ms) that dispatches store action to fetch lastUpdated status of items, which upon response and filtering, updates the store, and updated store is read as an observable and displayed in the view). This needs to happen for as long as the web app is open (so indefinitely). Currently, I'm using this: this.refreshDate = window.setInterval( () => this.store.dispatch(new FetchLastUpdate()) , 60000); And when view is destroyed/dismounted, I delete the

RxJS shareReplay() does not emit updated value

情到浓时终转凉″ 提交于 2020-08-10 19:19:47
问题 I have a user service which allows login, logout and maintains data about the currently logged in user: user$ = this.http.get<User>('/api/user') .pipe( shareReplay(1), ); I am using shareReplay(1) because I do not want the webservice to be called several times. On one of the components, I have this (for simplicity), but I have several other things I want to do if a user is logged in: <div *ngIf="isUserLoggedIn$ | async">Logout</div> isUserLoggedIn$ = this.userService.user$ .pipe( map(user =>

Upgrading to Angular 10 - Fix CommonJS or AMD dependencies can cause optimization bailouts

╄→尐↘猪︶ㄣ 提交于 2020-08-02 05:44:54
问题 I am trying to upgrade my angular 9 app to angular 10 version, but getting below warning after the upgrade rxjs\BehaviorSubject.js depends on rxjs-compat/BehaviorSubject Any idea how to fix this? Thanks in advance! 回答1: When you use a dependency that is packaged with CommonJS, it can result in larger slower applications Starting with version 10, Angular now warns you when your build pulls in one of these bundles. If you’ve started seeing these warnings for your dependencies, let your

RXJS How do I use the result of one observable in another (and then process those two results together)

自闭症网瘾萝莉.ら 提交于 2020-06-27 16:37:11
问题 A very common problem when using RxJs seems to be to want the result of one or more observables to then use them in subsequent ones. e.g. in pseudo-code (This is not rx or valid js syntax deliberately) var someResult = $observable-A; // wait to complete var finalResult = $observable-B(someResult.aValueINeed); This can be done in an ugly way where you could subscribe to both and call one inside the other.. however, this is very messy and doesn't afford you much flexibility. e.g. (real syntax)

You provided 'undefined' where a stream was expected

孤街浪徒 提交于 2020-06-17 10:01:13
问题 I am getting this in my Console. Since it's not pointing to my code I have no idea what it's all about: TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable. at subscribeTo (subscribeTo.js:28) at subscribeToResult (subscribeToResult.js:15) at CatchSubscriber.push../node_modules/rxjs/_esm5/internal/operators/catchError.js.CatchSubscriber.error (catchError.js:43) at CatchSubscriber.push../node_modules/rxjs/_esm5/internal

Why rxjs debounceTime does not work on observables created using 'of' operator?

为君一笑 提交于 2020-06-12 10:39:22
问题 Using angular 7 and rxjs 6 : <input (input)="onChange($event.target.value)"> Why the following does not debounce? onChange(val: string) { of(val) .pipe( debounceTime(300) ).subscribe(valx => { console.log(valx); }); } But this does: searchTerm$: Subject<string> = new Subject(); this.searchTerm$.pipe( debounceTime(300), ).subscribe(val => { console.log(val); }); onChange(val: string) { this.searchTerm$.next(val); } 回答1: This isn't because of of() . In your first example every time you call

How does throttleTime operator's config parameter work? (ThrottleConfig)

醉酒当歌 提交于 2020-06-08 18:24:05
问题 I have read the throttleTime documentation, but I don't get the operator fully. I know how throttleTime(1000) works. After an event arrives it will skip all subsequent events for 1 second and then start this process again. What I have trouble to understand is how exactly ThrottleConfig works, which is the third parameter of the operator. throttleTime<T>( duration: number, scheduler: SchedulerLike = async, config: ThrottleConfig = defaultThrottleConfig): MonoTypeOperatorFunction<T> How do

Angular template binding with Observable async pipe issue [duplicate]

假如想象 提交于 2020-05-28 06:53:08
问题 This question already has an answer here : Template binding with function return Observable and async pipe (1 answer) Closed 13 days ago . Note I have created a simplified version of this question at Template binding with function return Observable and async pipe Template: <div *ngIf="entity?.ext.insuredDetails.insuredType$() | async as insuredType"> {{insuredType}} </div> insuredType$ definition: @NeedsElement(sp(115621),ap(116215)) insuredType$(): Observable<string> { return empty(); }

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>