Hm, this should work, I suspect a typo in ReactiveList. Want to create a test case for it?
Trouble Zipping ReactiveList<T>.ItemChanging with ReactiveList<T>.ItemChanged
-
04-10-2022 - |
Question
I am trying to zip two sequences from a ReactiveList to return the old and new values when something changes. The zipped subscription however appears to be returning the same value for 'old and new'.
What am I missing?
Thanks :-)
void Main()
{
var names = new string[] {"Bill","Jane","Tom", "Jess"};
var list = new ReactiveList<ReactivePerson>(){ChangeTrackingEnabled = true};
// These subscriptions work as expected
list.ItemChanging.Subscribe(x=> string.Format("Property {0} changing from {1}",x.PropertyName, x.GetValue()).Dump());
list.ItemChanged.Subscribe(x=> string.Format("Property {0} changed to {1}",x.PropertyName, x.GetValue()).Dump());
// This subscription doesn't. It is returning the same value for both 'old and new'
list.ItemChanging.Zip(list.ItemChanged, (oldrec, newrec)=>new{o=oldrec.GetValue(),n=newrec.GetValue()}).Subscribe(x=>x.Dump());
// Add records
list.AddRange(names.Select (n => new ReactivePerson{FirstName=n}));
// manipulate records
list[0].FirstName = "Terry";
}
public class ReactivePerson : ReactiveObject
{
string _firstName;
public string FirstName{
get { return _firstName; }
set { this.RaiseAndSetIfChanged(ref _firstName, value); }
}
}
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow