小编Raf*_*l R的帖子

RxJS 主题有条件的 next() 更新,基于当前新值

我有一个角度应用程序,它在一个主题中存储一些数据

dataSubject = new Subject<SomeDataType>();
Run Code Online (Sandbox Code Playgroud)

我有两种不同的方式从服务器更新数据,它们看起来像

connection1.on('messageReceived', (newData: SomeDataType) => this.dataService.dataSubject.next(newData))
Run Code Online (Sandbox Code Playgroud)
connection2.on('messageReceived', (newData: SomeDataType) => this.dataService.dataSubject.next(newData))
Run Code Online (Sandbox Code Playgroud)

问题是最后到达的 newData 不一定是最新的。每个数据对象都包含一个我想使用的时间戳。

有没有办法让主题只接受具有 newData.timestamp > currentData.timestamp 的值?类似于条件 next()

rxjs angular

2
推荐指数
1
解决办法
66
查看次数

标签 统计

angular ×1

rxjs ×1