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

Commit

Permalink
fix(scope): honor $skipAutoDigest on non-root scopes
Browse files Browse the repository at this point in the history
Close #391
  • Loading branch information
mhevery committed Jan 22, 2014
1 parent 9d09a16 commit 7265ef7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/core/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ class Scope implements Map {
}

_autoDigestOnTurnDone() {
if (_skipAutoDigest) {
_skipAutoDigest = false;
if ($root._skipAutoDigest) {
$root._skipAutoDigest = false;
} else {
$digest();
}
Expand Down Expand Up @@ -393,7 +393,7 @@ class Scope implements Map {
* auto-digesting scope.
*/
$$verifyDigestWillRun() {
assert(!_skipAutoDigest);
assert(!$root._skipAutoDigest);
_zone.assertInTurn();
}

Expand Down Expand Up @@ -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

This comment has been minimized.

Copy link
@Droogans

Droogans Jan 23, 2014

Typo.

This comment has been minimized.

Copy link
@mhevery

mhevery Jan 23, 2014

Author Contributor

Thanks, fixed in 4494ce7

* 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
Expand All @@ -647,7 +647,7 @@ class Scope implements Map {
*/
$skipAutoDigest() {
_zone.assertInTurn();
_skipAutoDigest = true;
$root._skipAutoDigest = true;
}


Expand Down
17 changes: 17 additions & 0 deletions test/core/scope_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}));
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7265ef7

Please sign in to comment.