I am making multiple updates to a SourceCache using the Edit method. But when observing the changes for the resulting collection, the updates are returned one at a time. Furthermore, when the update threshold limit of 25 is reached, then the entire list is cleared and updated. While the items in the collection are valid, the UI animations based on the changes are not ideal. Especially in the case where the entire collection is cleared and rebuilt. Following snippet reproduces the issue:
Sample Snippet:
public class DynamicDataTest
{
private readonly SourceCache<string, string> _sourceCache = new SourceCache<string, string>(x => x);
private readonly ReadOnlyObservableCollection<string> _collection;
public DynamicDataTest()
{
_sourceCache.Connect()
//.Sort(SortExpressionComparer<string>.Ascending(l => l))
.Bind(out _collection)
.Subscribe();
new SourceList<string>(_collection.ToObservableChangeSet())
.Connect()
.ForEachChange(change => Console.WriteLine(change.Reason.ToString()))
.Subscribe();
_sourceCache.AddOrUpdate("start");
_sourceCache.Edit(source =>
{
for (int i = 0; i < 26; i++)
{
source.AddOrUpdate(i.ToString());
}
});
}
}
I would expect this to output:
Add or AddRange
AddRange
Instead it results in:
AddRange
Clear
AddRange