UNPKG

@allgemein/eventbus

Version:
60 lines (59 loc) 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EventBusConfiguration = void 0; const EventBusAdapterFactory_1 = require("../adapter/EventBusAdapterFactory"); const lodash_1 = require("lodash"); class EventBusConfiguration { constructor(bus, cfg) { this.configuration = cfg; if ((0, lodash_1.isString)(cfg.adapter)) { this.adapter = cfg.adapter; } else { this.adapter = this.configuration.adapter; } this._name = cfg.name; this.bus = bus; } get name() { return this._name; } static getAdapterFactory() { return this.factory; } /* static register(adapterClass: Function) { let name = adapterClass['ADAPTER_NAME']; if (isString(name)) { this.adapters[name] = adapterClass; } else { throw new Error('can\'t register as adapter ' + adapterClass); } } /* static createObjectByType<T>(obj: Function, ...args: any[]): T { let _obj: T = Reflect.construct(obj, args); return _obj; } */ createAdapter(nodeId, name, clazz, opts) { const cfg = (0, lodash_1.clone)(this.configuration); if (opts) { if (cfg.extra) { cfg.extra = (0, lodash_1.merge)(cfg.extra, opts); } else { cfg.extra = opts; } } const grouped = (0, lodash_1.get)(opts, 'group'); if (grouped) { // if group all have same nodeId! nodeId = grouped; } return EventBusConfiguration.factory.create(this.adapter, nodeId, name, clazz, cfg); } } exports.EventBusConfiguration = EventBusConfiguration; EventBusConfiguration.factory = EventBusAdapterFactory_1.EventBusAdapterFactory.$(); //# sourceMappingURL=EventBusConfiguration.js.map