UNPKG

@triviality/core

Version:
107 lines 4.32 kB
"use strict"; 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; }; var __spread = (this && this.__spread) || function () { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; }; Object.defineProperty(exports, "__esModule", { value: true }); var ramda_1 = require("ramda"); var ImmutableServiceReferenceList = /** @class */ (function () { function ImmutableServiceReferenceList(references) { if (references === void 0) { references = []; } this.references = references; } /** * This dependency is depended on the other dependency. */ ImmutableServiceReferenceList.prototype.add = function (dependency) { if (this.has(dependency)) { return this; } return new ImmutableServiceReferenceList(__spread(this.references, [dependency])); }; ImmutableServiceReferenceList.prototype.getService = function (tag) { var service = this.references.find(function (dep) { return dep.type === 'tagged' && dep.tag === tag; }); if (!service || service.type !== 'tagged') { throw new Error("Service with " + tag + " not found"); } return service; }; ImmutableServiceReferenceList.prototype.taggedPairs = function () { var filtered = this.references.filter(function (dep) { return dep.type === 'tagged'; }); return filtered.map(function (dependency) { return [dependency.tag, dependency]; }); }; ImmutableServiceReferenceList.prototype.async = function () { return this.filter(function (dep) { return dep.type === 'async'; }); }; ImmutableServiceReferenceList.prototype.notASync = function () { return this.filter(function (dep) { return dep.type !== 'async'; }); }; ImmutableServiceReferenceList.prototype.filter = function (accept) { var filtered = this.references.filter(accept); return new ImmutableServiceReferenceList(filtered); }; ImmutableServiceReferenceList.prototype.serviceFactoryObject = function () { var pairs = this.taggedPairs().map(function (_a) { var _b = __read(_a, 2), tag = _b[0], reference = _b[1]; return [tag, reference.getProxy()]; }); return ramda_1.fromPairs(pairs); }; ImmutableServiceReferenceList.prototype.has = function (needle) { return !!this.references.find(function (ref) { return ref.getDependencies().has(needle); }); }; ImmutableServiceReferenceList.prototype.hasTagged = function (needle) { return this.taggedPairs().filter(function (_a) { var _b = __read(_a, 1), tag = _b[0]; return needle === tag; }).length !== 0; }; ImmutableServiceReferenceList.prototype.toArray = function () { return __spread(this.references); }; ImmutableServiceReferenceList.prototype.remove = function (reference) { return this.filter(function (ref) { return ref !== reference; }); }; ImmutableServiceReferenceList.prototype.last = function () { return this.references[this.references.length - 1]; }; ImmutableServiceReferenceList.prototype.forEach = function (iterator) { return this.references.forEach(iterator); }; ImmutableServiceReferenceList.prototype.isEmpty = function () { return this.references.length === 0; }; ImmutableServiceReferenceList.prototype.isNotEmpty = function () { return this.references.length !== 0; }; ImmutableServiceReferenceList.prototype.count = function () { return this.references.length; }; return ImmutableServiceReferenceList; }()); exports.ImmutableServiceReferenceList = ImmutableServiceReferenceList; //# sourceMappingURL=ImmutableServiceReferenceList.js.map