-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix x-on with both self and once #4152
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the once
modifier should be moved to be the final modifier handled to also also handle keydown and keyup once usages.
I'm not sure if I understand your request correctly. Keydown and keydown are already lexically last, i.e. evaluated first. But maybe we want to move |
I added a test for Tests for |
Shouldn't 'once' be part of the options passed to the addEventListener though? Once option docs: |
That wouldn't work with the filtering modifiers, @Tim-Wils. Let's take keydown as an example: with plain event listeners, you can only listen for window.addEventListener('keydown', function(event) {
if (event.key === 'b') {
console.log('pressed b once');
}
}, { once: true }); Press first "a". Then press "b". Nothing will be logged on the console, because after pressing a, the listener would be gone. |
@bb Seems fair, you're right :) Thanks for the example! |
Yes last or first. Once should do it's thing only once all the others have passed, no? If once is after self, it should also be after the keyup modifiers. Since they should both only do the once if they pass. |
Exactly. That's how I did it from the beginning and how it still is. Order of processing in as of the current state of this PR:
So, what's your request? |
Looks great and makes perfect sense. Thanks @bb! |
Thanks for merging and for AlpineJS in general 😊 |
I want to use the
once
andself
modifiers together, like@something.self.once
, but the handler never runs if the first event is not from self. I think the reason is that once is evaluated before self.This PR fixes the order of evaluating the modifiers so the two work together.
I think the failing test is unrelated.