I am using RxJS in typescript and would like to have a generic way to handle changes in collections. A very naive implementation would be something like
Observable<Element[]>
where every single change in the collection turns into a "broadcast" of all the items included.. This is very cumbersome (and possibly not efficient) to deal with, but my main worry is that it requires checking on the Observer side what has changed.
Let´s imagine that Element is defined like:
class Element {
id: string,
propA: string,
propB: string,
hash(): number {..} // generates a hash based on the properties
}
in this case I would like to be notified if and when any of the Elements is added, removed or modified (an Element is considered modified if the id remains the same, but some of the properties do not).
In that case I would need some kind of extra Observable pipeline operations that receive the collection and based on the stored (previous) values generates a CollectionChangedEvent, which has a type (i.e. Added, Removed, Modified) and an id (of the target Element). The modifications being calculated based on the hash of each element.
class CollectionChangedEvent {
type: ChangeType,
id: string
}
Is there something similar already implemented or a better way to go about this?