corset icon indicating copy to clipboard operation
corset copied to clipboard

[request/suggestion] data-corset-props attr instead of many data-corset-prop-* attrs

Open JaneOri opened this issue 2 years ago • 4 comments

Assuming the data-corset-prop-* attrs are there individually just for an internal query selector and not a deeper need, would you consider changing it to be all contained in one data-corset-props and use the ~= attr selector instead like [data-corset-props~=--corset-prop]

Current: image

Proposed: image

Ty! 💜

JaneOri avatar Jul 31 '22 19:07 JaneOri

Oh, I like this idea a lot! Yeah, it just exists to do el.closest(selector) to find the nearest ancestor with the prop. I think your idea could work, and would be nicer to look at and likely even fix #155 since we have to try and make the vars be valid attribute names.

I would want to add a benchmark first (something that's needed anyways). This is a part of the code that runs fairly frequently and I'm not sure what the perf of =~ is. But assuming it's acceptable, I like this change a lot.

matthewp avatar Aug 01 '22 11:08 matthewp

I'm prototyping this.

matthewp avatar Aug 05 '22 11:08 matthewp

I worked on this and couldn't see a perf difference so I'm going to implement it.

Since stores and item/index use a lot of the same code I'm going to need to refactor them to use this sort of method as well. It will probably be something like data-corset-props, data-corset-stores and data-corset-scope to represent each of these concepts, so a max of 3 corset attributes on an element if you happen to use all of these features on the same element.

matthewp avatar Aug 19 '22 14:08 matthewp

awesome, thank you so much

Corset is awesome, really enjoy using it

JaneOri avatar Aug 19 '22 18:08 JaneOri

Released in https://github.com/matthewp/corset/releases/tag/v2.1.0

matthewp avatar Aug 28 '22 12:08 matthewp