UNPKG

alpha-dic

Version:

Asynchronous dependency injection container

27 lines (26 loc) 826 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.activationMiddleware = exports.onActivation = void 0; const activationAnnotationName = '__onActivation'; function onActivation(hook) { return { name: activationAnnotationName, hook }; } exports.onActivation = onActivation; function activationMiddleware(definition, next) { const service = next(definition); const hooks = definition.annotations .filter((a) => a.name === activationAnnotationName) .map((a) => a.hook); if (hooks.length) { let promise = Promise.resolve(service); for (const hook of hooks) { promise = promise.then(hook.bind(this)); } return promise; } return service; } exports.activationMiddleware = activationMiddleware;