响应式用户界面中的各种WhenAny方法之间有什么区别 [英] What are the distinctions between the various WhenAny methods in Reactive UI
问题描述
响应式UI中有几种扩展方法,用于获取可观察到的属性更改.
There are several extension methods in Reactive UI for getting observables for property changes.
我想我了解 WhenAny
和 WhenAnyValue
. WhenAny
用于一系列属性更改通知,您希望其中的对象和属性的元数据发生了更改,而 WhenAnyValue
用于真正需要更改的流时值.
I think I understand WhenAny
and WhenAnyValue
. WhenAny
is for a series of property change notifications where you want the metadata of which object and property had the change, while WhenAnyValue
is for when you really just want the stream of changed values.
首先,这是一个准确的评估吗?
First of all, is that an accurate assessment?
WhenAnyDynamic
, WhenAnyObservable
和 ObservableForProperty
怎么样?我真的无法弄清楚它们的用途,或它们与前两个的区别.它们都是供公众使用的吗?他们的目的是什么?
What about WhenAnyDynamic
, WhenAnyObservable
, and ObservableForProperty
? I can't really figure out what they're for, or how they're distinct from the first two. Are they all intended for public use? What is their purpose?
推荐答案
我想我了解WhenAny和WhenAnyValue.
I think I understand WhenAny and WhenAnyValue.
让我通过代码进行演示:
Let me demonstrate via code:
// 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怎么样?
What about WhenAnyDynamic, WhenAnyObservable, and ObservableForProperty?
WhenAnyDynamic
类似于WhenAny,但是当您要观察的东西不是常量时-您可能不需要它,但是RxUI内部需要它.
WhenAnyDynamic
is like WhenAny but when the things you want to observe aren't constants - you probably won't need it, but RxUI internals does.
WhenAnyObservable
使您可以获得Observable,但不必担心背后的物体会发生变化.例如
WhenAnyObservable
lets you get an Observable, but not have to worry about objects changing behind your back. For example
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在视图中非常有用,可以订阅命令.
WhenAnyObservable is super useful in the View to Subscribe to Commands.
ObservableForProperty
类似于WhenAny,但在最初订阅时不会触发.您可能应该忽略它,它实际上只是出于兼容性原因而成为WhenAny的基础.
ObservableForProperty
is like WhenAny but doesn't fire when initially subscribed to. You probably should ignore it, it's really just a building block for WhenAny that is around for compatibility reasons.
这篇关于响应式用户界面中的各种WhenAny方法之间有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!