【发布时间】:2020-08-29 19:46:58
【问题描述】:
我有一个在主题中存储一些数据的 Angular 应用程序
dataSubject = new Subject<SomeDataType>();
我有两种不同的方式从服务器更新数据,看起来像
connection1.on('messageReceived', (newData: SomeDataType) => this.dataService.dataSubject.next(newData))
connection2.on('messageReceived', (newData: SomeDataType) => this.dataService.dataSubject.next(newData))
问题是最后到达的新数据不一定是最新的。 每个数据对象都包含一个我想要使用的时间戳。
有没有办法让 Subject 只接受具有 newData.timestamp > currentData.timestamp 的值?类似于条件 next()
【问题讨论】: