From c6675db07fd17518a9fe5c46266026745ba40b4a Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Thu, 9 Jan 2020 15:18:54 -0800 Subject: [PATCH] `legacyNoObservedAttributes`: Ensure user created runs before attributesChanged --- lib/legacy/legacy-element-mixin.js | 19 +++++++++---------- test/unit/legacy-noattributes.html | 8 ++++++++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/legacy/legacy-element-mixin.js b/lib/legacy/legacy-element-mixin.js index a6c0575c3a..76c0682dcb 100644 --- a/lib/legacy/legacy-element-mixin.js +++ b/lib/legacy/legacy-element-mixin.js @@ -122,16 +122,7 @@ export const LegacyElementMixin = dedupingMixin((base) => { * @override * @return {void} */ - created() { - // Pull all attribute values 1x if `legacyNoObservedAttributes` is set. - if (legacyNoObservedAttributes && this.hasAttributes()) { - const a = this.attributes; - for (let i=0, l=a.length; i < l; i++) { - const attr = a[i]; - this.__attributeReaction(attr.name, null, attr.value); - } - } - } + created() {} /** * Processes an attribute reaction when the `legacyNoObservedAttributes` @@ -310,6 +301,14 @@ export const LegacyElementMixin = dedupingMixin((base) => { super._initializeProperties(); this.root = /** @type {HTMLElement} */(this); this.created(); + // Pull all attribute values 1x if `legacyNoObservedAttributes` is set. + if (legacyNoObservedAttributes && this.hasAttributes()) { + const a = this.attributes; + for (let i=0, l=a.length; i < l; i++) { + const attr = a[i]; + this.__attributeReaction(attr.name, null, attr.value); + } + } // Ensure listeners are applied immediately so that they are // added before declarative event listeners. This allows an element to // decorate itself via an event prior to any declarative listeners diff --git a/test/unit/legacy-noattributes.html b/test/unit/legacy-noattributes.html index 1e25a99570..91b45662f3 100644 --- a/test/unit/legacy-noattributes.html +++ b/test/unit/legacy-noattributes.html @@ -66,7 +66,11 @@ camelCase: String, disabled: {type: Boolean, value: 'true'} }, + created() { + this.wasCreated = true; + }, attributeChanged(name, old, value) { + this.wasCreatedInAttributeChanged = this.wasCreated; this.attrInfo = {name, old, value}; } }); @@ -104,6 +108,10 @@ assert.equal(el.camelCase, 'camelCase'); }); + test('created called before attributeChanged', () => { + assert.isTrue(el.wasCreatedInAttributeChanged); + }); + test('attributeChanged gets expected arguments', () => { el = fixture('one-attr'); assert.deepEqual(el.attrInfo, {name: 'foo', old: null, value: 'foo'});