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] 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() {