NOTE: I'm calling the set function in a component that has an ngFor. So when I call set function the ngOnInit gets executed multiple times so the set function executes as well multiple times. I have an observable with an object that I update to keep data consistent.
private app= this.subject.asObservable().distinctUntilChanged();
I access the data using this method
select<T>(name: string): Observable<T> {
return this.app.pluck(name);
}
When I update a this "app" on every user selection then I enter an infinite loop. So $info starts printing the same information over and over again. And the "set" gets called over and over again. I'm using the async pipe to subscribe and unsubscribe in the html view. ANY IDEAS ?
updateFruits(fruit) {
this.app.set('Fruits', fruit);
}
set(name: string, state: any) {
this.subject.next({ ...this.value, [name]: state });
}
this.info$ = combineLatest(fruits$)
.pipe(
distinctUntilChanged(),
debounceTime(0)
map(fruits => fruits)
);