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

Commit 30a774d

Browse files
committed
refactor($scope): present multiple calls to listener on $destroy
Prevent isolated scopes from having listeners that get called multiple times when on `$destroy`
1 parent 5cf1d89 commit 30a774d

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

Diff for: src/ng/rootScope.js

+1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ function $RootScopeProvider(){
196196
// ensure that there is just one async queue per $rootScope and its children
197197
child.$$asyncQueue = this.$$asyncQueue;
198198
child.$$postDigestQueue = this.$$postDigestQueue;
199+
child.$on('$destroy', function() { child.$$destroyed = true; });
199200
} else {
200201
// Only create a child scope class if somebody asks for one,
201202
// but cache it to allow the VM to optimize lookups.

Diff for: test/ng/rootScopeSpec.js

+7
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,13 @@ describe('Scope', function() {
994994
expect(log).toBe('123');
995995
}));
996996

997+
it('should broadcast the $destroy only once', inject(function($rootScope, log) {
998+
var isolateScope = first.$new(true);
999+
isolateScope.$on('$destroy', log.fn('event'));
1000+
first.$destroy();
1001+
isolateScope.$destroy();
1002+
expect(log).toEqual('event');
1003+
}));
9971004

9981005
it('should decrement ancestor $$listenerCount entries', inject(function($rootScope) {
9991006
var EVENT = 'fooEvent',

0 commit comments

Comments
 (0)