I have an angular application that stores some data in a Subject
dataSubject = new Subject<SomeDataType>();
I have two different ways that the data gets updated from the server which look like
connection1.on('messageReceived', (newData: SomeDataType) => this.dataService.dataSubject.next(newData))
connection2.on('messageReceived', (newData: SomeDataType) => this.dataService.dataSubject.next(newData))
The problem is that the newData that arrives last, is not necessarily the latest. Each data object contains a timestamp that I want to use.
Is there a way to make the Subject only accept values that have newData.timestamp > currentData.timestamp? Something like a conditional next()