-
Notifications
You must be signed in to change notification settings - Fork 424
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
Feature request - Ability to access controller
or event.params
in the registerActionOption
function
#668
Comments
I would more than happy to put up a PR for this feature (one or both approaches) if this is considered useful. |
I think this addition makes sense 👍🏼 Personally I'd probably want to use the I wouldn't be opposed to see a PR for this, either for one or both approaches. |
Awesome, I'll give it a go. |
- Add ability for registerActionOption callbacks to receive the controller instance - Relates to hotwired#668
- Add ability for registerActionOption callbacks to receive the event after `params` have been resolved - Relates to hotwired#668
PRs are up |
- Add ability for registerActionOption callbacks to receive the event after `params` have been resolved - Relates to hotwired#668
- Add ability for registerActionOption callbacks to receive the controller instance - Relates to hotwired#668
- Add ability for registerActionOption callbacks to receive the controller instance - Relates to hotwired#668
The latest version of Stimulus brought in a powerful way to add custom event listener (action) options.
It would be amazing if the action option function allowed for access to the event.params on the element's action or alternatively the controller instance. Maybe even both of these.
Example usage - current state
For the sake of this example, we want to create a debounce action option that will block events for X ms (default 250) and allows for this value being changed per element. However, there is no easy way to make this value different for actions on the same element.
Example usage -
event.params
If we had access to the event params (as we do in the method call), this could become easier. We could read
event.params
and we also get smart value parsing (e.g. string to Number) for 'free'.Example usage - passing
controller
Another approach could be to pass the controller instance to the function, either as
this
or as an explicit param.Implementation
The simplest code change would likely be passing the
controller
viathis
or via an argument to the callback but this does feel a bit like the action option has too much power.It will be a slightly more complex change but still doable to move the addition of the params on the
event
to a new method that can be called inapplyEventModifiers
instead ofinvokeWithEvent
. This does feel like it gives a new level of access to the action option without really changing the way to reason about these handlers too much.stimulus/src/core/binding.ts
Line 59 in 8a614c5
The text was updated successfully, but these errors were encountered: