UNPKG

@carlosv2/glue

Version:

Dependency injection library that stays out of the way

41 lines (40 loc) 1.77 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Service = void 0; const buildable_1 = require("./buildable"); class Service extends buildable_1.Buildable { constructor(context, scope, tags, calls) { super(context); this.scope = scope; this.tags = tags; this.calls = calls; } assemble(context) { return __awaiter(this, void 0, void 0, function* () { const instance = (yield this.instantiate(context)); yield Promise.all(this.calls.map((call) => __awaiter(this, void 0, void 0, function* () { const method = (yield call.method.build(context)); const args = yield Promise.all(call.params.map(param => param.build(context))); const fn = instance[method].bind(instance); fn(...args); }))); return instance; }); } getScope() { return this.scope; } getTagsByName(name) { return this.tags.filter(tag => tag.name === name); } } exports.Service = Service;