881456b2ca
- Modified: - Renamed the decorator `exportFunctionAsNopeService` -> `exportAsNopeService` and the Interface `IexportFunctionAsNopeServiceParameters` -> `IexportAsNopeServiceParameters` - `NopeInstanceManager` and `GenericWrapper`: Now receives a factory to generate the a `NopeEventEmitter`: - This affects a lot packages. - `NopeModule`: - renamed `listFunctions` to `listMethods` - renamed `functions` is now called `methods` - The Description format is being updated (`functions` is now called `methods`) - Fixes: - `NopeModule`: - Now disposes Emitters as Properties as well - `getIdentifierOf` checks event emitters as well now. - `GenericWrapper`: - Now automatically registers emitters as well. - Added: - `NopeModule`: Added the method `listEvents` (to show the available Emitters registered as Properties.)
42 lines
859 B
TypeScript
42 lines
859 B
TypeScript
/**
|
|
* @author Martin Karkowski
|
|
* @email m.karkowski@zema.de
|
|
* @desc [description]
|
|
*/
|
|
|
|
import {
|
|
getCentralDecoratedContainer,
|
|
IexportAsNopeServiceParameters,
|
|
} from "./container";
|
|
|
|
const CONTAINER = getCentralDecoratedContainer();
|
|
|
|
/**
|
|
* Defintion of a Functon.
|
|
*/
|
|
export type callable<T> = {
|
|
(...args): T;
|
|
};
|
|
|
|
/**
|
|
* Decorator, that will export the Function to a Dispatcher
|
|
* @param func The Function
|
|
* @param options The Options.
|
|
*/
|
|
export function exportAsNopeService<T>(
|
|
func: T,
|
|
options: IexportAsNopeServiceParameters
|
|
) {
|
|
// Only add the element if it doesnt exists.
|
|
if (!CONTAINER.services.has(options.id)) {
|
|
CONTAINER.services.set(options.id, {
|
|
callback: async (...args) => {
|
|
return await (func as any)(...args);
|
|
},
|
|
options,
|
|
uri: options.id || (func as any).name,
|
|
});
|
|
}
|
|
return func;
|
|
}
|