Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure properties is only invoked once #5261

Merged
merged 3 commits into from
Aug 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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