Skip to content

Commit 5d5c95c

Browse files
author
Steven Orvell
committed
Slightly improve how _registered is called.
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.
1 parent f62755d commit 5d5c95c

2 files changed

Lines changed: 21 additions & 28 deletions

File tree

lib/legacy/class.html

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,8 @@
205205
are controlled via the finalization mechanism provided by `Properties-Mixin`.
206206
207207
`Properties` and `observers` are collected by manually traversing the prototype
208-
chain and merging.
209-
210-
The `_registered` method is called via `LegacyElementMixin._finalizeClass`
211-
and is called on each prototype in the element's chain. Because a non-legacy
212-
element may extend a legacy one, it's important that work in `_registered`
213-
carefully act only once.
208+
chain and merging. The `_registered` method is called via
209+
`LegacyElementMixin._finalizeClass`.
214210
215211
*/
216212
/**
@@ -224,7 +220,6 @@
224220
function GenerateClassFromInfo(info, Base, behaviors) {
225221

226222
// manages behavior and lifecycle processing (filled in after class definition)
227-
let registered = false;
228223
let activeBehaviors;
229224
const lifecycle = {};
230225

@@ -285,27 +280,20 @@
285280
`is` in `beforeRegister` as you could in 1.x.
286281
*/
287282
const proto = this;
288-
// NOTE: this `registered` flag is required so that extensions
289-
// that do not override `_registered` do not try to "re-register"
290-
// this data. Only extensions that use `mixinBehaviors` will normally
291-
// have this implementation.
292-
if (!registered) {
293-
registered = true;
294-
if (activeBehaviors) {
295-
copyAndFilterBehaviors(proto, activeBehaviors, lifecycle);
296-
}
297-
copyAndFilterProperties(proto, info, lifecycle);
298-
let list = lifecycle.beforeRegister;
299-
if (list) {
300-
for (let i=0; i < list.length; i++) {
301-
list[i].call(proto);
302-
}
283+
if (activeBehaviors) {
284+
copyAndFilterBehaviors(proto, activeBehaviors, lifecycle);
285+
}
286+
copyAndFilterProperties(proto, info, lifecycle);
287+
let list = lifecycle.beforeRegister;
288+
if (list) {
289+
for (let i=0; i < list.length; i++) {
290+
list[i].call(proto);
303291
}
304-
list = lifecycle.registered;
305-
if (list) {
306-
for (let i=0; i < list.length; i++) {
307-
list[i].call(proto);
308-
}
292+
}
293+
list = lifecycle.registered;
294+
if (list) {
295+
for (let i=0; i < list.length; i++) {
296+
list[i].call(proto);
309297
}
310298
}
311299
}

lib/legacy/legacy-element-mixin.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,12 @@
9595
}
9696

9797
static _finalizeClass() {
98-
this.prototype._registered();
98+
// Note, call `_registered` only if this specific prototype has
99+
// an implementation; this ensures `_registered` is not called
100+
// on extenders that do not implement it.
101+
if (this.prototype.hasOwnProperty('_registered')) {
102+
this.prototype._registered();
103+
}
99104
super._finalizeClass();
100105
}
101106

0 commit comments

Comments
 (0)