I have a few objects that contain each a ReactiveList
(children), for whose changes I'd like to execute some logic. The parents are dynamic and also in a ReactiveList
. Basically I'm doing this:
var parents = new ReactiveList<Parent>();
parents.Add(new Parent() { Id = 1, Children = new ReactiveList<Child>() };
parents.Add(new Parent() { Id = 2, Children = new ReactiveList<Child>() };
parents.Changed
.SelectMany(_ => parents.Select(x => x.Children.Changed).Merge())
.Subscribe(x => {
// Some of the parent's children have changed. But which parent?
});
// trigger Changed event
parents[1].Children.Add(new Child());
The problem is that I need to know for which of the parents this happened. If I had at least the collection that's being changed, I could retrieve the parent. But I've looked at the NotifyCollectionChangedEventArgs
that is passed down and there is nothing useful in there.
So apart from looping "manually" through the parents and subscribing to each, which doesn't look very Rxly to me and probably introduces a bunch of leaking problems, is there an elegant solution?