Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,10 @@ protected override void Handler(in NotifyCollectionChangedEventArgs<T> eventArgs
case NotifyCollectionChangedAction.Add:
case NotifyCollectionChangedAction.Remove:
case NotifyCollectionChangedAction.Reset when countPrev != collection.Count:
countPrev = collection.Count;
observer.OnNext(collection.Count);
break;
}
countPrev = collection.Count;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void ObserveReplace()
collection[1] = 444;
events.Count.Should().Be(1);
}

[Fact]
public void ObserveDictionaryReplace()
{
Expand Down Expand Up @@ -247,6 +247,27 @@ public void ObserveCountChanged()
events.Count.Should().Be(3);
}

[Fact]
public void ObserveCountChanged_WithSideEffect()
{
var events = new List<int>();
var collection = new ObservableList<int>([]);

using var _ = collection.ObserveCountChanged().Subscribe(count =>
{
events.Add(count);
// Side effect - when count is 1, clear the list
if(count == 1) collection.Clear();
});

events.Should().BeEmpty();

collection.Add(12);

collection.Count.Should().Be(0);
events.Should().BeEquivalentTo([1, 0]);
}

[Fact]
public void ObserveCountChanged_NotifyCurrent()
{
Expand All @@ -257,4 +278,4 @@ public void ObserveCountChanged_NotifyCurrent()
.Subscribe(count => events.Add(count));
events[0].Should().Be(3);
}
}
}