blob: a70f0ece06301b98bb61b52a1c48e31e7a37b71a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
import { Component } from '../component';
/** Retains a pool of Components for re-use, keyed on component name.
* Note: since component names are not unique or even necessarily available, these are primarily a form of sharding.
* @private
*/
const components = {};
export function collectComponent(component) {
let name = component.constructor.name,
list = components[name];
if (list) list.push(component);
else components[name] = [component];
}
export function createComponent(Ctor, props, context) {
let inst = new Ctor(props, context),
list = components[Ctor.name];
Component.call(inst, props, context);
if (list) {
for (let i=list.length; i--; ) {
if (list[i].constructor===Ctor) {
inst.nextBase = list[i].nextBase;
list.splice(i, 1);
break;
}
}
}
return inst;
}
|