-
-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fn.on delegation misbehaviour #235
Comments
I see 2 problems here:
Thanks for the bug report, I'll try to get this fixed in a timely manner. |
The issue with When using event delegation in jQuery, ie. Luckily it seems that we can use It might be good to mention that we don't support things like |
I'm afraid both problems can't be fixed, not without any major drawbacks. I've added a section to the migration guide about this, you might want to check that out: https://github.com/kenwheeler/cash/blob/master/docs/migration_guide.md/#events Here there's an explanation why they can't be fixed without major drawbacks:
event.currentTarget = 123;
event.currentTarget === 123; // => false Possibile solutions that come to mind:
Both possible solutions are unaccetable, so just use
We are listening for events on the target element, not the delegate elements. That's basically the whole point of event delegation. So when you call Possibile solutions that come to mind:
Both possible solutions are unaccetable, and there isn't a workaround that works for every situation, in many cases you could just use I'm closing this issue as it doesn't look like there's a way for us to fix it that doesn't come with huge downsides. |
Thanks for the quick response. Using Until the best solution is determined it may be good to use an additional property on I noticed another problem during testing today. Some events (e.g. |
I don't want to add custom properties that don't have a jQuery counterpart to events. I feel your pain, and you can already do that yourself by patching cash's const onPrev = $.fn.on;
$.fn.on = function on ( event, selector, callback, _one ) {
if ( $.isString ( eventFullName ) ) {
if ( isFunction ( selector ) ) {
callback = selector;
selector = '';
}
const callbackPrev = callback;
callback = function callback ( event, data ) {
event.myCustomProperty = this;
return callbackPrev.call ( this, event, data );
}
}
return onPrev.call ( this, event, selector, callback, _one );
};
Can you make a separate issue about this? |
Reopening as these issues might be fixable without any major drawbacks.
We only have to clone the event object when using event delegation. Hopefully cloning it would be fast and all those
We can call Basically in order to fix both of these issues we need to have writable events. |
Fixed in 7d0884f.
|
It seems that there are some unexpected errors when using this 🤔 I'll investigate this further tomorrow. |
Since part of this issue has been resolved I'm closing this in favor of #238. |
In #188
this
was fixed but I noticed that the value ofevent.currentTarget
is different from jQuery.You can see the current behaviour here.
event.currentTarget
returns always the outer div even when you click the inner.The expected behaviour is this.
When you click the inner div
event.currentTarget
should return the inner div.It also looks like cash triggers both events (on the outer and inner div) whereas jQuery only triggers the second one.
The text was updated successfully, but these errors were encountered: