RxJs:将数据流递增地推送到BehaviorSubject []. [英] RxJs: Incrementally push stream of data to BehaviorSubject<[]>

查看:76
本文介绍了RxJs:将数据流递增地推送到BehaviorSubject [].的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我正在尝试使用要分批加载的数据数组向BehaviorSubject<[]>充气.

Basically I'm trying to inflate BehaviorSubject<[]> with array of data which will be loaded in chunks.

BehaviorSubject<[]>将添加新的数据块(例如Array.push),但是我不想使用另一个数组来存储并添加到BehaviorSubject.next,因为这将导致渲染花费的时间太长,因为数据随着时间的增长.

BehaviorSubject<[]> will be added with new chunk of data (like Array.push) but I don't want to use another array to store and add to BehaviorSubject.next because this will cause rendering to take too long as the data grow over time.

有什么建议吗?

推荐答案

您可以使用getValue()方法来实现您想要做的事情.

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

示例:

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]));
}

这篇关于RxJs:将数据流递增地推送到BehaviorSubject [].的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆