UNPKG

@lillallol/dic

Version:

My own dependency injection container.

37 lines (36 loc) 1.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isLiveAbstraction = void 0; const getRegistrationStrictOf_1 = require("../Dic/getRegistrationStrictOf"); const validateNumberOfDependencies_1 = require("../Dic/validateNumberOfDependencies"); /** * @description * Returns a map. * If you provide the map with an abstraction that is not used by the entry points * you will get back `false`, else you will get `true`. */ function isLiveAbstraction(_) { const { dic, entryPointAbstractions, ignoreAbstractions } = _; const hasBeenIterated = new Map([...dic.registry.entries()].map(([abstraction]) => [abstraction, false])); // just to check that the ignored abstractions are registered ignoreAbstractions.forEach((abstraction) => { getRegistrationStrictOf_1.getRegistrationStrictOf(dic.registry, abstraction); hasBeenIterated.set(abstraction, true); }); entryPointAbstractions.forEach((entry) => { hasBeenIterated.set(entry, true); (function recurse(abstraction) { const { factory, dependencies } = getRegistrationStrictOf_1.getRegistrationStrictOf(dic.registry, abstraction); validateNumberOfDependencies_1.validateNumberOfDependencies(dependencies, factory); dependencies.forEach((abstraction) => { if (hasBeenIterated.get(abstraction)) return; else hasBeenIterated.set(abstraction, true); recurse(abstraction); }); })(entry); }); return hasBeenIterated; } exports.isLiveAbstraction = isLiveAbstraction;