Skip to content

Commit

Permalink
legacyNoObservedAttributes: Ensure user created runs before attribu…
Browse files Browse the repository at this point in the history
…tesChanged
  • Loading branch information
Steven Orvell committed Jan 9, 2020
1 parent b8315d6 commit c6675db
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
19 changes: 9 additions & 10 deletions lib/legacy/legacy-element-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/unit/legacy-noattributes.html
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
});
Expand Down Expand Up @@ -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'});
Expand Down

0 comments on commit c6675db

Please sign in to comment.