-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
I'm guessing it's due to some optimisation, but this test fails, and the console output shows a clear.
[TestClass]
public class DynamicDataIssues
{
private interface ICommonInterface { }
private struct A : ICommonInterface { }
private class B : ICommonInterface { }
[TestMethod]
public void RemoveAllFromMerged()
{
A[] fixedItems = { new(), new() };
SourceList<B> moreItems = new();
var disposable = fixedItems.AsObservableChangeSet(completable: true).Transform(i => (ICommonInterface)i)
.Merge(moreItems.Connect().Transform(i => (ICommonInterface)i))
.Do(x => Console.WriteLine($"+{x.Adds}, -{x.Removes}, {x.First()}"))
// The sorting is to keep things in the order I merged them, but I would prefer to not need to do this.
.Sort(SortExpressionComparer<ICommonInterface>
.Ascending(i => i is not A)
.ThenByAscending(i => i is not B))
.Bind(out var allItems)
.Subscribe();
Assert.AreEqual(2, allItems.Count);
// These work as expected
moreItems.Add(new B());
moreItems.Add(new B());
// But these result it the fixed items being removed
moreItems.RemoveMany(moreItems.Items.ToArray());
Assert.AreEqual(2, allItems.Count);
Assert.AreEqual(2, allItems.OfType<A>().Count());
}
}
I've worked around the issue by removing items gradially rather than all in one go, but if I do a .Clear()
the whole merged collection is cleared, which is also wrong. Is there more correct way to do this?
Thanks
Update: seems likely to be coming from here:
Is there a better way to prevent this than to remove all items individually?
Metadata
Metadata
Assignees
Labels
No labels