Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix($evalAsync): have only one global async queue
Browse files Browse the repository at this point in the history
Having one async queue per scope complicates the matters when users wish to do
partial scope updates, since many services put events on the rootScope. By
having single queue the programing model is simplified.
  • Loading branch information
mhevery committed Sep 11, 2012
1 parent f2ebfa1 commit 331cd5a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions src/ng/rootScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ function $RootScopeProvider(){
child['this'] = child;
child.$$listeners = {};
child.$parent = this;
child.$$asyncQueue = [];
child.$$watchers = child.$$nextSibling = child.$$childHead = child.$$childTail = null;
child.$$prevSibling = this.$$childTail;
if (this.$$childHead) {
Expand Down Expand Up @@ -362,7 +361,7 @@ function $RootScopeProvider(){
$digest: function() {
var watch, value, last,
watchers,
asyncQueue,
asyncQueue = this.$$asyncQueue,
length,
dirty, ttl = TTL,
next, current, target = this,
Expand All @@ -371,18 +370,19 @@ function $RootScopeProvider(){

beginPhase('$digest');

do {
do { // "while dirty" loop
dirty = false;
current = target;
do {
asyncQueue = current.$$asyncQueue;
while(asyncQueue.length) {
try {
current.$eval(asyncQueue.shift());
} catch (e) {
$exceptionHandler(e);
}

while(asyncQueue.length) {
try {
current.$eval(asyncQueue.shift());
} catch (e) {
$exceptionHandler(e);
}
}

do { // "traverse the scopes" loop
if ((watchers = current.$$watchers)) {
// process our watches
length = watchers.length;
Expand Down
2 changes: 1 addition & 1 deletion test/ng/rootScopeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ describe('Scope', function() {
child.$evalAsync(function(scope) { log += 'child.async;'; });
child.$watch('value', function() { log += 'child.$digest;'; });
$rootScope.$digest();
expect(log).toEqual('parent.async;parent.$digest;child.async;child.$digest;');
expect(log).toEqual('parent.async;child.async;parent.$digest;child.$digest;');
}));

it('should cause a $digest rerun', inject(function($rootScope) {
Expand Down

0 comments on commit 331cd5a

Please sign in to comment.