Skip to content

Commit c6675db

Browse files
author
Steven Orvell
committed
legacyNoObservedAttributes: Ensure user created runs before attributesChanged
1 parent b8315d6 commit c6675db

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

lib/legacy/legacy-element-mixin.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,7 @@ export const LegacyElementMixin = dedupingMixin((base) => {
122122
* @override
123123
* @return {void}
124124
*/
125-
created() {
126-
// Pull all attribute values 1x if `legacyNoObservedAttributes` is set.
127-
if (legacyNoObservedAttributes && this.hasAttributes()) {
128-
const a = this.attributes;
129-
for (let i=0, l=a.length; i < l; i++) {
130-
const attr = a[i];
131-
this.__attributeReaction(attr.name, null, attr.value);
132-
}
133-
}
134-
}
125+
created() {}
135126

136127
/**
137128
* Processes an attribute reaction when the `legacyNoObservedAttributes`
@@ -310,6 +301,14 @@ export const LegacyElementMixin = dedupingMixin((base) => {
310301
super._initializeProperties();
311302
this.root = /** @type {HTMLElement} */(this);
312303
this.created();
304+
// Pull all attribute values 1x if `legacyNoObservedAttributes` is set.
305+
if (legacyNoObservedAttributes && this.hasAttributes()) {
306+
const a = this.attributes;
307+
for (let i=0, l=a.length; i < l; i++) {
308+
const attr = a[i];
309+
this.__attributeReaction(attr.name, null, attr.value);
310+
}
311+
}
313312
// Ensure listeners are applied immediately so that they are
314313
// added before declarative event listeners. This allows an element to
315314
// decorate itself via an event prior to any declarative listeners

test/unit/legacy-noattributes.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@
6666
camelCase: String,
6767
disabled: {type: Boolean, value: 'true'}
6868
},
69+
created() {
70+
this.wasCreated = true;
71+
},
6972
attributeChanged(name, old, value) {
73+
this.wasCreatedInAttributeChanged = this.wasCreated;
7074
this.attrInfo = {name, old, value};
7175
}
7276
});
@@ -104,6 +108,10 @@
104108
assert.equal(el.camelCase, 'camelCase');
105109
});
106110

111+
test('created called before attributeChanged', () => {
112+
assert.isTrue(el.wasCreatedInAttributeChanged);
113+
});
114+
107115
test('attributeChanged gets expected arguments', () => {
108116
el = fixture('one-attr');
109117
assert.deepEqual(el.attrInfo, {name: 'foo', old: null, value: 'foo'});

0 commit comments

Comments
 (0)