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

Commit 331cd5a

Browse files
committed
fix($evalAsync): have only one global async queue
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.
1 parent f2ebfa1 commit 331cd5a

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/ng/rootScope.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ function $RootScopeProvider(){
195195
child['this'] = child;
196196
child.$$listeners = {};
197197
child.$parent = this;
198-
child.$$asyncQueue = [];
199198
child.$$watchers = child.$$nextSibling = child.$$childHead = child.$$childTail = null;
200199
child.$$prevSibling = this.$$childTail;
201200
if (this.$$childHead) {
@@ -362,7 +361,7 @@ function $RootScopeProvider(){
362361
$digest: function() {
363362
var watch, value, last,
364363
watchers,
365-
asyncQueue,
364+
asyncQueue = this.$$asyncQueue,
366365
length,
367366
dirty, ttl = TTL,
368367
next, current, target = this,
@@ -371,18 +370,19 @@ function $RootScopeProvider(){
371370

372371
beginPhase('$digest');
373372

374-
do {
373+
do { // "while dirty" loop
375374
dirty = false;
376375
current = target;
377-
do {
378-
asyncQueue = current.$$asyncQueue;
379-
while(asyncQueue.length) {
380-
try {
381-
current.$eval(asyncQueue.shift());
382-
} catch (e) {
383-
$exceptionHandler(e);
384-
}
376+
377+
while(asyncQueue.length) {
378+
try {
379+
current.$eval(asyncQueue.shift());
380+
} catch (e) {
381+
$exceptionHandler(e);
385382
}
383+
}
384+
385+
do { // "traverse the scopes" loop
386386
if ((watchers = current.$$watchers)) {
387387
// process our watches
388388
length = watchers.length;

test/ng/rootScopeSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ describe('Scope', function() {
441441
child.$evalAsync(function(scope) { log += 'child.async;'; });
442442
child.$watch('value', function() { log += 'child.$digest;'; });
443443
$rootScope.$digest();
444-
expect(log).toEqual('parent.async;parent.$digest;child.async;child.$digest;');
444+
expect(log).toEqual('parent.async;child.async;parent.$digest;child.$digest;');
445445
}));
446446

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

0 commit comments

Comments
 (0)