all files / src/vdom/ component-recycler.js

100% Statements 18/18
100% Branches 8/8
100% Functions 2/2
100% Lines 16/16
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            11× 11× 11× 11×   1061×   1061×     1638×   1638× 1059× 1058× 1053× 1053× 1053×       1638×    
/** 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
 */
"use strict";
 
exports.__esModule = true;
exports.collectComponent = collectComponent;
exports.createComponent = createComponent;
var components = {};
 
function collectComponent(component) {
	var name = component.constructor.name,
	    list = components[name];
	if (list) list.push(component);else components[name] = [component];
}
 
function createComponent(Ctor, props, context, fresh) {
	var inst = new Ctor(props, context),
	    list = !fresh && components[Ctor.name];
	if (list) {
		for (var i = 0; i < list.length; i++) {
			if (list[i].constructor === Ctor) {
				inst.nextBase = list[i].base;
				list.splice(i, 1);
				break;
			}
		}
	}
	return inst;
}