Skip to content

Commit f30efa2

Browse files
authored
Fixed that .SortAndPage() would not send a downstream changeset upon change of the comprer, when the current page includes all items. (#967)
1 parent 5e1dcd5 commit f30efa2

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

src/DynamicData.Tests/Cache/SortAndPageFixture.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,32 @@ public void ChangeComparer()
4040
// change the comparer
4141
_comparerSubject.OnNext(_descComparer);
4242

43+
Aggregator.Messages.Cast<IChangeSet<Person, string, PageContext<Person>>>().LastOrDefault().Context.Comparer.Should().Be(_descComparer);
4344
expectedResult = people.OrderBy(p => p, _descComparer).Take(25).ToList();
44-
actualResult = Aggregator.Data.Items.OrderBy(p => p, Comparer);
45+
actualResult = Aggregator.Data.Items.OrderBy(p => p, _descComparer);
46+
actualResult.Should().BeEquivalentTo(expectedResult);
47+
}
48+
49+
[Fact]
50+
public void ChangeComparerWithOnlyOnePage()
51+
{
52+
PageRequests.OnNext(new PageRequest(page: 1, size: 200));
53+
54+
var people = Enumerable.Range(1, 100).Select(i => new Person($"P{i:000}", i)).OrderBy(p => Guid.NewGuid());
55+
Source.AddOrUpdate(people);
56+
57+
// for first batch, it should use the results of the _PageRequests subject (if a behaviour subject is used).
58+
var expectedResult = people.OrderBy(p => p, Comparer).ToList();
59+
var actualResult = Aggregator.Data.Items.OrderBy(p => p, Comparer);
60+
actualResult.Should().BeEquivalentTo(expectedResult);
61+
var changesetCount = Aggregator.Messages.Count;
62+
63+
// change the comparer
64+
_comparerSubject.OnNext(_descComparer);
65+
66+
Aggregator.Messages.Cast<IChangeSet<Person, string, PageContext<Person>>>().LastOrDefault().Context.Comparer.Should().Be(_descComparer);
67+
expectedResult = people.OrderBy(p => p, _descComparer).ToList();
68+
actualResult = Aggregator.Data.Items.OrderBy(p => p, _descComparer);
4569
actualResult.Should().BeEquivalentTo(expectedResult);
4670
}
4771
}

src/DynamicData/Cache/Internal/SortAndPage.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,11 @@ public IObservable<IChangeSet<TObject, TKey, PageContext<TObject>>> Run() =>
110110
return ApplyPagedChanges(changes);
111111
});
112112

113-
return
114-
comparerChanged
115-
.Merge(paramsChanged)
116-
.Merge(dataChange)
117-
.Where(changes => changes.Count is not 0)
118-
.SubscribeSafe(observer);
113+
return Observable.Merge(
114+
comparerChanged.Skip(1),
115+
paramsChanged.Where(changes => changes.Count is not 0),
116+
dataChange.Where(changes => changes.Count is not 0))
117+
.SubscribeSafe(observer);
119118

120119
ChangeSet<TObject, TKey, PageContext<TObject>> ApplyPagedChanges(IChangeSet<TObject, TKey>? changeSet = null)
121120
{

0 commit comments

Comments
 (0)