我想我理解WhenAny和WhenAnyValue。
讓我通過代碼演示:
// These two statements are 100% identical, but the latter looks nicer.
this.WhenAny(x => x.Foo.Bar, x => x.Value)
this.WhenAnyValue(x => x.Foo.Bar);
什麼WhenAnyDynamic,WhenAnyObservable和ObservableForProperty?
WhenAnyDynamic
就像WhenAny但是當你想觀察的東西不是常量 - 你可能不需要它,但是RxUI內部的東西。
WhenAnyObservable
讓你得到一個可觀察的,但不必擔心背後的對象變化。例如
this.SomeChildViewModel.MyCoolCommand
.Subscribe(x => Console.WriteLine("Clicked!"));
// Later...
this.SomeChildViewModel = new SomeChildViewModel();
// (Hey, why doesn't my Clicked! handler show up anymore! I'm still subscribed
// to the old object but it's super not obvious that's what happened)
對戰
this.WhenAnyObservable(x => x.MyCoolCommand).
.Subscribe(x => Console.WriteLine("Clicked!"));
// Later...
this.SomeChildViewModel = new SomeChildViewModel();
// Cool, everything still works.
WhenAnyObservable是在查看超級有用的訂閱命令。
ObservableForProperty
就像WhenAny但不是最初訂閱時觸發。您可能應該忽略它,它實際上只是出於兼容性原因而出現的時間約束。
應該'this.WhenAnyObservable(x => x.MyCoolCommand).'不是'this.WhenAnyObservable(x => x.SomeChildViewModel.MyCoolCommand).'? – Wilka
所以你說WhenAny(..)。Skip(1)比ObservableForProperty(..)更可取,如果我真的只想更改通知? ObservableForProperty可能會從未來的版本中刪除? – Clyde
這是正確的 –