Closed Pajn closed 9 years ago
There is a problem with booleans. When attribute doesn't have any value, it will have default value, and default value can be false
, true
, or something else, so we can't just ignore false
values when rendering, and remove them in diff/patch.
The boolean attribute should only be used on HTML attributes that are actually boolean see https://html.spec.whatwg.org/multipage/infrastructure.html#boolean-attributes, for them an empty value (or a value of the name of the attribute) means true and omitting them completely is the only way to say false.
Yes, it makes sense.
updateAttrs should be also modified to support nums and booleans.
Maybe create a helper function _setAttr(NamedNodeMap attrs, String key, value)
and use it everywhere.
Yes, I will fix that.
Now updateAttrs is fixed. I had to change your addAll call to a loop so that every value got converted. Unfortunately I don't know if that has performance implications and hadn't the time I needed to figure out how to run your benchmark against it.
I think that this api change is more important than any perf implications, we have a good perf budget to improve api.
Add support for numeric or boolean values in attrs.
Use cases
boolean
input[type="checkbox"]
is checked if there is a checked attribute, no matter the value. Currently one need a bit of boilerplate to handle checkboxes, supporting a boolean value directly is much nicer.numeric
When working with SVG I use a lot of calculations to set x, y and similar attributes, having to call
.toString()
isn't quite as bad as the checkbox but it would still be nice with support for numbers.