Skip to content

Commit

Permalink
Merge pull request #5261 from Polymer/double-properties-invocation
Browse files Browse the repository at this point in the history
Ensure properties is only invoked once
  • Loading branch information
Steve Orvell authored Aug 3, 2018
2 parents 6847cf4 + 9576bef commit 59405b5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 39 deletions.
8 changes: 6 additions & 2 deletions lib/mixins/properties-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ export const PropertiesMixin = dedupingMixin(superClass => {
if (!constructor.hasOwnProperty(JSCompiler_renameProperty('__ownProperties', constructor))) {
let props = null;

if (constructor.hasOwnProperty(JSCompiler_renameProperty('properties', constructor)) && constructor.properties) {
props = normalizeProperties(constructor.properties);
if (constructor.hasOwnProperty(JSCompiler_renameProperty('properties', constructor))) {
const properties = constructor.properties;

if (properties) {
props = normalizeProperties(properties);
}
}

constructor.__ownProperties = props;
Expand Down
61 changes: 24 additions & 37 deletions test/unit/polymer.properties-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,25 @@
<script type="module" src="../../lib/mixins/properties-mixin.js"></script>
<body>

<dom-module id="my-element">
<script type="module">
<test-fixture id="my-element-attr">
<template>
<my-element prop="attr" camelCase="camelCase"></my-element>
</template>
</test-fixture>

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

<test-fixture id="sub-mixin-element-attr">
<template>
<sub-mixin-element prop="attr" prop2="attr" prop3="attr" mixin="5" custom-observed-attr="custom"></sub-mixin-element>
</template>
</test-fixture>

<script type="module">
import { PropertiesMixin } from '../../lib/mixins/properties-mixin.js';

class Glar {}
Expand All @@ -27,6 +44,8 @@
class MyElement extends PropertiesMixin(HTMLElement) {

static get properties() {
this._calledProperties++;

return {
prop: String,
noStomp: String,
Expand Down Expand Up @@ -94,16 +113,11 @@
MyElement.prototype._calledReady = 0;
MyElement.prototype._callAttributeChangedCallback = 0;

MyElement.constructor.prototype._calledProperties = 0;

customElements.define('my-element', MyElement);

window.MyElement = MyElement;
</script>
</dom-module>


<dom-module id="sub-element">
<script type="module">
import '../../lib/mixins/properties-mixin.js';

class SubElement extends window.MyElement {

Expand Down Expand Up @@ -141,12 +155,6 @@
customElements.define('sub-element', SubElement);

window.SubElement = SubElement;
</script>
</dom-module>

<dom-module id="sub-mixin-element">
<script type="module">
import '../../lib/mixins/properties-mixin.js';

function MyMixin(Base) {
return class extends Base {
Expand Down Expand Up @@ -208,29 +216,7 @@
customElements.define('sub-mixin-element', SubMixinElement);

window.SubMixinElement = SubMixinElement;
</script>
</dom-module>

<test-fixture id="my-element-attr">
<template>
<my-element prop="attr" camelCase="camelCase"></my-element>
</template>
</test-fixture>

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

<test-fixture id="sub-mixin-element-attr">
<template>
<sub-mixin-element prop="attr" prop2="attr" prop3="attr" mixin="5" custom-observed-attr="custom"></sub-mixin-element>
</template>
</test-fixture>

<script type="module">
import '../../lib/mixins/properties-mixin.js';
suite('class extends Polymer.PropertiesMixin', function() {

let el;
Expand All @@ -254,6 +240,7 @@
assert.equal(el._calledConnectedCallback, 1);
assert.equal(el._calledReady, 1);
assert.equal(el._callAttributeChangedCallback, 0);
assert.equal(el.constructor._calledProperties, 1);
});

test('listeners', function() {
Expand Down

0 comments on commit 59405b5

Please sign in to comment.