From de09d73030cb474f02d4b978ba3f7607ff728378 Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Thu, 16 Mar 2017 17:44:38 +1100 Subject: [PATCH] =?UTF-8?q?Fixes=20#4437.=20Ensure=20`=5Fregistered`=20is?= =?UTF-8?q?=20called=201x=20for=20each=20element=20class=20using=20`Legacy?= =?UTF-8?q?ElementMixin`.=20Ensure=20that=20a=20behaviors=E2=80=99s=20`reg?= =?UTF-8?q?istered`=20method=20is=20called=20for=20any=20extending=20class?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/legacy/class.html | 12 +++--------- lib/legacy/legacy-element-mixin.html | 9 +++++++-- test/unit/mixin-behaviors.html | 24 ++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/lib/legacy/class.html b/lib/legacy/class.html index 2856cd773e..108e3d1f4f 100644 --- a/lib/legacy/class.html +++ b/lib/legacy/class.html @@ -131,8 +131,6 @@ function GenerateClassFromInfo(info, Base) { - let registered = false; - class PolymerGenerated extends Base { static get properties() { @@ -163,13 +161,9 @@ } _registered() { - if (!registered) { - super._registered(); - // call `registered` only if it was not called for *this* constructor - registered = true; - if (info.registered) { - info.registered.call(Object.getPrototypeOf(this)); - } + super._registered(); + if (info.registered) { + info.registered.call(Object.getPrototypeOf(this)); } } diff --git a/lib/legacy/legacy-element-mixin.html b/lib/legacy/legacy-element-mixin.html index 6272b1cecf..8f67b81ee2 100644 --- a/lib/legacy/legacy-element-mixin.html +++ b/lib/legacy/legacy-element-mixin.html @@ -105,12 +105,17 @@ /** * Overrides the default `Polymer.PropertyEffects` implementation to - * add support for one-time `registration` callback. + * add support for class initialization via the `_registered` callback. + * This is called only when the first instance of the element is created. * * @override */ _initializeProperties() { - this._registered(); + let proto = Object.getPrototypeOf(this); + if (!proto.hasOwnProperty('__hasRegisterFinished')) { + proto.__hasRegisterFinished = true; + this._registered(); + } super._initializeProperties(); } diff --git a/test/unit/mixin-behaviors.html b/test/unit/mixin-behaviors.html index e64ee2ae24..8bfd9dbfe1 100644 --- a/test/unit/mixin-behaviors.html +++ b/test/unit/mixin-behaviors.html @@ -329,12 +329,18 @@ BehaviorRegistered.prototype.registeredCount = 0; customElements.define(BehaviorRegistered.is, BehaviorRegistered); + + class BehaviorRegisteredExt extends BehaviorRegistered { + static get is() { return 'behavior-registered-ext'} + } + + BehaviorRegisteredExt.prototype.registeredCount = 0; + + customElements.define(BehaviorRegisteredExt.is, BehaviorRegisteredExt); }); - - + + + +