Repository URL to install this package:
|
Version:
6.0.4 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Static poolers. Several custom versions for each potential number of
* arguments. A completely generic pooler is easy to implement, but would
* require accessing the `arguments` object. In each of these, `this` refers to
* the Class itself, not an instance. If any others are needed, simply add them
* here, or in their own files.
*
* @since 5.0.0
* @memberOf pooler
*
* @param copyFieldsFrom obj with instance pool (arguments for constructor?)
* @return instance of Klass
*
* @example
*
* class Eh {}
* addPoolingTo(Eh)
* const eh = Eh.getPooled() //=> oneArgumentPooler(Eh)
* eh.release()
*
*/
function oneArgumentPooler(copyFieldsFrom) {
var Klass = this;
if (Klass.instancePool.length) {
var instance = Klass.instancePool.pop();
// require('fliplog').quick({Klass, instance, copyFieldsFrom})
// @TODO or a static construct!
// if (Klass.construct) Klass.construct.call(instance, copyFieldsFrom)
if (instance.construct)
instance.construct(copyFieldsFrom);
else
Klass.call(instance, copyFieldsFrom);
return instance;
}
else {
return new Klass(copyFieldsFrom);
}
}
exports.default = oneArgumentPooler;
//# sourceMappingURL=oneArgumentPooler.js.map