I have a question, which is a continuation of the next question raised on this site.
Is there a more elegant way to merge observables when the return type is unimportant?
I have IObservable<Unit>(say X) a reactive collection ( Y) and a property ( Z). The return type is not important. I just want to subscribe when any of these changes change.
I know how to observe all 3 and Subscribeusing Observable.Merge, as shown below.
Observable.Merge(X, Y.Changed, ObservableForProperty(Z).Select(_ => Unit.Default)).Subscribe(..)
And it works.
However, when I try to use WhenAny(...,....,....).Subscribe(), the subscription does not start when it changes X. What is the syntax for doing the above using WhenAny(...)and not Observable.Merge(..)?
I prefer to use WhenAny(....)because I use ReactiveUIin other places.
Example: Say I have a class derived from ReactiveObjectwith the following properties.
public class AnotherVM : ReactiveObject
{
public bool IsTrue
{
get { return this.isTrue; }
set { this.RaiseAndSetIfChanged(x => x.isTrue, ref this.isTrue, value); }
}
public IObservable<Unit> Data
{
get { return this.data; }
}
public ReactiveCollection MyCol
{
get { return Mycol; }
}
}
public class MyVM : ReactiveObject
{
MyVM
{
}
}
I want to observe the above properties in a class AnotherVMusing Observable.Merge(..)or WhenAny(...)in a class MyVM. I found that I do not always receive a notification when I subscribe to the above at MyVM, using WhenAny(...)or Merge(...)when one of the three properties changes.
source
share