Skip to content

Commit

Permalink
fix(scope): log firing expressions in the watchLog
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelgj committed Dec 14, 2013
1 parent 6c6151c commit 0e66b21
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/core/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,11 @@ class Scope implements Map {

watcherCount = 0;
scopeCount = 0;
var firedExpressions;
if (_ttl - _ttlLeft >= 2) {
firedExpressions = <String>[];
watchLog.add(firedExpressions);
}
assert((timerId = _perf.startTimer('ng.dirty_check', _ttl-_ttlLeft)) != false);
digestLoop:
do { // "traverse the scopes" loop
Expand All @@ -456,6 +461,9 @@ class Scope implements Map {
var value = watch.get(current);
var last = watch.last;
if (!_identical(value, last)) {
if (_ttl - _ttlLeft >= 2) {
firedExpressions.add(watch.exp == null ? '[closure]' : watch.exp);
}
lastDirtyWatch = watch;
lastLoopLastDirtyWatch = null;
watch.last = value;
Expand Down
14 changes: 14 additions & 0 deletions test/core/scope_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,20 @@ main() {
}));


it(r'should prevent infinite digest and should log firing expressions', inject((Scope $rootScope) {
$rootScope['a'] = 0;
$rootScope['b'] = 0;
$rootScope.$watch('a = a + 1');
$rootScope.$watch('b = b + 1');

expect(() {
$rootScope.$digest();
}).toThrow('Watchers fired in the last 5 iterations: ['
'["a = a + 1","b = b + 1"],["a = a + 1","b = b + 1"],'
'["a = a + 1","b = b + 1"],["a = a + 1","b = b + 1"]]');
}));


it(r'should always call the watchr with newVal and oldVal equal on the first run',
inject((Scope $rootScope) {
var log = [];
Expand Down

0 comments on commit 0e66b21

Please sign in to comment.