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

refactor($rootScope): add warnings when emitting/broadcasting on a destroyed scope #6784

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

andersekdahl
Copy link

When a scope is destroyed, all event listeners gets unregistered, and the connection to
the parent/child scopes are removed. Because of this, no one is noticed of the event.
$emit and $broadcast now logs a warning when trying to emit or broadcast an event on
a destroyed scope.

Closes #6768

…stroyed scope

When a scope is destroyed, all event listeners gets unregistered, and the connection to
the parent/child scopes are removed. Because of this, no one is noticed of the event.
$emit and $broadcast now logs a warning when trying to emit or broadcast an event on
a destroyed scope.

Closes angular#6768
@mary-poppins
Copy link

Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.

  • Uses the issue template (#6784)

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

Thanks again for your help!

@andersekdahl
Copy link
Author

Yes, well, it's a bit of a slippery slope in that case. If it's the child of a destroyed scope, and the child scope hasn't yet been destroyed then it can still call listeners on the child scope. So my reasoning for only checking this.$$destroyed is that in that case there's no chance of anyone recieving that event.

@thorn0
Copy link
Contributor

thorn0 commented Dec 14, 2014

Subscopes of destroyed scopes have $$destroyed set to false, at least in v1.3.6.
See https://github.com/angular/angular.js/blob/master/src/ng/rootScope.js#L229

@lgalfaso
Copy link
Contributor

@thorn0 did you mean: set to true?

@thorn0
Copy link
Contributor

thorn0 commented Dec 15, 2014

Oops, yes, I did.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Emitting an event on a destroyed scope
5 participants