localvoid / uix

[UNMAINTAINED] Dart Web UI library
BSD 2-Clause "Simplified" License
77 stars 4 forks source link

Add support for boolean and numeric values for attrs #11

Closed Pajn closed 9 years ago

Pajn commented 9 years ago

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.

localvoid commented 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.

Pajn commented 9 years ago

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.

localvoid commented 9 years ago

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.

Pajn commented 9 years ago

Yes, I will fix that.

Pajn commented 9 years ago

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.

localvoid commented 9 years ago

I think that this api change is more important than any perf implications, we have a good perf budget to improve api.