unify hx-on and hx-trigger modifier grammar2#3805
Open
MichaelWest22 wants to merge 7 commits into
Open
Conversation
- enable hx-on="eventSpec => code" syntax that supports all existing hx-trigger modifiers (e.g. [filter], once, delay, changed, from, etc.). - add new modifiers to both hx-on and hx-trigger: prevent, stop, halt, capture, passive, from:self, from:outside - remove undocumented dot modifiers (.prevent, .stop, .halt, .once, .self, .outside, .capture, .passive, .cc) from hx-on:event syntax - rename __onTrigger -> __onEvent - rename __parseTriggerSpecs -> __parseEventSpecs - remove hx-trigger queue modifier from docs (no-op in 4.0) - update tests, docs, and extension references
Change the grammar separator in hx-on="event => code" from => to ->.
This avoids visual ambiguity with JavaScript arrow functions that may
appear in the handler code.
Updated:
- src/htmx.js: indexOf('=>') → indexOf('->')
- test/tests/attributes/hx-on.js: all hx-on attribute values
- test/tests/ext/hx-live.js: hx-live helper tests using hx-on
- www docs: all examples and explanations in hx-on.md
- enable hx-on="eventSpec => code" syntax that supports all existing hx-trigger modifiers (e.g. [filter], once, delay, changed, from, etc.). - add new modifiers to both hx-on and hx-trigger: prevent, stop, halt, capture, passive, from:self, from:outside - remove undocumented dot modifiers (.prevent, .stop, .halt, .once, .self, .outside, .capture, .passive, .cc) from hx-on:event syntax - rename __onTrigger -> __onEvent - rename __parseTriggerSpecs -> __parseEventSpecs - remove hx-trigger queue modifier from docs (no-op in 4.0) - update tests, docs, and extension references
Change the grammar separator in hx-on="event => code" from => to ->.
This avoids visual ambiguity with JavaScript arrow functions that may
appear in the handler code.
Updated:
- src/htmx.js: indexOf('=>') → indexOf('->')
- test/tests/attributes/hx-on.js: all hx-on attribute values
- test/tests/ext/hx-live.js: hx-live helper tests using hx-on
- www docs: all examples and explanations in hx-on.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Built some changes on top of the great work in #3798
Changes @scriptogre made:
enable hx-on="triggerSpec -> code" syntax that supports all existing hx-trigger modifiers (e.g. [filter], once, delay, changed, from, etc.).
add new modifiers to both hx-on and hx-trigger: prevent, stop, halt, capture, passive, from:self, from:outside
remove undocumented dot modifiers (.prevent, .stop, .halt, .once, .self, .outside, .capture, .passive, .cc) from hx-on:event syntax
remove hx-trigger queue modifier from docs (no-op in 4.0)
update tests, docs, and extension references
Changes I've made on top:
reverted the triggerSpec -> eventSpec and onTrigger -> onEvent renames. I feel that the old trigger name is clearer here and more understood. these specs and handling can be non event based like load, intersect etc and can have modifiers in how they trigger over just a pure event based action so I think Trigger is still the right name for them both.
improved the JS handling and splitting of the triggerSpec -> code using a simple regex. with -> as the new seperator it does not conflict with JS syntax and we can use the ; at the end to identify chained triggerSpec's cleanly now.
Simplified the onTrigger() function to use less deeply nested chained callbacks. Found that the reworked hx-on . modifiers had a simpler handler design and we can reuse this in onTrigger to cut out much of the code complexity and just leave the things like delay etc that have to stay as handler wrappers.
Also added in rootMargin support to the IntersectionObserver which is only one line to add now which is easy. #1349 #2593 #3802