-
-
Notifications
You must be signed in to change notification settings - Fork 175
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
data-reflex-dataset and data-reflex-dataset-all #478
Conversation
Nice, I love the idea to extend But I'm a little bit concerned about allowing raw XPath expressions (like I know that not every XPath is that long, but this feels like an anti-pattern to me and will probably lead to unexpected behavior/hard to maintain code if you change your markup 😅 Maybe just providing simple IDs and classes would work better? data-reflex-dataset="siblings parent #myinput .checkboxes" Maybe the classes could be serialized to an array/object. Just thinking out loud. |
That's a good point, Marco. I'd be perfectly happy letting |
add jsdom-global to devDependencies and configure mocha to run with it
…13) * add tests for new data-reflex-dataset features * collect and stack overlapping data values in plural key if multiple elements have the `data-post-id` attribute it will put the first occurance in the `data-post-id` key. The first and all the other remaing values of the attribtue will be stacked in a `data-post-ids` array. * handle edge case if the plural key is already used * standardize * extract data attributes stacking to `data-reflex-dataset-array` This is to ensure that you always get an array even if there is just on occurence of an attribute
I'm seeing some interesting results when I interrogate a Reflex element with pry: <button class="btn btn-dark" type="button" data-reflex="click->Example#meta" data-reflex-dataset=".post"><span class="fas fa-angry me-2"></span>69</button>
<div class="post" data-post-id="1"></div> Then, in the binding:
The good news is that
It is working, which is good. 👍 |
This is happening here: https://github.com/hopsoft/stimulus_reflex/blob/master/lib/stimulus_reflex/element.rb#L10 |
* split up dataset and datasetArray in payload so we can move the pluralization to the server * move pluralize logic to `StimulusReflex::Element` * move alias_method * extract transform underscore logic in helper method
I like this a lot and propose that we use <div data-reflex-dataset-list=".post">
<div class="post" data-post-id="1"></div>
<div class="post" data-post-id="2"></div>
<div class="post" data-post-id="3"></div>
<div class="post" data-post-id="4"></div>
</div> The server will receive: {
'data-reflex-dataset-lists': ['.post'],
'data-post-ids': [
'1',
'2',
'3',
'4'
]
} |
I'll let you and @marcoroth duke this one out. 🤠 |
@hopsoft I guess |
I was thinking in terms of Would love to hear other opinions on this. |
Type of PR (feature, enhancement, bug fix, etc.)
Enhancement
Description
@joshleblanc gave me the idea to expand what could be passed to a
data-reflex-dataset
attribute.What I've done in this PR is re-imagined the
extractElementDataset
function as a power tool for grabbing attributes from relative elements.combined
has been deprecated in favour ofancestors
.The deprecation itself is commented until #438 is merged.data-reflex-dataset
anddata-reflex-dataset-all
support one or multiple space-separated tokens. egTokens can be keywords or CSS queries. They are evaluated in the order that they are included.
Currently proposed and supported keywords are:
data-reflex-dataset
Current (3.4.1) behaviour of grabbing and holding the first unique value for a given key is maintained:
The server will receive:
data-reflex-dataset-all
This introduces a 2nd form which enables the scooping of a group of matching elements:
The server will receive:
Since the data-post-id always contains the first occurring value (like it was before) it's fully backwards compatible, because just the data-post-ids is added additionally.
You can of course also mix-and-match the two attributes.
Let's try both!
The server will receive:
Smart pluralization
We don't need no
postss
:The server will receive:
And thanks to @marcoroth's dark magic, we now have full support for
ActiveSupport::Inflector
:Wait, did this really just produce a list of all of the checked values? Why, yes it did.
Honestly, it's pretty great
Why should this be added
Power and flexibility.
Thanks to @marcoroth there is ~500LOC worth of tests for the new features of the
data-reflex-dataset
/data-reflex-dataset-all
attributes:Checklist