WhenAnyPropertyChanged() did'nt work, because Transform() #608
-
I have: I connect() transform(). I listen Items collection, observe UserViewModel members change, use WhenAnyPropertyChanged(), and it didn't work. test project : https://github.com/a44281071/TestDynamicData |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Your |
Beta Was this translation helpful? Give feedback.
-
I see the issue, and there is a fundamental mistake in the sample code. In reactive every subscription creates a new and independent stream . As an example the code below var chosen = itemsCache.Connect()
.Transform(dd => new UserViewModel(dd))
.AutoRefresh(p => p.IsCamOn)
.Sort(SortExpressionComparer<UserViewModel>.Descending(e => e.IsCamOn))
.Page(pager)
.Do(change => PageParameters.Update(change.Response))
.ObserveOnDispatcher()
chosen.WhenAnyPropertyChanged()
.Subscribe(dd => Trace.TraceInformation("WhenAnyPropertyChanged() name = {0}", dd!.Info.Name));
chosen.Bind(Items)
.Subscribe(); will re-create 2 distinct RX streams, meaning that each operator will be in invoked once per subscription. The implication is that chosen.WhenAnyPropertyChanged() and chosen.Bind(Items) will enforce all previous operators along the chain to run again. This means that the UserViewModel which is bound to is different to the UserViewModels where property changes are being listened to. The answer is to share the connection using the rx Publish / Connect operator and pairs. var chosen = itemsCache.Connect()
.Transform(dd => new UserViewModel(dd))
.AutoRefresh(p => p.IsCamOn)
.Sort(SortExpressionComparer<UserViewModel>.Descending(e => e.IsCamOn))
.Page(pager)
.Do(change => PageParameters.Update(change.Response))
.ObserveOnDispatcher()
.Publish() //THE MAGIC IS HERE - means multiple subscribers share the output from this point onwards
chosen.WhenAnyPropertyChanged()
.Subscribe(dd => Trace.TraceInformation("WhenAnyPropertyChanged() name = {0}", dd!.Info.Name));
chosen.Bind(Items)
.Subscribe();
// rx Connect() turns the sharing on.
// It is not dd Connect(). Ambiguous I know and it's a historic naming mistake.
var myConnectedDisposable =chosen.Connect() |
Beta Was this translation helpful? Give feedback.
-
Thanks!!! It's MAAAAAAAAAAAAAAAAAAAGIC!!! |
Beta Was this translation helpful? Give feedback.
I see the issue, and there is a fundamental mistake in the sample code. In reactive every subscription creates a new and independent stream .
As an example the code below
w…