UNPKG

@inversifyjs/core

Version:

InversifyJs core package

31 lines 1.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.resolveInstanceBindingNodeFromConstructorParams = resolveInstanceBindingNodeFromConstructorParams; const common_1 = require("@inversifyjs/common"); const resolvePostConstruct_1 = require("./resolvePostConstruct"); function resolveAllPostConstructMethods(instance, binding, postConstructMethodNames) { if (postConstructMethodNames.size === 0) { return instance; } let result = instance; for (const methodName of postConstructMethodNames) { if ((0, common_1.isPromise)(result)) { result = result.then((resolvedInstance) => (0, resolvePostConstruct_1.resolvePostConstruct)(resolvedInstance, binding, methodName)); } else { result = (0, resolvePostConstruct_1.resolvePostConstruct)(result, binding, methodName); } } return result; } function resolveInstanceBindingNodeFromConstructorParams(setInstanceProperties) { return (constructorValues, params, node) => { const instance = new node.binding.implementationType(...constructorValues); const propertiesAssignmentResult = setInstanceProperties(params, instance, node); if ((0, common_1.isPromise)(propertiesAssignmentResult)) { return propertiesAssignmentResult.then(() => resolveAllPostConstructMethods(instance, node.binding, node.classMetadata.lifecycle.postConstructMethodNames)); } return resolveAllPostConstructMethods(instance, node.binding, node.classMetadata.lifecycle.postConstructMethodNames); }; } //# sourceMappingURL=resolveInstanceBindingNodeFromConstructorParams.js.map