Skip to content

Commit 152f896

Browse files
author
Steven Orvell
committed
Improve docs and add test for case conversion.
1 parent dcdb750 commit 152f896

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

lib/elements/basic-element.html

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,15 @@
4040
}
4141
}
4242

43+
/**
44+
* Implements standard custom elements getter to observes the attributes
45+
* listed in `properties`. These are camel to dash cased.
46+
*/
4347
static get observedAttributes() {
4448
const props = this.properties;
45-
return props ? Object.keys(props) : [];
49+
return props ? Object.keys(props).map(p => {
50+
return this.prototype._attributeNameForProperty(p);
51+
}) : [];
4652
}
4753

4854
/**
@@ -60,14 +66,21 @@
6066
}
6167

6268
/**
63-
* Overrides default behavior and adds a call to `finalize`.
69+
* Overrides default behavior and adds a call to `finalize` which lazily
70+
* configures the element's property accessors.
6471
* @override
6572
*/
6673
_initializeProperties() {
6774
this.constructor._ensureFinalized(this.localName);
6875
super._initializeProperties();
6976
}
7077

78+
/**
79+
* Overrides default behavior to use `type` information stored in the
80+
* static `properties` object. This allows attributes to be converted to
81+
* the coressponding type given in `properties`. Atributes are dash to
82+
* camel cased.
83+
*/
7184
_attributeToProperty(attribute, value, type) {
7285
if (!type) {
7386
const property = this._propertyNameForAttribute(attribute);
@@ -78,6 +91,11 @@
7891
super._attributeToProperty(attribute, value, type);
7992
}
8093

94+
/**
95+
* Called when the element is added to a document.
96+
* Calls `_enableProperties` to turn on property system from
97+
* `PropertyAccessors`.
98+
*/
8199
connectedCallback() {
82100
this._enableProperties();
83101
}

test/unit/polymer.basic-element.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@
149149

150150
static get properties() {
151151
return Object.assign({
152-
prop3: String
152+
prop3: String,
153+
camelCase: String
153154
}, super.properties);
154155
}
155156

@@ -195,7 +196,7 @@
195196

196197
<test-fixture id="sub-mixin-element-attr">
197198
<template>
198-
<sub-mixin-element prop="attr" prop2="attr" prop3="attr" mixin="5"></sub-mixin-element>
199+
<sub-mixin-element prop="attr" prop2="attr" prop3="attr" mixin="5" camel-case="camelCase"></sub-mixin-element>
199200
</template>
200201
</test-fixture>
201202

@@ -343,12 +344,12 @@
343344
assert.equal(fixtureEl.prop, 'attr');
344345
assert.equal(fixtureEl.prop2, 'attr');
345346
assert.equal(fixtureEl.prop3, 'attr');
347+
assert.equal(fixtureEl.camelCase, 'camelCase');
346348
assert.equal(fixtureEl.mixin, 5);
347-
assert.equal(fixtureEl._callAttributeChangedCallback, 4);
349+
assert.equal(fixtureEl._callAttributeChangedCallback, 5);
348350
assert.isTrue(fixtureEl.hasAttribute('tabindex'));
349351
assert.equal(fixtureEl.getAttribute('role'), 'button');
350352
assert.equal(fixtureEl.getAttribute('mixinattr'), 'mixinattr');
351-
assert.equal(fixtureEl.getAttribute('submixinattr'), 'submixinattr');
352353
});
353354

354355
});

0 commit comments

Comments
 (0)