Skip to content

Commit

Permalink
Fix subclassing and simplify.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed Nov 29, 2017
1 parent 603123e commit e09285d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 38 deletions.
41 changes: 6 additions & 35 deletions lib/mixins/properties-changed.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,6 @@
/** @const {!AsyncInterface} */
const microtask = Polymer.Async.microTask;

/**
* Returns the map matching attribute names to properties. This map is
* used in `propertyNameForAttribute` which locks property names and
* attribute names together using this data.
*
* @private
* @param {PropertiesChangedConstructor} constructor PropertiesChanged
* constructor
* @return {Object} Object mapping property names to attributes.
*/
function getAttributeToPropertyMap(constructor) {
return constructor.__attributeToPropertyMap;
}

/**
* Adds to the `attributeToPropertyMap` for the given class. A key for the
* attribute discovered via `attributeNameForProperty` points to the
* given property name. This map is used in `propertyNameForAttribute`.
*
* @private
* @param {PropertiesChangedConstructor} constructor PropertiesChanged
* constructor
* @param {string} property Property name.
*/
function addToAttributeToPropertyMap(constructor, property) {
if (!constructor.hasOwnProperty(JSCompiler_renameProperty(
'__attributeToPropertyMap', constructor))) {
constructor.__attributeToPropertyMap = {};
}
const attr = constructor.attributeNameForProperty(property);
constructor.__attributeToPropertyMap[attr] = property;
}

/**
* Element class mixin that provides basic meta-programming for creating one
* or more property accessors (getter/setter pair) that enqueue an async
Expand Down Expand Up @@ -112,7 +79,7 @@
* @protected
*/
static propertyNameForAttribute(attribute) {
const map = getAttributeToPropertyMap(this);
const map = this.prototype.__dataAttributes;
return map && map[attribute] || attribute;
}

Expand Down Expand Up @@ -157,9 +124,13 @@
if (!this.hasOwnProperty('__dataHasAccessor')) {
this.__dataHasAccessor = Object.assign({}, this.__dataHasAccessor);
}
if (!this.hasOwnProperty('__dataAttributes')) {
this.__dataAttributes = Object.assign({}, this.__dataAttributes);
}
if (!this.__dataHasAccessor[property]) {
this.__dataHasAccessor[property] = true;
addToAttributeToPropertyMap(this.constructor, property);
const attr = this.constructor.attributeNameForProperty(property);
this.__dataAttributes[attr] = property;
this._definePropertyAccessor(property, readOnly);
}
}
Expand Down
9 changes: 6 additions & 3 deletions test/unit/polymer.properties-element.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@

static get properties() {
return {
prop2: String
prop2: String,
camelCase2: String
};
}

Expand Down Expand Up @@ -208,7 +209,7 @@

<test-fixture id="sub-element-attr">
<template>
<sub-element prop="attr" prop2="attr" custom-observed-attr="custom"></sub-element>
<sub-element prop="attr" prop2="attr" camelCase="camelCase" camelCase2="camelCase2" custom-observed-attr="custom"></sub-element>
</template>
</test-fixture>

Expand Down Expand Up @@ -326,7 +327,9 @@
var fixtureEl = fixture('sub-element-attr');
assert.equal(fixtureEl.prop, 'attr');
assert.equal(fixtureEl.prop2, 'attr');
assert.equal(fixtureEl._callAttributeChangedCallback, 3);
assert.equal(fixtureEl.camelCase, 'camelCase');
assert.equal(fixtureEl.camelCase2, 'camelCase2');
assert.equal(fixtureEl._callAttributeChangedCallback, 5);
});

});
Expand Down

0 comments on commit e09285d

Please sign in to comment.