Posted at

ReactiveCollectionの変更を雑に取りたい時のアレ

More than 3 years have passed since last update.


ReactiveCollection<Hoge> Hoges;
// Hogesにかかるあらゆる変更を取得する
IObservable<ReactiveCollection<Hoge>> observeChanged;
public IObservable<ReactiveCollection<Hoge>> ObserveChanged()
{
if (observeChanged == null)
{
observeChanged = Hoges.ObserveReplace().Select(x => Hoges)
.Merge(Hoges.ObserveCountChanged().Select(x => Hoges))
.Publish()
.RefCount();
}

return observeChanged;
}

ReactiveCollection のAdd,Remove,Replace,Clearあたりで毎回通知が来る奴