/** * @author Martin Karkowski * @email m.karkowski@zema.de * @create date 2020-08-25 23:27:28 * @modify date 2020-09-12 00:31:07 * @desc [description] */ import { getSingleton } from "../helpers/singletonMethod"; import { nopeObservable } from "../observables/nopeObservable"; import { getDispatcher } from "./getDispatcher"; import { nopeDispatcherOptions } from './nopeDispatcher'; import { IExportFunctionToDispatcherParameters, IExportMethodToDispatcherParameters, IExportPropertyToDispatcherParameters } from "./nopeDispatcherDecorators"; /** * Returns a Dispatcher. * @param options */ export function getLinkedDispatcher(options: nopeDispatcherOptions) { const container = getSingleton('nopeBackendDispatcher.container', () => { return { methods: new Map Promise, options: IExportMethodToDispatcherParameters }>(), parameters: new Map, options: IExportPropertyToDispatcherParameters }>(), functions: new Map Promise, options: IExportFunctionToDispatcherParameters }>() } }); const dispatcher = getDispatcher(options); // Iterate over the Methods for (const [uri, settings] of container.instance.methods.entries()) { dispatcher.registerFunction(settings.callback, { id: uri }) } // Iterate over the Functions for (const [uri, settings] of container.instance.functions.entries()) { dispatcher.registerFunction(settings.callback, { id: uri }); } // Iterate over the Functions for (const [uri, settings] of container.instance.parameters.entries()) { const _pathes = { get: uri + '.get', set: uri + '.set', subscribe: uri + '.subscribe' } // Register Getter: dispatcher.registerFunction(async () => { return settings.item.getContent() }, { id: _pathes.get }); // Register Setter: dispatcher.registerFunction(async (content, ...args) => { return settings.item.setContent(content, ...args) }, { id: _pathes.set }); // Register Subscription: dispatcher.registerFunction(async (oberserver, ...args) => { return settings.item.subscribe(oberserver, ...args) }, { id: _pathes.subscribe }); } return dispatcher; }