UNPKG

@inversifyjs/core

Version:

InversifyJs core package

32 lines 1.69 kB
import { isPromise } from '@inversifyjs/common'; import { resolveBindingPreDestroy } from './resolveBindingPreDestroy.js'; import { resolveBindingServiceDeactivations } from './resolveBindingServiceDeactivations.js'; const CACHE_KEY_TYPE = 'cache'; export function resolveBindingDeactivations(params, binding) { const preDestroyResult = resolveBindingPreDestroy(params, binding); if (preDestroyResult === undefined) { return resolveBindingDeactivationsAfterPreDestroy(params, binding); } return preDestroyResult.then(() => resolveBindingDeactivationsAfterPreDestroy(params, binding)); } function resolveBindingDeactivationsAfterPreDestroy(params, binding) { const bindingCache = binding.cache; if (isPromise(bindingCache.value)) { return bindingCache.value.then((resolvedValue) => resolveBindingDeactivationsAfterPreDestroyFromValue(params, binding, resolvedValue)); } return resolveBindingDeactivationsAfterPreDestroyFromValue(params, binding, bindingCache.value); } function resolveBindingDeactivationsAfterPreDestroyFromValue(params, binding, resolvedValue) { let deactivationResult = undefined; if (binding.onDeactivation !== undefined) { const bindingDeactivation = binding.onDeactivation; deactivationResult = bindingDeactivation(resolvedValue); } if (deactivationResult === undefined) { return resolveBindingServiceDeactivations(params, binding.serviceIdentifier, resolvedValue); } else { return deactivationResult.then(() => resolveBindingServiceDeactivations(params, binding.serviceIdentifier, resolvedValue)); } } //# sourceMappingURL=resolveBindingDeactivations.js.map