UNPKG

@carlosv2/glue

Version:

Dependency injection library that stays out of the way

37 lines (36 loc) 1.64 kB
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()); }); }; import { Buildable } from './buildable.js'; export class Service extends 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); } }