From 7265ef7a897be00743db9e04523188969e9f0303 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 22 Jan 2014 12:40:51 -0800 Subject: [PATCH] fix(scope): honor $skipAutoDigest on non-root scopes Close #391 --- lib/core/scope.dart | 12 ++++++------ test/core/scope_spec.dart | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/core/scope.dart b/lib/core/scope.dart index b24fa1676..30f8d9c9c 100644 --- a/lib/core/scope.dart +++ b/lib/core/scope.dart @@ -102,8 +102,8 @@ class Scope implements Map { } _autoDigestOnTurnDone() { - if (_skipAutoDigest) { - _skipAutoDigest = false; + if ($root._skipAutoDigest) { + $root._skipAutoDigest = false; } else { $digest(); } @@ -393,7 +393,7 @@ class Scope implements Map { * auto-digesting scope. */ $$verifyDigestWillRun() { - assert(!_skipAutoDigest); + assert(!$root._skipAutoDigest); _zone.assertInTurn(); } @@ -632,12 +632,12 @@ class Scope implements Map { * you just scheduled or are otherwise certain of an impending VM turn and the * digest at the end of that turn is sufficient. You should be able to answer * "No" to the question "Is there any other code that is aware that this VM - * turn occured and therefore expected a digest?". If your answer is "Yes", + * turn occurred and therefore expected a digest?". If your answer is "Yes", * then you run the risk that the very next VM turn is not for your event and * now that other code runs in that turn and sees stale values. * * You might call this function, for instance, from an event listener where, - * though the event occured, you need to wait for another event before you can + * though the eventoccurredd, you need to wait for another event before you can * perform something meaningful. You might schedule that other event, * set a flag for the handler of the other event to recognize, etc. and then * call this method to skip the digest this cycle. Note that you should call @@ -647,7 +647,7 @@ class Scope implements Map { */ $skipAutoDigest() { _zone.assertInTurn(); - _skipAutoDigest = true; + $root._skipAutoDigest = true; } diff --git a/test/core/scope_spec.dart b/test/core/scope_spec.dart index 348945e5c..9924581e6 100644 --- a/test/core/scope_spec.dart +++ b/test/core/scope_spec.dart @@ -19,6 +19,7 @@ main() { describe(r'$root', () { it(r'should point to itself', inject((Scope $rootScope) { + expect($rootScope.$root).toEqual($rootScope); expect($rootScope.$root).toEqual($rootScope); expect($rootScope.$root).toBeTruthy(); })); @@ -106,6 +107,22 @@ main() { expect(digestedValue).toEqual(1); })); + it(r'should skip auto digest if requested on any scope', inject((Scope $rootScope) { + var scope = $rootScope.$new(); + var digestedValue = 0; + scope.a = 1; + scope.$watch('a', (newValue, oldValue, _this) { + digestedValue = newValue; + }); + expect(digestedValue).toEqual(0); + zone.run(() { + scope.$skipAutoDigest(); + }); + expect(digestedValue).toEqual(0); + zone.run(noop); + expect(digestedValue).toEqual(1); + })); + it(r'should throw exception if asked to skip auto digest outside of a turn', inject((Scope $rootScope) { var digestedValue = 0;