mirror of
https://github.com/Polymer/polymer.git
synced 2025-02-25 18:55:30 -06:00
Merge pull request #4438 from Polymer/fix-4437
Ensure `_registered` is called 1x for each element class using `LegacyElementMixin`
This commit is contained in:
commit
3d054bab66
@ -131,8 +131,6 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
|
||||
function GenerateClassFromInfo(info, Base) {
|
||||
|
||||
let registered = false;
|
||||
|
||||
class PolymerGenerated extends Base {
|
||||
|
||||
static get properties() {
|
||||
@ -163,13 +161,9 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
}
|
||||
|
||||
_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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,12 +105,17 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
|
@ -329,12 +329,18 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
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);
|
||||
});
|
||||
</script>
|
||||
</dom-module>
|
||||
|
||||
</script>
|
||||
|
||||
<test-fixture id="single">
|
||||
<template>
|
||||
<single-behavior></single-behavior>
|
||||
@ -364,6 +370,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
<behavior-registered></behavior-registered>
|
||||
</template>
|
||||
</test-fixture>
|
||||
|
||||
<test-fixture id="registered-ext">
|
||||
<template>
|
||||
<behavior-registered-ext></behavior-registered-ext>
|
||||
</template>
|
||||
</test-fixture>
|
||||
<script>
|
||||
|
||||
suite('single behavior element', function() {
|
||||
@ -421,6 +433,14 @@ suite('behavior.registered', function() {
|
||||
assert.deepEqual(el.registeredProps, [true, true, true]);
|
||||
});
|
||||
|
||||
test('extending element with behaviors with registered properly registers', function() {
|
||||
var el = fixture('registered-ext');
|
||||
assert.equal(el.registeredCount, 4);
|
||||
assert.equal(el.registeredBehaviors.length, 3);
|
||||
assert.equal(el.registeredBehaviors, el.behaviors);
|
||||
assert.deepEqual(el.registeredProps, [true, true, true]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
suite('behavior lifecycle', function() {
|
||||
|
Loading…
Reference in New Issue
Block a user