Skip to content

Commit

Permalink
Fixed that .SortAndPage() would not send a downstream changeset upon …
Browse files Browse the repository at this point in the history
…change of the comprer, when the current page includes all items. (#967)
  • Loading branch information
JakenVeina authored Dec 17, 2024
1 parent 5e1dcd5 commit f30efa2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
26 changes: 25 additions & 1 deletion src/DynamicData.Tests/Cache/SortAndPageFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,32 @@ public void ChangeComparer()
// change the comparer
_comparerSubject.OnNext(_descComparer);

Aggregator.Messages.Cast<IChangeSet<Person, string, PageContext<Person>>>().LastOrDefault().Context.Comparer.Should().Be(_descComparer);
expectedResult = people.OrderBy(p => p, _descComparer).Take(25).ToList();
actualResult = Aggregator.Data.Items.OrderBy(p => p, Comparer);
actualResult = Aggregator.Data.Items.OrderBy(p => p, _descComparer);
actualResult.Should().BeEquivalentTo(expectedResult);
}

[Fact]
public void ChangeComparerWithOnlyOnePage()
{
PageRequests.OnNext(new PageRequest(page: 1, size: 200));

var people = Enumerable.Range(1, 100).Select(i => new Person($"P{i:000}", i)).OrderBy(p => Guid.NewGuid());
Source.AddOrUpdate(people);

// for first batch, it should use the results of the _PageRequests subject (if a behaviour subject is used).
var expectedResult = people.OrderBy(p => p, Comparer).ToList();
var actualResult = Aggregator.Data.Items.OrderBy(p => p, Comparer);
actualResult.Should().BeEquivalentTo(expectedResult);
var changesetCount = Aggregator.Messages.Count;

// change the comparer
_comparerSubject.OnNext(_descComparer);

Aggregator.Messages.Cast<IChangeSet<Person, string, PageContext<Person>>>().LastOrDefault().Context.Comparer.Should().Be(_descComparer);
expectedResult = people.OrderBy(p => p, _descComparer).ToList();
actualResult = Aggregator.Data.Items.OrderBy(p => p, _descComparer);
actualResult.Should().BeEquivalentTo(expectedResult);
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/DynamicData/Cache/Internal/SortAndPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,11 @@ public IObservable<IChangeSet<TObject, TKey, PageContext<TObject>>> Run() =>
return ApplyPagedChanges(changes);
});

return
comparerChanged
.Merge(paramsChanged)
.Merge(dataChange)
.Where(changes => changes.Count is not 0)
.SubscribeSafe(observer);
return Observable.Merge(
comparerChanged.Skip(1),
paramsChanged.Where(changes => changes.Count is not 0),
dataChange.Where(changes => changes.Count is not 0))
.SubscribeSafe(observer);

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

0 comments on commit f30efa2

Please sign in to comment.