feat: Add optional value to event options#895
Open
tchiadeu wants to merge 2 commits into
Open
Conversation
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.
Allow action options to capture a string value with
:name(value)Summary
Action options currently only express booleans:
:nameyields true and:!nameyields false. This PR adds a parenthesized syntax,:name(value), that captures a string value and passes it to the option'sregisterActionOptionscallback. This makes options parameterizable (e.g. a throttle delay) without having to smuggle the value through a separate data attribute.Motivation
Custom action options are a natural place to configure event handling behavior, but the boolean-only value made it impossible to express something like "throttle to 500ms" inline in the descriptor. Users had to fall back to reading a data attribute inside the callback.
Usage
Captured values are always strings, so convert them as needed (e.g.
Number(value)).What changed
parseEventOptions(src/core/action_descriptor.ts) now detects aname(value)token via regex and assigns the captured string; tokens without parentheses keep the existing boolean behavior (name→true,!name→false).ActionDescriptorFilterOptions.valuefrombooleantoboolean | string.docs/reference/actions.md.Backward compatibility
Fully backward compatible. Boolean options are unchanged; only the new parenthesized form produces a string. Unknown string options are ignored by
addEventListenerjust like unknown boolean options.Tests
Added
event_options_tests.tscoverage for: a parenthesized value reaching the callback as a string, a string value mixed with a boolean option in the same descriptor, and a value driving whether the action runs.