Skip to content

Commit

Permalink
Fix issue with camel cased properties and disable-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
dfreedm committed Aug 9, 2019
1 parent 04ddc24 commit f95fd32
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/mixins/properties-changed.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,12 @@ export const PropertiesChanged = dedupingMixin(
if (!this.hasOwnProperty('__dataAttributes')) {
this.__dataAttributes = Object.assign({}, this.__dataAttributes);
}
if (!this.__dataAttributes[property]) {
const attr = this.constructor.attributeNameForProperty(property);
let attr = this.__dataAttributes[property];
if (!attr) {
attr = this.constructor.attributeNameForProperty(property);
this.__dataAttributes[attr] = property;
}
return attr;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/mixins/properties-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const PropertiesMixin = dedupingMixin(superClass => {
if (!this.hasOwnProperty('__observedAttributes')) {
register(this.prototype);
const props = this._properties;
this.__observedAttributes = props ? Object.keys(props).map(p => this.attributeNameForProperty(p)) : [];
this.__observedAttributes = props ? Object.keys(props).map(p => this.prototype._addPropertyToAttributeMap(p)) : [];
}
return this.__observedAttributes;
}
Expand Down
27 changes: 27 additions & 0 deletions test/unit/disable-upgrade.html
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,25 @@ <h2 id="element">[[prop]]</h2>
</script>
</dom-module>

<script type="module">
import { Polymer } from '../../lib/legacy/polymer-fn.js';
Polymer({
is: 'x-disabled-camel',
properties: {
camelCaseProperty: Boolean,
bootedCorrectly: {
type: Boolean,
value: false
}
},
attached() {
if (this.camelCaseProperty) {
this.bootedCorrectly = true;
}
}
});
</script>

<script type="module">
import '../../lib/mixins/disable-upgrade-mixin.js';
import {flush} from '../../lib/utils/flush.js';
Expand Down Expand Up @@ -433,6 +452,14 @@ <h2 id="element">[[prop]]</h2>
assert.ok(el.$.disabledBoundEl.wasDisconnected);
});

test('elements with camelCase properties initialize correctly after being enabled', function() {
const div = document.createElement('div');
div.innerHTML = `<x-disabled-camel disable-upgrade camel-case-property></x-disabled-camel>`;
const camel = div.querySelector('x-disabled-camel');
document.body.appendChild(div);
camel.removeAttribute('disable-upgrade');
assert.ok(camel.bootedCorrectly);
});

});

Expand Down

0 comments on commit f95fd32

Please sign in to comment.