Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Issue 836923002: Automate reflected properties in SkyElement. (Closed)

Created:
5 years, 11 months ago by esprehn
Modified:
5 years, 11 months ago
Reviewers:
abarth-chromium, ojan
CC:
ojan, eseidel, mojo-reviews_chromium.org, rafaelw
Base URL:
git@github.com:domokit/mojo.git@master
Target Ref:
refs/heads/master
Project:
mojo
Visibility:
Public.

Description

Automate reflected properties in SkyElement. Now you can use the attributes attribute on <sky-element> that accepts a set of name:type comma separated pairs to control the reflected attributes. ex. attributes="size:number" Each attribute creates a getter and a setter on the element that returns the correct type and will coerce the string attribute values into the right type. It also correctly hooks into the data binding system. A new callback is added: {name}Changed(oldValue, newValue) which will be invoked whenever the attribute with that name changes and gets the correctly coerced type values. See the <sky-radio> or <sky-checkbox> widgets for examples of using the new callback. Number attributes default to 0, booleans to false, and strings to empty string. There is no way provided to set a different default, for that you can use hasAttribute in the created callback to conditionally set a value. Don't just assign the property there otherwise you'll overwrite the value from the parser. Another behavior change from making this work is that now attributeChanged() is called for each attribute, even when the element is created by the parser. Overall this allows a nice simplification to the <sky-button>, <sky-radio> and <sky-checkbox> widgets. R=abarth@chromium.org Committed: https://chromium.googlesource.com/external/mojo/+/a0235a16d45cfaca40274db73e84bcf6bd25c72d

Patch Set 1 #

Total comments: 8

Patch Set 2 : abarth review #

Patch Set 3 : single quotes. #

Patch Set 4 : moar single quotes #

Unified diffs Side-by-side diffs Delta from patch set Stats (+226 lines, -72 lines) Patch
M sky/framework/sky-button/sky-button.sky View 1 2 3 2 chunks +8 lines, -14 lines 0 comments Download
M sky/framework/sky-checkbox/sky-checkbox.sky View 1 2 3 3 chunks +9 lines, -25 lines 0 comments Download
M sky/framework/sky-element/sky-element.sky View 1 2 5 chunks +74 lines, -4 lines 0 comments Download
M sky/framework/sky-radio/sky-radio.sky View 1 2 3 3 chunks +19 lines, -19 lines 0 comments Download
M sky/tests/framework/templates.sky View 2 chunks +84 lines, -1 line 0 comments Download
M sky/tests/framework/templates-expected.txt View 1 chunk +14 lines, -8 lines 0 comments Download
M sky/tests/resources/test-element.sky View 3 chunks +18 lines, -1 line 0 comments Download

Messages

Total messages: 10 (2 generated)
esprehn
5 years, 11 months ago (2015-01-06 03:51:42 UTC) #2
abarth-chromium
LGTM https://codereview.chromium.org/836923002/diff/1/sky/framework/sky-element/sky-element.sky File sky/framework/sky-element/sky-element.sky (right): https://codereview.chromium.org/836923002/diff/1/sky/framework/sky-element/sky-element.sky#newcode28 sky/framework/sky-element/sky-element.sky:28: if (value == null) Why handle |null| special ...
5 years, 11 months ago (2015-01-06 04:02:38 UTC) #3
esprehn
https://codereview.chromium.org/836923002/diff/1/sky/framework/sky-element/sky-element.sky File sky/framework/sky-element/sky-element.sky (right): https://codereview.chromium.org/836923002/diff/1/sky/framework/sky-element/sky-element.sky#newcode28 sky/framework/sky-element/sky-element.sky:28: if (value == null) On 2015/01/06 at 04:02:38, abarth ...
5 years, 11 months ago (2015-01-06 04:10:24 UTC) #4
esprehn
Committed patchset #4 (id:60001) manually as a0235a16d45cfaca40274db73e84bcf6bd25c72d (presubmit successful).
5 years, 11 months ago (2015-01-06 04:13:02 UTC) #5
abarth-chromium
On 2015/01/06 at 04:10:24, esprehn wrote: > https://codereview.chromium.org/836923002/diff/1/sky/framework/sky-element/sky-element.sky > File sky/framework/sky-element/sky-element.sky (right): > > https://codereview.chromium.org/836923002/diff/1/sky/framework/sky-element/sky-element.sky#newcode28 ...
5 years, 11 months ago (2015-01-06 05:17:45 UTC) #6
esprehn
On 2015/01/06 at 05:17:45, abarth wrote: > On 2015/01/06 at 04:10:24, esprehn wrote: > > ...
5 years, 11 months ago (2015-01-06 05:27:51 UTC) #7
ojan
not lgtm. Why do we want reflected attributes? This is one of the things the ...
5 years, 11 months ago (2015-01-07 04:30:32 UTC) #9
esprehn
5 years, 11 months ago (2015-01-07 04:42:03 UTC) #10
Message was sent while issue was closed.
On 2015/01/07 at 04:30:32, ojan wrote:
> not lgtm.
> 
> Why do we want reflected attributes? This is one of the things the web got
wrong IMO. We should have properties and attributes and they should stay
separate. If we want an easy way to access attributes, we can add an attrs thing
off the element, so you can do this.attrs.highlight = true.
> 
> Blurring the line makes for confusing things like this.id and this.value that
we got rid of. You can never tell if something is an attribute or a property and
if setting it is going to be accidentally expensive.

We should just delete attribute selectors then, it doesn't make any sense to
have data duplicated in both properties and attributes, that just leads to bugs.

Powered by Google App Engine
This is Rietveld 408576698