UNPKG

@triviality/core

Version:
63 lines 2.62 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; Object.defineProperty(exports, "__esModule", { value: true }); var ramda_1 = require("ramda"); var Context_1 = require("./Context"); var TaggedServiceFactoryReference_1 = require("./Value/TaggedServiceFactoryReference"); function invokeFeatureFactory(internalContext, ff) { if (!ff) { return function (ffc) { return invokeFeatureFactory(internalContext, ffc); }; } var container = internalContext.container; var context = Context_1.createFeatureFactoryContext(__assign({ invoke: invokeFeatureFactory }, internalContext)); Context_1.withGlobalContext({ context: context, container: container, featureFactory: ff }, function () { var newServices = ramda_1.toPairs(ff(context)); newServices.forEach(function (_a) { var _b = __read(_a, 2), tag = _b[0], factory = _b[1]; if (Context_1.hasContextTag(tag)) { throw new Error("Cannot use \"" + tag + "\" context name for service factories"); } if (container.references().hasTagged(tag)) { throw new Error("Cannot redefine \"" + tag + "\" service"); } if (Context_1.isServiceReferenced(factory)) { Context_1.handleServiceReferenced(container, factory, tag); return; } container.add(new TaggedServiceFactoryReference_1.TaggedServiceFactoryReference({ tag: tag, factory: factory, feature: ff, })); }); }); } exports.invokeFeatureFactory = invokeFeatureFactory; exports.invokeFeatureFactories = function (context) { return ramda_1.forEach(invokeFeatureFactory(context)); }; //# sourceMappingURL=invokeFeatureFactory.js.map