Reputation: 489
I am updating all data for each user in Firebase - Real Time Database at fixed periods of time and I am using:
this.db.list('/' + this.user.uid + '/data).valueChanges()
.subscribe(items=>{
console.log(items)
});
to retrieve the update. But because multiple values are updated(even though all at once) I receive in the web application one update at a time. Is this normal? Is there any way to update all and receive the update only once?
Upvotes: 0
Views: 648
Reputation: 2599
If you really don't like multiple emissions, you could try some RxJS operators before your subscribe.
this.db.list('/' + this.user.uid + '/data).valueChanges().pipe(
buffer(interval(1000))
)
.subscribe(items=>{
console.log(items);
});
For example, that would emit an array of values inside of a one second span.
If there's a way to listen to when you update (or rather, the confirmation from the server that updating was successful), you could listen to that, then just grab the current value of this.db.list
instead of each value change as it comes in.
Upvotes: 0
Reputation: 317467
If you make multiple independent updates at the location of a listener, the listener could trigger as many times as there are updates. This system is going to try to synchronize all the changes as fast as it can. You can't change this behavior. If you want only one update, then you should make only one change at that location.
Upvotes: 1