Skip to content

Commit

Permalink
Slightly improve how _registered is called.
Browse files Browse the repository at this point in the history
This ensures it's not called on extendors who do not specifically implement `_registered`. This is important since it's expected to do prototype specific work.
  • Loading branch information
Steven Orvell committed Nov 6, 2018
1 parent f62755d commit 5d5c95c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
42 changes: 15 additions & 27 deletions lib/legacy/class.html
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,8 @@
are controlled via the finalization mechanism provided by `Properties-Mixin`.
`Properties` and `observers` are collected by manually traversing the prototype
chain and merging.
The `_registered` method is called via `LegacyElementMixin._finalizeClass`
and is called on each prototype in the element's chain. Because a non-legacy
element may extend a legacy one, it's important that work in `_registered`
carefully act only once.
chain and merging. The `_registered` method is called via
`LegacyElementMixin._finalizeClass`.
*/
/**
Expand All @@ -224,7 +220,6 @@
function GenerateClassFromInfo(info, Base, behaviors) {

// manages behavior and lifecycle processing (filled in after class definition)
let registered = false;
let activeBehaviors;
const lifecycle = {};

Expand Down Expand Up @@ -285,27 +280,20 @@
`is` in `beforeRegister` as you could in 1.x.
*/
const proto = this;
// NOTE: this `registered` flag is required so that extensions
// that do not override `_registered` do not try to "re-register"
// this data. Only extensions that use `mixinBehaviors` will normally
// have this implementation.
if (!registered) {
registered = true;
if (activeBehaviors) {
copyAndFilterBehaviors(proto, activeBehaviors, lifecycle);
}
copyAndFilterProperties(proto, info, lifecycle);
let list = lifecycle.beforeRegister;
if (list) {
for (let i=0; i < list.length; i++) {
list[i].call(proto);
}
if (activeBehaviors) {
copyAndFilterBehaviors(proto, activeBehaviors, lifecycle);
}
copyAndFilterProperties(proto, info, lifecycle);
let list = lifecycle.beforeRegister;
if (list) {
for (let i=0; i < list.length; i++) {
list[i].call(proto);
}
list = lifecycle.registered;
if (list) {
for (let i=0; i < list.length; i++) {
list[i].call(proto);
}
}
list = lifecycle.registered;
if (list) {
for (let i=0; i < list.length; i++) {
list[i].call(proto);
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion lib/legacy/legacy-element-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@
}

static _finalizeClass() {
this.prototype._registered();
// Note, call `_registered` only if this specific prototype has
// an implementation; this ensures `_registered` is not called
// on extenders that do not implement it.
if (this.prototype.hasOwnProperty('_registered')) {
this.prototype._registered();
}
super._finalizeClass();
}

Expand Down

0 comments on commit 5d5c95c

Please sign in to comment.