Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
chain-able-deps / dist / cache / oneArgumentPooler.js
Size: Mime:
"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