-
-
Notifications
You must be signed in to change notification settings - Fork 174
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
Introduce StimulusReflex Targets #490
base: main
Are you sure you want to change the base?
Conversation
After playing with a working version of this and taking it for a bit of a test drive, I had a few notes and bits of feedback regarding the open questions in the description. Restricting named targets to the controller elementIn the case where there's a custom Stimulus controller on a whole section of the page (maybe a form for example) and it has multiple child elements and calls But in the simpler case of a stand-alone element (like a button with It really feels like it should be at least possible to use named targets that are anywhere on the current page. Named targets anywhere on the pageIf named targets can be anywhere on the page and aren't restricted to being children of My thoughts around these questions are coalescing towards the idea that the ability to control whether or not this additional data gets added and what the scope of it should be really wants to be represented by an optional parameter of some kind. Roughly what I'm leaning towards is: by default the additional data about named target elements does not get included. Optionally; data for only the named targets that are children of <span data-reflex-target="whatever"> Target Me! </span>
<button data-reflex="click->Example#action_one"> Not using targets </button>
<button data-reflex="click->Example#action_two" data-include-targets="page"> Targetting! </button>
<form data-controller="stimulating" data-include-targets="controller" data-action="submit->stimulating#submit">
<input data-reflex-target="launchcodes" type="text" />
<button data-reflex-target="bigredbutton" class="big red"> Boom! </button>
</from> Support for multiple targets with the same nameThis feels like it would be amazing, but it'll need some changes to how the targets are put together and what the interface for accessing them looks like. Also... there are some interesting questions about calling chainable operations directly on a collection of targets. I had a quick look and I'm pretty sure that all operations that could feasibly be called on an element have the optional Edit: it works 🎉 👉 Matt-Yorkley@428ac77 A side note on simplicityAn interesting part of this change is that by removing the need to specify the button_target.remove And that translates to a valid There's a lot of scenarios where the reduction in the total volume of code required to achieve things and the overall increase in the clarity and simplicity of that code is absolutely wild. |
Type of PR
Feature
Description
This PR is part of a bigger story. This work is based on #478 and #489.
With this PR we allow to declare DOM nodes as StimulusReflex targets so you are able to access and operate on them with CableRady operations in your reflexes.
Here is an example:
Why should this be added
Targets are well known to Stimulus developers. This PR applies the same target-concept to reflexes. This, in combination with #489, enables a whole new world on how you write your CableReady operations while writing clean, super understandable and easy-to-look-at code.
Open Points
[data-reflex-target]
inside of the controller elementfolders.input
to declare a target. Should we just allowinput
?input_target
returns the first targetinput_targets
would return an array of all targets so you can loop over themChecklist