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

Fixed issues where a List with the same data but different instance would cause "Model Unstable" #1677

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
8 changes: 8 additions & 0 deletions lib/change_detection/dirty_checking_change_detector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,14 @@ class DirtyCheckingRecord<H> implements WatchRecord<H> {
currentValue = current;
} else if (last is num && last.isNaN && current is num && current.isNaN) {
// we need this for the compiled JavaScript since in JS NaN !== NaN.
} else if (last is List && current is List && last.length == current.length) {
for (int i = 0; i < last.length; i++){
if (last[i] != current[i]){
previousValue = last;
currentValue = current;
return true;
}
}
} else {
previousValue = last;
currentValue = current;
Expand Down
25 changes: 24 additions & 1 deletion test/core/scope_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,19 @@ void main() {
expect(errors.length).toEqual(1);
expect(errors.first.error, startsWith('Model did not stabilize'));
});

it('should not throw "model unstable" error if new list but same data', (RootScope rootScope, VmTurnZone zone, ExceptionHandler e) {
// Generates a different, equal, list on each evaluation.
rootScope.context['list'] = new StableButDifferentInstanceList();

rootScope.watch('list.list', (n, v) => null, canChangeModel: true);
try {
zone.run(() => null);
} catch(_) {}

var errors = (e as LoggingExceptionHandler).errors;
expect(errors.length).toEqual(0);
});
});

it(r'should allow stopping event propagation', (RootScope rootScope) {
Expand Down Expand Up @@ -1757,7 +1770,17 @@ class MockScopeStatsEmitter implements ScopeStatsEmitter {
}

class UnstableList {
List get list => new List.generate(3, (i) => i);
int value = 1;
List get list => new List.generate(3, (i) => value++);
}

class StableButDifferentInstanceList {
StableObject stableObject = new StableObject();
List get list => new List()..addAll([stableObject,stableObject,stableObject]);
}

class StableObject{

}

class Foo {
Expand Down