From 291e4f56ab8552c4d7f07eda734d2a3f1d739716 Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Sat, 27 Jan 2018 20:23:07 +0100 Subject: [PATCH 1/3] Fix issue with observers being called twice --- lib/mixins/properties-mixin.html | 13 ++++++++---- test/unit/property-effects-elements.html | 25 +++++++++++++++++++++++- test/unit/property-effects.html | 10 ++++++++++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/lib/mixins/properties-mixin.html b/lib/mixins/properties-mixin.html index 114ea1427a..287b15d122 100644 --- a/lib/mixins/properties-mixin.html +++ b/lib/mixins/properties-mixin.html @@ -70,6 +70,7 @@ */ function superPropertiesClass(constructor) { const superCtor = Object.getPrototypeOf(constructor); + // Note, the `PropertiesMixin` class below only refers to the class // generated by this call to the mixin; the instanceof test only works // because the mixin is deduped and guaranteed only to apply once, hence @@ -87,10 +88,14 @@ * @return {Object} Memoized properties object */ function ownProperties(constructor) { - if (!constructor.hasOwnProperty( - JSCompiler_renameProperty('__ownProperties', constructor))) { - const props = constructor.properties; - constructor.__ownProperties = props ? normalizeProperties(props) : null; + if (!constructor.hasOwnProperty(JSCompiler_renameProperty('__ownProperties', constructor))) { + let props = null; + + if (constructor.hasOwnProperty('properties') && constructor.properties) { + props = normalizeProperties(constructor.properties); + } + + constructor.__ownProperties = props; } return constructor.__ownProperties; } diff --git a/test/unit/property-effects-elements.html b/test/unit/property-effects-elements.html index 1a52caf3c7..ae2cb8f4c8 100644 --- a/test/unit/property-effects-elements.html +++ b/test/unit/property-effects-elements.html @@ -1038,4 +1038,27 @@ this.xChanged = sinon.spy(); } }); - \ No newline at end of file + + + diff --git a/test/unit/property-effects.html b/test/unit/property-effects.html index 3e18d333af..2a7581fbb5 100644 --- a/test/unit/property-effects.html +++ b/test/unit/property-effects.html @@ -409,6 +409,16 @@ } }); + suite('observer inheritance', function() { + setup(function() { + el = document.createElement('sub-observer-element'); + document.body.appendChild(el); + }); + + test('does not invoke observer twice', function() { + assert.equal(el.__observerCalled, 1); + }); + }); }); suite('computed bindings with dynamic functions', function() { From 5e0bee77af237ee5705c8d3af4f5fc53435100fd Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Sat, 27 Jan 2018 20:26:47 +0100 Subject: [PATCH 2/3] Fix linter errors --- test/unit/property-effects-elements.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/property-effects-elements.html b/test/unit/property-effects-elements.html index ae2cb8f4c8..aeeee70e43 100644 --- a/test/unit/property-effects-elements.html +++ b/test/unit/property-effects-elements.html @@ -1047,11 +1047,11 @@ return { prop: { value: 'String', - observer(value, oldValue) { + observer() { this.__observerCalled++; } } - } + }; } } SuperObserverElement.prototype.__observerCalled = 0; From 74a4626ade0ef65ee98d42c2c35ea4a236bea68a Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Tue, 30 Jan 2018 11:30:11 +0100 Subject: [PATCH 3/3] Invoke JS compiler rename for properties --- lib/mixins/properties-mixin.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mixins/properties-mixin.html b/lib/mixins/properties-mixin.html index 287b15d122..782311bb8e 100644 --- a/lib/mixins/properties-mixin.html +++ b/lib/mixins/properties-mixin.html @@ -91,7 +91,7 @@ if (!constructor.hasOwnProperty(JSCompiler_renameProperty('__ownProperties', constructor))) { let props = null; - if (constructor.hasOwnProperty('properties') && constructor.properties) { + if (constructor.hasOwnProperty(JSCompiler_renameProperty('properties', constructor)) && constructor.properties) { props = normalizeProperties(constructor.properties); }