rxjs6

Will overwriting my observable variable kill current subscribers?

会有一股神秘感。 提交于 2021-02-19 03:05:55
问题 I want to be able to cache an http call, but also force the cache to refresh. My service looks like this: @Injectable() export class UserService { private currentUser$: Observable<User>; constructor(private http: HttpClient) { } getCurrentUser(force = false): Observable<User> { if (!this.currentUser$ || force) { this.currentUser$ = this.http.get<User>(`${environment.API_URL}/profiles/me`) .pipe( shareReplay(CACHE_SIZE) ); } return this.currentUser$; } } If I call getCurrentUser(true) , the

Type 'Observable<HttpEvent<>>' is not assignable to type 'Observable<>'

半腔热情 提交于 2021-02-08 15:10:35
问题 I have this code snippet: SubmitTransaction(transNumber: string, transactionRequest: ITransactionRequestObj): Observable<TransactionResponse> { this.body = JSON.stringify(transactionRequest); this.headers = new HttpHeaders().set('Content-Type', 'application/json'); this.headers.append('Accept', 'application/json'); this.options = new RequestOptions({headers: this.headers}); return this.http.post<TransactionResponse>(this.baseUrl + '/transactions/' + transNumber + '/new', this.body, this

implement a queueing system with a fixed stack in RxJs

我是研究僧i 提交于 2021-02-08 07:40:27
问题 Say I want a queue where only 3 items are being processed asynchronously at any one time, how do I go about this? This is what I mean: If I have a collection of items to upload to the backend i.e. upload some artefacts to cloud storage and consequently create/update a doc to reflect the url of each artefact and I don't want to: Async/Await each upload operation before the next - as this would be slow Send everything off at the same time - this could lead to write hot-spotting or rate limiting

RxJS All Individual Observables completed

杀马特。学长 韩版系。学妹 提交于 2021-01-29 08:02:09
问题 I have an array of unique ID's and want to perform a bulk action (HTTP patch, delete etc) on them. That needs to be done individually and I need to display individual results. As the requests are individual and it's responses should not affect each other. Results are displayed as they are received. Every call is a separate Observable and what I'm looking for is a way to know when all Observables have completed . The onCompleted method works only when there are no errors. The goal is to

Angular app - User login, logout and session reload with Observables

给你一囗甜甜゛ 提交于 2021-01-29 07:10:58
问题 This is a followup question for another question I had posted, which remains half-solved: RxJS shareReplay() does not emit updated value I am creating an Angular app and I'm trying to use Observables extensively. The problem is with creating a UserService class which has an observable user$ which can be piped to throughout the application to get the currently logged in user. The currently accepted answer (by @DeborahK - she had been very patient with me) is a great solution, but has a bug - A

Angular 7 CI rxjs/Operators cannot find module

ⅰ亾dé卋堺 提交于 2021-01-28 23:40:55
问题 I have tried setting up CI for my angular project using Circle CI following this configuration: https://angular.io/guide/testing#configure-project-for-circle-ci However, when ng test runs I get the following error: ERROR in src/app/account/login-form/login-form.component.ts(4,26): error TS2307: Cannot find module 'rxjs/Operators'. Locally, if I delete node_modules/ and run npm install followed by npm test I don't have any issue with rxjs. My package.json : "dependencies": { "@angular

Angular 7 CI rxjs/Operators cannot find module

喜你入骨 提交于 2021-01-28 22:45:59
问题 I have tried setting up CI for my angular project using Circle CI following this configuration: https://angular.io/guide/testing#configure-project-for-circle-ci However, when ng test runs I get the following error: ERROR in src/app/account/login-form/login-form.component.ts(4,26): error TS2307: Cannot find module 'rxjs/Operators'. Locally, if I delete node_modules/ and run npm install followed by npm test I don't have any issue with rxjs. My package.json : "dependencies": { "@angular

RxJS - How to incrementally increase the delay time without using interval?

可紊 提交于 2021-01-20 09:24:30
问题 I want to incrementally increase the delay for this: const source = from(839283, 1123123, 63527, 4412454); // note: this is random const spread = source.pipe(concatMap(value => of(value).pipe(delay(1000)))); // how to incrementally increase the delay where the first item emits in a second, the second item emits in three seconds, the third item emits in five seconds, and the last item emits in seven seconds. spread.subscribe(value => console.log(value)); I'm aware of using interval to

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

依然范特西╮ 提交于 2020-11-30 06:30:18
问题 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

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

家住魔仙堡 提交于 2020-11-30 06:28:57
问题 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