UNPKG

@solidgrounds/core

Version:
49 lines 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FeatureGroupFactory = void 0; const Value_1 = require("./Value"); const Error_1 = require("./Error"); const lodash_1 = require("lodash"); const serviceReferenceFactoryInterface_1 = require("./serviceReferenceFactoryInterface"); const GlobalInvokeStack_1 = require("./GlobalInvokeStack"); class FeatureGroupFactory { build(featureFactories, name) { const info = new Value_1.FeatureGroupBuildInfo(name, this); const { featureContext, references } = info; /** * Set all feature function to the container object. */ for (const feature of featureFactories) { const featureFactory = new Value_1.FeatureFactoryBuildInfo(feature); info.addFeature(featureFactory); GlobalInvokeStack_1.GlobalInvokeStack.run({ featureFactory, serviceContainer: info }, () => { /** * We bind the feature so the internal reference are correct */ const result = feature.bind(references)(featureContext); for (const [name, service] of lodash_1.toPairs(result)) { if (name in references) { if (references[name] === service) { continue; } throw new Error_1.ContainerError(`Service ${name} already registered`); } Value_1.assertServiceFactory(service, name); const sfr = serviceReferenceFactoryInterface_1.asServiceFactoryReference(service); Object.assign(references, { [name]: sfr, }); featureFactory.addService(sfr.info); /** * We rebind function call to allow closures inside the feature. */ result[name] = info.getServiceFactory(name); } }); } info.resolvePendingReferences(); return info; } } exports.FeatureGroupFactory = FeatureGroupFactory; //# sourceMappingURL=FeatureGroupFactory.js.map