diff --git a/lib/change_detection/dirty_checking_change_detector.dart b/lib/change_detection/dirty_checking_change_detector.dart index eaf91e06a..b80097cfa 100644 --- a/lib/change_detection/dirty_checking_change_detector.dart +++ b/lib/change_detection/dirty_checking_change_detector.dart @@ -629,6 +629,14 @@ class DirtyCheckingRecord implements WatchRecord { 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; diff --git a/test/core/scope_spec.dart b/test/core/scope_spec.dart index 83f2d30d4..bd5d7ff07 100644 --- a/test/core/scope_spec.dart +++ b/test/core/scope_spec.dart @@ -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) { @@ -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 {