Skip to content

Commit

Permalink
Merge pull request #5 from tylandercasper/patch-3
Browse files Browse the repository at this point in the history
add notifyWhenEqual to projectListSplices
  • Loading branch information
jodinathan authored Jan 5, 2025
2 parents ddd845e + 682bcea commit 15f3923
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.28.0
* add notifyWhenEqual to projectListSplices so equal changes aren't filtered out

## 0.27.0
* added notifyWhenEqual flag to ObservableMap

Expand Down
4 changes: 2 additions & 2 deletions lib/src/async/differs/list_differ.dart
Original file line number Diff line number Diff line change
Expand Up @@ -442,14 +442,14 @@ List<ListChangeRecord<E>> _createInitialSplices<E>(
// insert incorrectly, because those items will be shifted.
List<ListChangeRecord<E>> projectListSplices<E>(
List<E> list, List<ListChangeRecord<E>> records,
[Equality<E>? equality]) {
{Equality<E>? equality, bool notifyWhenEqual = false}) {
equality ??= DefaultEquality<E>();
if (records.length <= 1) return records;
final splices = <ListChangeRecord<E>>[];
final initialSplices = _createInitialSplices(list, records);
for (final splice in initialSplices) {
if (splice.addedCount == 1 && splice.removed.length == 1) {
if (splice.removed[0] != list[splice.index]) {
if (notifyWhenEqual || splice.removed[0] != list[splice.index]) {
splices.add(splice);
}
continue;
Expand Down
4 changes: 3 additions & 1 deletion lib/src/async/observable_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ class ObservableList<E> extends ListBase<E>

bool deliverListChanges() {
if (_listRecords == null) return false;
final records = projectListSplices<E>(this, _listRecords!);
//projectListSplices removes equal entries so skip the call when requested
final records = projectListSplices<E>(this, _listRecords!,
notifyWhenEqual: notifyWhenEqual);
_listRecords = null;

if (hasListObservers && records.isNotEmpty) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: change_notifier
version: 0.27.0
version: 0.28.0
description: Support for marking objects as observable
homepage: https://github.com/angulardart-community/change_notifier
environment:
Expand Down

0 comments on commit 15f3923

Please sign in to comment.