RxJs: increment data stream in BehaviorSubject <[]>

I am basically trying to inflate a BehaviorSubject<[]> array of data to be loaded into chunks.

BehaviorSubject<[]> a new piece of data will be added (for example, Array.push ), but I do not want to use another array to store and add to BehaviorSubject.next , because this will cause the rendering to take too much time, since the data grow over time.

Any suggestion?

+5
source share
1 answer

You can use the getValue() method to accomplish what you want to do.

Example:

 data = new BehaviorSubject<any[]>([]); addData(foo:any):void{ // I'm using concat here to avoid using an intermediate array (push doesn't return the result array, concat does). this.data.next(this.data.getValue().concat([foo])); } 
+5
source

Source: https://habr.com/ru/post/1268372/


All Articles