Skip to content

Commit 9db62d6

Browse files
committed
add $defer.flush('$burp') to the scope life-cycle
1 parent b004276 commit 9db62d6

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/Scope.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ function createScope(providers, instanceCache) {
101101
* {@link angular.service.$exceptionHandler $exceptionHandler} service.
102102
* 3. The {@link angular.scope.$watch watch} listeners are fired immediately after
103103
* the expression was executed using the {@link angular.scope.$digest $digest()} method.
104-
* 4. Finally the update of the DOM is scheduled using the
104+
* 4. The `{@link angular.service.$defer $burp queue} with deferred tasks is flushed.
105+
* 5. Finally the update of the DOM is scheduled using the
105106
* {@link angular.service.$updateView $updateView} service (see step #6) The `$updateView`
106107
* may merge multiple requests, that are close time-wise, into a single update.
107108
* 6. The {@link angular.service.$updateView $updateView} service then fires DOM
@@ -842,6 +843,7 @@ Scope.prototype = {
842843
$exceptionHandler(e);
843844
} finally {
844845
$root.$digest();
846+
$defer.flush('$burp');
845847
$updateView();
846848
}
847849
}
@@ -860,6 +862,7 @@ Scope.prototype = {
860862
this.$service('$exceptionHandler')(e);
861863
} finally {
862864
this.$root.$digest();
865+
this.$service('$defer').flush('$burp');
863866
this.$service('$updateView')();
864867
}
865868
}

test/ScopeSpec.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,10 @@ describe('Scope', function(){
439439
var log = '';
440440
var child = root.$new();
441441
root.$watch('a', function(scope, a){ log += '1'; });
442-
root.$observe('a', function(scope, a){ log += '2'; });
442+
root.$observe('a', function(scope, a){ log += '3'; });
443+
root.$service('$defer')('$burp', function() { log += '2'; });
443444
child.$apply('$parent.a=0');
444-
expect(log).toEqual('12');
445+
expect(log).toEqual('123');
445446
});
446447

447448

@@ -464,8 +465,11 @@ describe('Scope', function(){
464465
log = '';
465466
$exceptionHandler = jasmine.createSpy('$exceptionHandler');
466467
$updateView = jasmine.createSpy('$updateView');
468+
$defer = {flush: jasmine.createSpy('$defer.flush')};
467469
root.$service = function(name) {
468-
return {$updateView:$updateView, $exceptionHandler:$exceptionHandler}[name];
470+
return {$updateView:$updateView,
471+
$exceptionHandler:$exceptionHandler,
472+
$defer:$defer}[name];
469473
};
470474
root.$watch(function(){ log += '$digest;'; });
471475
log = '';

0 commit comments

Comments
 (0)