nope/lib/dispatcher/getLinkedDispatcher.ts

45 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-08-25 22:11:26 +00:00
/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
* @create date 2020-08-25 23:27:28
* @modify date 2020-08-25 23:46:32
* @desc [description]
*/
import { getSingleton } from "../helpers/singletonMethod";
2020-08-30 08:25:53 +00:00
import { ICommunicationInterface } from './nopeDispatcher';
2020-08-25 22:11:26 +00:00
import { IExportMethodToDispatcherParameters, IExportPropertyToDispatcherParameters } from "./nopeDispatcherDecorators";
2020-08-30 08:25:53 +00:00
import { getDispatcher } from "./getDispatcher";
2020-08-25 22:11:26 +00:00
/**
* Returns a Dispatcher.
* @param communicator
*/
export function getLinkedDispatcher(communicator: ICommunicationInterface) {
const container = getSingleton('nopeBackendDispatcher.methodContainer', () => {
return {
methods: new Map<string, {
uri: string,
callback: (...args) => Promise<any>,
options: IExportMethodToDispatcherParameters
}>(),
parameters: new Map<string, {
uri: string,
callback: (...args) => Promise<any>,
options: IExportPropertyToDispatcherParameters
}>()
}
});
const dispatcher = getDispatcher(communicator);
for (const [uri, settings] of container.instance.methods.entries()) {
dispatcher.registerFunction(settings.callback, {
id: uri
})
}
return dispatcher;
}