Questions tagged [rxjs-observables]

759 questions
1
vote
2 answers

RXJS, How to watch mouse and keyboard and do something when when none has been used for some time?

I need run a function if neither the mouse has moved, nor the keyboard has been touched for 1mn. I tried the code below but doesn't seem to work. How can I fix it? Thank you for your help. mouseEvent$ = fromEvent(document, 'mouseMove'); keyPress$ =…
user1445685
  • 793
  • 1
  • 11
  • 25
1
vote
2 answers

Read values from one observable but switch to another once it (the other one) emits

My desired behaviour: Run HTTP request Immediately look up data in async cache If cache has the value before HTTP emits - use cache value. Use HTTP value after it's finally here. If HTTP responds faster than cache - ignore cache. So basically I…
devmiles.com
  • 9,895
  • 5
  • 31
  • 47
1
vote
1 answer

How to properly add a child generator (sub-flow) to an Observable on RxJS?

I'm using RxJS 7, and I would like to have a child generator (another Observable) emitting values based on the parent data. I was already able to achieve this, but the solution I found is not efficient in terms of CPU usage because it needs to build…
Pedro Kehl
  • 166
  • 3
  • 11
1
vote
2 answers

How to use rxjs to create an object observable from another observable?

I would like to expose an observable in my service, which emits a value each time a BehaviorSubject is assigned a value (and after filtering it from a list). Example implementation: export class MyService { // Given a list of all object …
GK100
  • 3,664
  • 1
  • 26
  • 19
1
vote
3 answers

One by one observables RxJS

I have a problem with observables. I've prepared stackblitz to simplify my problem. I have 2 observables (obs1$, obs2$) and array of numbers. I want to wait for obs1$ to be completed and then loop through array and return observable of each element,…
mackosz
  • 139
  • 1
  • 8
1
vote
2 answers

Angular - How to merge these two observables with ngrx some magics?

I have 2 observables. One returns an event and the other boolean. I want to create a new observable that returns the boolean or event while the value in the store is true. Here is the code. This obs1 should wait until the obs2 returns true. const…
mark
  • 129
  • 7
1
vote
1 answer

How to Map/reduce a series of date bound values to a running total in JavaScript / RXJS?

I have an observable that emits measurement values with a date for a key. Something like: { "date" : "2021-11-01", "temp" : 23.4, "hum" : 74.5 } I need a 7 days running total and average for temp and hum. If I would have a a value for each…
stwissel
  • 20,110
  • 6
  • 54
  • 101
1
vote
1 answer

Types of property 'observers' are incompatible. Why?

I'm trying to make a BehaviorSubject that will accept only values of the AvailableLanguages enum, but the compiler doesn't agree with my code for some reason. Can you tell me why? I'm using Angular 12.2.10. Here is the service: import { Injectable…
SteDeus
  • 47
  • 4
1
vote
2 answers

Subscribe in subscribe in Angular rxjs

I have: getSth(): void { this.service.functionName.pipe( takeUntil(this.destroy$), distinctUntilChanged(), map(res => res.event) ).subscribe(((response) => { this.getAnother(response); })); …
1
vote
1 answer

Rxjs: Combine observables data streams(grpc service) into an array after X secs using scan or mergeMap or any rxjs

I receive a stream of data as response from a service(grpc) like 5 streams in within 2 secs. Each stream is an observable object that I'm subscribing. The processing logic once I receive each stream is more, and each stream is having some heavy json…
1
vote
2 answers

RxJS subscription in Angular component

I don't completely understand where and how I need to declare observables / subjects in Angular component. Currently I develop a website which interacts with MovieDB API and I have everything working, but at the same time I understand that my code…
1
vote
1 answer

How to convert Observable[] to Observable

I’ve got an Observable that has an array of objects and I would like to convert them to a different object using a second observable. This is part of a larger project so to simplify this for my question I am going to have an observable that has an…
Eric
  • 343
  • 4
  • 14
1
vote
2 answers

Getting last two values emitted from a chained Observable

I have two Observables that I am trying to chain together. I need to subscribe to both and act on the emitted values for both. I feel like I'm doing something wrong in my setup and wanted to ask if this is the best way to accomplish…
sma
  • 9,449
  • 8
  • 51
  • 80
1
vote
1 answer

RxJs: get array of observables

I have following pseudocode zip( ...[1, 2, 3].map((id) => this.http.function1(id).pipe( mergeMap((obj1) => this.http.function2(obj1.id)), mergeMap((obj2) => this.http.function3(obj2.id)), ), …
StaticName
  • 239
  • 1
  • 2
  • 10
1
vote
1 answer

How to return an observable that combines results of another observable?

The goal is to retrieve a document from firestore, and for each document, complete it with an array of documents coming another collection. Firestore isn't supporting the "inclusion" of subcollection. In my cases, I've a Test, which has a whole…
J4N
  • 19,480
  • 39
  • 187
  • 340