Rationale behind bool in attrs #13
-
Why you treat bool in attributes as strings, instead of simply switching on/off the attribute? While of course you can do .attribute for certain things, that doesn´t solve the above issue and also doesn´t work in SVG (.hidden does nothing in SVG. You have to actually switch the attribute). I know that changing that behavior now would be a breaking change, but could that be implemented in a major version release? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 15 replies
-
it's already implemented in both hyperHTML and lighterhtml, and it's ambiguous for the following reasons:
but ... did I say lighterhtml already does these magic tricks for you behind the scene? that's the beauty of having choices: whatever you've done with uhtml will also work in lighterhtml, plus the extra magic you are looking for 👋 |
Beta Was this translation helpful? Give feedback.
-
To whom it might concern, we just had an issue with hyperHTML and custom elements, because if an element has an accessor, but it hasn't been defined yet in the registry, hyperHTML, as well as lighterhtml, won't be able to recognize such accessor, hence once the element gets updated, reaching the accessor will instead add or remove an attribute. This is the price you pay when too much magic is involved, so that the workaround to avoid surprises is to use specialized syntax in there too, because there's no way these declarative libraries can know upfront what an element is going to be, or how its properties will behave in the future. This is a golden opportunity to bring in I hope this extra detail, about a bug we're trying to solve in the real world, convinces skeptical developers even more on "why magic behavior based on value, instead of intent, can be a footgun". |
Beta Was this translation helpful? Give feedback.
it's already implemented in both hyperHTML and lighterhtml, and it's ambiguous for the following reasons:
null
orundefined
instead, or even empty strings, expected attributes to be removed or added same way (null
is an explicit intent to remove listeners as DOM Level 0, as example, whilefalse
is not even allowd in there).
prefix, is a 1:1 behavior of what you would do via JavaScript, if you had the node reference..contentEditable=${true | false}
is an example, and please note the camelCase, while.hidden
is another one, and the mistake there is to believe SVG elements have an.hidden
accessor…