diff --git a/lib/legacy/legacy-element-mixin.html b/lib/legacy/legacy-element-mixin.html
index afeb8bf017..59514e4993 100644
--- a/lib/legacy/legacy-element-mixin.html
+++ b/lib/legacy/legacy-element-mixin.html
@@ -80,11 +80,6 @@
this.__boundListeners;
/** @type {Object} */
this._debouncers;
- // 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
- // seeing the event. Note, this ensures compatibility with 1.x ordering.
- this._applyListeners();
}
/**
@@ -99,6 +94,11 @@
return this.prototype.importMeta;
}
+ static _finalizeClass() {
+ this.prototype._registered();
+ super._finalizeClass();
+ }
+
/**
* Legacy callback called during the `constructor`, for overriding
* by the user.
@@ -181,14 +181,14 @@
* @suppress {invalidCasts}
*/
_initializeProperties() {
- let proto = Object.getPrototypeOf(this);
- if (!proto.hasOwnProperty('__hasRegisterFinished')) {
- proto.__hasRegisterFinished = true;
- this._registered();
- }
super._initializeProperties();
this.root = /** @type {HTMLElement} */(this);
this.created();
+ // 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
+ // seeing the event. Note, this ensures compatibility with 1.x ordering.
+ this._applyListeners();
}
/**
diff --git a/test/unit/disable-upgrade.html b/test/unit/disable-upgrade.html
index f5ad09dd49..b002336ffc 100644
--- a/test/unit/disable-upgrade.html
+++ b/test/unit/disable-upgrade.html
@@ -89,13 +89,17 @@ [[prop]]
type: String
}
},
+ listeners: {
+ foo: 'fooHandler'
+ },
created() {
this.hasCreated = true;
this.prop = 'enabled!';
},
ready() {
this.enabled = true;
- }
+ },
+ fooHandler: function() {}
});
Polymer({
@@ -238,30 +242,39 @@ [[prop]]
assert.ok(el.$.enabledEl.enabled);
assert.ok(el.$.enabledEl.$.element);
assert.equal(el.$.enabledEl.$.element.textContent, 'enabled!');
+ el.$.enabledEl.fooHandler = sinon.spy();
+ el.$.enabledEl.fire('foo');
+ assert.equal(el.$.enabledEl.fooHandler.callCount, 1);
assert.notOk(el.$.disabledEl.hasCreated);
assert.notOk(el.$.disabledEl.enabled);
assert.notOk(el.$.disabledEl.$);
+ el.$.disabledEl.fooHandler = sinon.spy();
+ el.$.disabledEl.fire('foo');
+ assert.equal(el.$.disabledEl.fooHandler.callCount, 0);
assert.notOk(el.$.disabledBoundEl.hasCreated);
assert.notOk(el.$.disabledBoundEl.enabled);
assert.notOk(el.$.disabledBoundEl.$);
+ el.$.disabledBoundEl.fooHandler = sinon.spy();
+ el.$.disabledBoundEl.fire('foo');
+ assert.equal(el.$.disabledBoundEl.fooHandler.callCount, 0);
});
test('elements upgrade when `disable-upgrade` removed', function() {
- assert.notOk(el.$.disabledEl.hasCreated);
- assert.notOk(el.$.disabledEl.enabled);
- assert.notOk(el.$.disabledEl.$);
- assert.notOk(el.$.disabledBoundEl.hasCreated);
- assert.notOk(el.$.disabledBoundEl.enabled);
- assert.notOk(el.$.disabledBoundEl.$);
el.enable();
assert.ok(el.$.disabledEl.hasCreated);
assert.ok(el.$.disabledEl.enabled);
assert.ok(el.$.disabledEl.$.element);
assert.equal(el.$.disabledEl.$.element.textContent, 'enabled!');
+ el.$.disabledEl.fooHandler = sinon.spy();
+ el.$.disabledEl.fire('foo');
+ assert.equal(el.$.disabledEl.fooHandler.callCount, 1);
assert.ok(el.$.disabledBoundEl.hasCreated);
assert.ok(el.$.disabledBoundEl.enabled);
assert.ok(el.$.disabledBoundEl.$.element);
assert.equal(el.$.disabledBoundEl.$.element.textContent, 'enabled!');
+ el.$.disabledBoundEl.fooHandler = sinon.spy();
+ el.$.disabledBoundEl.fire('foo');
+ assert.equal(el.$.disabledBoundEl.fooHandler.callCount, 1);
});