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

Add support for event delegation to jqLite.on #5483

Closed
kseamon opened this issue Dec 19, 2013 · 24 comments
Closed

Add support for event delegation to jqLite.on #5483

kseamon opened this issue Dec 19, 2013 · 24 comments

Comments

@kseamon
Copy link
Contributor

kseamon commented Dec 19, 2013

In addition to querySelectorAll support in find, it would be very convenient to leverage matchesSelector in order to have event delegation (filter and is would also be useful and fairly trivial).

@ghost ghost assigned IgorMinar Dec 20, 2013
@benjamingr
Copy link
Contributor

Care to show an "angular" use case for this?

@kseamon
Copy link
Contributor Author

kseamon commented Dec 21, 2013

It would allow some complex ui component directives to use jqlite instead of maintaining a jQuery dependency.

In light of the dropping of IE 8 support, this would no longer require a lot of code to support.

Sent from my iPhone

On Dec 21, 2013, at 7:39 AM, benjamingr [email protected] wrote:

Care to show an "angular" use case for this?


Reply to this email directly or view it on GitHub.

@benjamingr
Copy link
Contributor

Right, still - can you show me an example ?

Thanks.

@kseamon
Copy link
Contributor Author

kseamon commented Dec 21, 2013

The one that first comes to mind is a data grid directive that is somewhat widely used inside of Google. It uses jQuery's event delegation to detect mouse enter and mouse leave events on each cell that would otherwise require thousands of registrations if it had to be done on a per cell basis.

There's been some discussion of refactoring angular's built-in directives (ng-click, input, etc) to use delegation as well in order to reduce startup time and save memory, but some tests we did have indicated it might not be worth the effort, as it did not make a huge difference in one of our big apps (Though it might turn out to be more valuable in other apps).

Sent from my iPhone

On Dec 21, 2013, at 9:38 AM, benjamingr [email protected] wrote:

Right, still - can you show me an example ?

Thanks.


Reply to this email directly or view it on GitHub.

@benjamingr
Copy link
Contributor

Ok, thanks. That example seems solid.

@klebba
Copy link

klebba commented Jan 5, 2014

+1

3 similar comments
@quantizor
Copy link

+1

@madtimber
Copy link

+1

@soaxelbrooke
Copy link

+1

@uxder
Copy link

uxder commented Jul 3, 2014

+1

4 similar comments
@andrewplummer
Copy link

+1

@dance-cmdr
Copy link

+1

@orizens
Copy link

orizens commented Jul 15, 2014

+1

@jtomaszewski
Copy link

+1

@rodyhaddad rodyhaddad assigned tbosch and unassigned rodyhaddad Jul 23, 2014
@RafalFilipek
Copy link

+1

1 similar comment
@teabyii
Copy link

teabyii commented Jul 28, 2014

+1

@tbosch
Copy link
Contributor

tbosch commented Jul 31, 2014

Links to adding querySelectorAll to jqLite: #3586 and #3598.

matches or matchesSelector is supported on all major browsers now, see http://caniuse.com/matchesselector. We would only need to handle the browser prefixes and decide whether to use matches or matchesSelector.

@tbosch
Copy link
Contributor

tbosch commented Jul 31, 2014

The problem is that if we implement this we should probably also implement all the corner cases that jQuery did. E.g. for the blur event switch to focusout (see http://api.jquery.com/blur/).

@mzgol Do you know how many corner cases for event delegation there are in jQuery?

@mgol
Copy link
Member

mgol commented Jul 31, 2014

@mzgol Do you know how many corner cases for event delegation there are in jQuery?

There are more hooks (e.g. click handling native .click() DOM method for checkboxes) but if we restrict to delegation, apart from focus-related ones there is mouseenter/mouseleave and, since recently, pointerenter/pointerleave.

jQuery 1.x has more of them but that's not important here.

@tbosch
Copy link
Contributor

tbosch commented Jul 31, 2014

@mzgol: You and @IgorMinar talked about this, that even in jQuery there are still issues coming up with event delegation, and that we probably should not do this in jQLite. Could you add some more details here and then close this issue?

@tbosch
Copy link
Contributor

tbosch commented Aug 16, 2014

@mzgol ping :-)

@mgol
Copy link
Member

mgol commented Aug 16, 2014

I'm on holiday until Tuesday so I'll replay then.

Michał Gołębiowski

@mgol
Copy link
Member

mgol commented Aug 20, 2014

Maybe not so much issues as the fact that it still requires workarounds for some events (as I described in the previous comments) and for Angular users it's more "natural" to implement directives "in place" (delegated events are in fact events of ancestors that are interpreted in the context of the descendant) for better isolation etc. This and the fact that there was no noticeable performance gain for Angular prototype implementations leveraging delegated events (ng-click is only one example but for events that would fire more frequently one has to remember that delegated events save overhead when registering handlers but incur the perf. penalty when triggering them).

jQuery supports a lot of edge cases but jqLite's aim is to support most needed ones for Angular apps while keeping the size low and it doesn't seem this would be very useful in the Angular context.

@IgorMinar might be able to say more. In the meantime, I'll close the issue.

@mgol mgol closed this as completed Aug 20, 2014
@tbosch
Copy link
Contributor

tbosch commented Aug 22, 2014

Thanks!

On Wed, Aug 20, 2014 at 12:33 PM, Michał Gołębiowski <
[email protected]> wrote:

Maybe not so much issues as the fact that it still requires workarounds
for some events (as I described in the previous comments) and for Angular
users it's more "natural" to implement directives "in place" (delegated
events are in fact events of ancestors that are interpreted in the context
of the descendant) for better isolation etc. This and the fact that there
was no noticeable performance gain for Angular prototype implementations
leveraging delegated events (ng-click is only one example but for events
that would fire more frequently one has to remember that delegated events
save overhead when registering handlers but incur the perf. penalty when
triggering them).

jQuery supports a lot of edge cases but jqLite's aim is to support most
needed ones for Angular apps while keeping the size low and it doesn't seem
this would be very useful in the Angular context.

Igor might be able to say more. In the meantime, I'll close the issue.


Reply to this email directly or view it on GitHub
#5483 (comment).

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

No branches or pull requests