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

feat($rootScope): implement non-propagating event dispatcher #4625

Closed
wants to merge 2 commits into from

Conversation

caitp
Copy link
Contributor

@caitp caitp commented Oct 24, 2013

$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.

Caitlin Potter added 2 commits October 24, 2013 10:11
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.
@mary-poppins
Copy link

Thanks for the PR!

  • Contributor signed CLA now or in the past
    • If you just signed, leave a comment here with your real name
  • PR's commit messages follow the commit message format

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!

@cburgdorf
Copy link
Contributor

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.

@caitp
Copy link
Contributor Author

caitp commented Oct 25, 2013

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 Scope.$on? That way you could have this convenience method for $rootScope as well as direct siblings, and it wouldn't really change the Scope interface in any significant way.

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.

@cburgdorf
Copy link
Contributor

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.

@IgorMinar
Copy link
Contributor

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.
PS2: If you are a Googler, please sign the CLA as well to simplify the CLA verification process.

@IgorMinar
Copy link
Contributor

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).

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

Successfully merging this pull request may close these issues.

5 participants