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

Incorrect behavior of deregistration function returned from $rootScope.$on when called twice #9666

Closed
dmytroyarmak opened this issue Oct 17, 2014 · 1 comment

Comments

@dmytroyarmak
Copy link
Contributor

Hello,

I've notice that when you call deregistration function more than one time it decrease $$listenerCount each time.
https://github.com/angular/angular.js/blob/master/src/ng/rootScope.js#L1105-L1108

After $$listenerCount becomes zero $breadcast starts ignore this event and It cause that other listeners for the same event will not be called.
https://github.com/angular/angular.js/blob/master/src/ng/rootScope.js#L1219

Reproducing

Here is plunker and steps to reproduce:
http://plnkr.co/edit/bHtWlu?p=preview

We have page with two handlers that bound to "sampleEvent", 3 buttons that broadcasts and unbinds handlers, block with displayed $$listenerCount value.

  1. sampleEvent count equal 2
  2. Click "Emit simple event"
  3. Two alerts should appear
  4. Click "Unregister first handler"
  5. sampleEvent count equal 1
  6. Click "Emit simple event"
  7. One alert should appear
  8. Click "Unregister first handler" second time

Actual result:

There is no sampleEvent count and second handler is not triggered after broadcast 'sampleEvent'

Expected result:

sampleEvent should still be 1 and second handler should be triggered after broadcast 'sampleEvent'

I'm going to create pull request with fix for this bug after few minutes.

@petebacondarwin
Copy link
Contributor

Closing in favour of the pr.

petebacondarwin pushed a commit that referenced this issue Oct 19, 2014
Check that listener is still present in $$listeners before decrease
$$listenerCount. It fixes problem with incorrect $$listenerCount after
call deregistering function multiple times.

Closes #9666
Closes #9667
petebacondarwin added a commit that referenced this issue Oct 19, 2014
Check that listener is still present in $$listeners before decrease
$$listenerCount. It fixes problem with incorrect $$listenerCount after
call deregistering function multiple times.

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

Successfully merging a pull request may close this issue.

2 participants