@robotlegsjs/core
Version:
An architecture-based IoC framework for JavaScript/TypeScript
40 lines • 1.8 kB
JavaScript
;
// ------------------------------------------------------------------------------
// Copyright (c) 2017-present, RobotlegsJS. All Rights Reserved.
//
// NOTICE: You are permitted to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyHooks = void 0;
var instantiateUnmapped_1 = require("./instantiateUnmapped");
/*============================================================================*/
/* Public Functions */
/*============================================================================*/
/**
* <p>A hook can be a function, object or class.</p>
*
* <p>When an object is passed it is expected to expose a "hook" method.</p>
*
* <p>When a class is passed, an instance of that class will be instantiated and called.
* If an injector is provided the instance will be created using that injector,
* otherwise the instance will be created manually.</p>
*
* @param hooks An array of hooks
* @param injector An optional Injector
*/
function applyHooks(hooks, injector) {
for (var _i = 0, hooks_1 = hooks; _i < hooks_1.length; _i++) {
var hook = hooks_1[_i];
if (typeof hook === "function" && hook.prototype.hook === undefined) {
hook();
continue;
}
if (typeof hook === "function" && hook.prototype.hook !== undefined) {
hook = injector ? instantiateUnmapped_1.instantiateUnmapped(injector, hook) : new hook();
}
hook.hook();
}
}
exports.applyHooks = applyHooks;
//# sourceMappingURL=applyHooks.js.map