-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat($rootScope): implement non-propagating event dispatcher #4625
Conversation
Shared event dispatch logic centralizes the place to fix event dispatch logic, and theoretically shrinks code ever so slightly.
$dispatch provides a mechanism to dispatch events to a single scope without worrying about having to terminate propagation. This is useful for many directives which need to communicate with an immediately adjacent scope, but do not wish to propagate the events beyond that point.
Thanks for the PR!
If you need to make changes to your pull request, you can update the commit with Thanks again for your help! |
Let's reference this discussion here. It's not really related to my proposal but since you left some notes about your plans in that ticket, I think it's worth to link it here. |
Heh =) It is unrelated of course. For a convenience method like you're suggesting, what about making the target scope an optional first parameter to But I'm still not sure any of this stuff is likely to get merged in, and isn't really a priority right now. Just stuff to think about and see if developers get anything out of it. |
That's how I had it at first ;) I just wanted to make it even more convenient. But it's a fair point to consider. |
I'm sorry, but I wasn't able to verify your CLA signature. CLA signature is required for any code contributions to AngularJS. Please sign our CLA and ensure that the CLA signature email address and the email address in this PR's commits match. If you signed the CLA as a corporation, please let me know the company's name. Thanks a bunch! PS: If you signed the CLA in the past then most likely the email addresses don't match. Please sign the CLA again or update the email address in the commit of this PR. |
CLA signature verified! Thank you! Someone from the team will now triage your PR and it will be processed based on the determined priority (doc updates and fixes with tests are prioritized over other changes). |
02dc2aa
to
fd2d6c0
Compare
$dispatch provides a mechanism to dispatch events to a single scope without worrying about having to terminate propagation. This is useful for many directives which need to communicate with an immediately adjacent scope, but do not wish to propagate the events beyond that point.
This patch also (experimentally) combines the event dispatch logic from $broadcast and $emit into a shared routine, so that $dispatch can easily share the same code. Unfortunately the shared code is not super clean, which is
sort of a downside.
This is really just an experiment, however a strategy like $dispatch would be useful in a lot of cases, so I'm interested to see what people think of it.
The good news is that, in combination with the "shared logic" patch,
$dispatch()
is a one-liner.