Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 86df529

Browse files
vicbrkirov
authored andcommitted
fix(dccd): fix removals reporting
closes #1097 Conflicts: lib/change_detection/dirty_checking_change_detector.dart
1 parent 03c3f54 commit 86df529

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

lib/change_detection/dirty_checking_change_detector.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -1142,9 +1142,6 @@ class _CollectionChangeRecord<V> implements CollectionChangeRecord<V> {
11421142
var prev = record._prevRemoved;
11431143
var next = record._nextRemoved;
11441144

1145-
assert((record._prevRemoved = null) == null);
1146-
assert((record._nextRemoved = null) == null);
1147-
11481145
if (prev == null) {
11491146
_removalsHead = next;
11501147
} else {
@@ -1252,10 +1249,12 @@ class _CollectionChangeRecord<V> implements CollectionChangeRecord<V> {
12521249
record.currentIndex = null;
12531250
if (_removedItems == null) _removedItems = new DuplicateMap();
12541251
_removedItems.put(record);
1252+
record._nextRemoved = null;
12551253

12561254
if (_removalsTail == null) {
12571255
assert(_removalsHead == null);
12581256
_removalsTail = _removalsHead = record;
1257+
record._prevRemoved = null;
12591258
} else {
12601259
assert(_removalsTail._nextRemoved == null);
12611260
assert(record._nextRemoved == null);

test/change_detection/dirty_checking_change_detector_spec.dart

+25
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,31 @@ void testWithGetterFactory(FieldGetterFactory getterFactory) {
288288
moves: ['2[1 -> 0]', '1[0 -> 1]'],
289289
removals: []));
290290
});
291+
292+
it('should handle swapping elements correctly - gh1097', () {
293+
// This test would only have failed in non-checked mode only
294+
var list = ['a', 'b', 'c'];
295+
var record = detector.watch(list, null, null);
296+
var iterator = detector.collectChanges()..moveNext();
297+
298+
list..clear()..addAll(['b', 'a', 'c']);
299+
iterator = detector.collectChanges()..moveNext();
300+
expect(iterator.current.currentValue, toEqualCollectionRecord(
301+
collection: ['b[1 -> 0]', 'a[0 -> 1]', 'c'],
302+
previous: ['a[0 -> 1]', 'b[1 -> 0]', 'c'],
303+
additions: [],
304+
moves: ['b[1 -> 0]', 'a[0 -> 1]', 'c'],
305+
removals: []));
306+
307+
list..clear()..addAll(['b', 'c', 'a']);
308+
iterator = detector.collectChanges()..moveNext();
309+
expect(iterator.current.currentValue, toEqualCollectionRecord(
310+
collection: ['b', 'c[2 -> 1]', 'a[1 -> 2]'],
311+
previous: ['b', 'a[1 -> 2]', 'c[2 -> 1]'],
312+
additions: [],
313+
moves: ['c[2 -> 1]', 'a[1 -> 2]'],
314+
removals: []));
315+
});
291316
});
292317

293318
it('should detect changes in list', () {

0 commit comments

Comments
 (0)