fixing typ errors, adding callbackfunction to the Method.
This commit is contained in:
parent
9c9e34e424
commit
8948ca4f9b
@ -264,4 +264,26 @@ export class CallDispatcher {
|
||||
this.clearTasks();
|
||||
this.unregisterAll();
|
||||
}
|
||||
}
|
||||
|
||||
declare const global;
|
||||
declare const window;
|
||||
|
||||
/**
|
||||
* Function to extract a Singleton Dispatcher
|
||||
* @param uuid The Unique Id of the Dispatcher
|
||||
* @param communicator The provided communicator
|
||||
*/
|
||||
export function getDispatcher(uuid: string, communicator: ICommunicationInterface){
|
||||
|
||||
// Get the global variable
|
||||
const _global = typeof global !== "undefined" ? global : window;
|
||||
const _accessor = '__singletons__'+uuid;
|
||||
const _hasDispatcher = _global[_accessor] !== undefined;
|
||||
|
||||
if (!_hasDispatcher){
|
||||
_global[_accessor] = new CallDispatcher(communicator);
|
||||
}
|
||||
|
||||
return _global[_accessor] as CallDispatcher
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
// Symbols for the Property Registery:
|
||||
const _registedMethods_ = Symbol('_registedMethods_');
|
||||
const _registedParams_ = Symbol('_registedParams_');
|
||||
const _registeredMethods_ = Symbol('_registedMethods_');
|
||||
const _registeredParams_ = Symbol('_registedParams_');
|
||||
|
||||
// Interfaces for the Class
|
||||
export interface IExportApiParameters {
|
||||
@ -30,33 +30,33 @@ export function eportApi(options: IExportApiParameters) {
|
||||
constructor(...args: any[]) {
|
||||
super(...args);
|
||||
|
||||
const _this = this as any;
|
||||
|
||||
// Adding the Path Option.
|
||||
(this as any).__path = options.url;
|
||||
_this.__path = options.url;
|
||||
|
||||
// extract the Registered Methods of the Class.
|
||||
const registedMethods = Base.prototype[_registedMethods_] as Map<string, IExportMethodParameters>;
|
||||
const registedParams = Base.prototype[_registedParams_] as Map<string, IExportPropertyParameters>;
|
||||
const registeredMethods = Base.prototype[_registeredMethods_] as Map<string, IExportMethodParameters>;
|
||||
const registeredParams = Base.prototype[_registeredParams_] as Map<string, IExportPropertyParameters>;
|
||||
|
||||
// Online if they are present, iterate over them
|
||||
if (registedMethods) {
|
||||
registedMethods.forEach((options, methodName) => {
|
||||
|
||||
// Provide the code that should be exectuted for every
|
||||
// Registered Function
|
||||
unicorn.test.push([methodName, options]);
|
||||
console.log(unicorn.test)
|
||||
});
|
||||
if (registeredMethods) {
|
||||
_this.__dispatchRegisterdMethods = (cb: (methodName: string, callback: (...args) => Promise<any>, options: IExportMethodParameters) => void) => {
|
||||
registeredMethods.forEach((options, methodName) => {
|
||||
// Callback the Method
|
||||
cb(methodName, async (...args) => _this[methodName](...args), options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Online if they are present, iterate over them
|
||||
if (registedParams) {
|
||||
registedParams.forEach((options, parameterName) => {
|
||||
|
||||
// Provide the code that should be exectuted for every
|
||||
// Registered Function
|
||||
unicorn.test.push([parameterName, options]);
|
||||
console.log(unicorn.test)
|
||||
});
|
||||
if (registeredParams) {
|
||||
_this.__dispatchRegisterdParams = (cb: (methodName: string, callback: (...args) => Promise<any>, options: IExportPropertyParameters) => void) => {
|
||||
registeredParams.forEach((options, methodName) => {
|
||||
// Callback the Method
|
||||
cb(methodName, async (...args) => _this[methodName](...args), options);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -69,9 +69,9 @@ export function eportApi(options: IExportApiParameters) {
|
||||
*/
|
||||
export function exportMethod(options: IExportMethodParameters = {}) {
|
||||
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
|
||||
target[_registedMethods_] = target[_registedMethods_] || new Map<string, IExportMethodParameters>();
|
||||
target[_registeredMethods_] = target[_registeredMethods_] || new Map<string, IExportMethodParameters>();
|
||||
// Here we just add some information that class decorator will use
|
||||
target[_registedMethods_].set(propertyKey, options);
|
||||
target[_registeredMethods_].set(propertyKey, options);
|
||||
};
|
||||
}
|
||||
|
||||
@ -81,8 +81,8 @@ export function exportMethod(options: IExportMethodParameters = {}) {
|
||||
*/
|
||||
export function exportProperty(options: IExportPropertyParameters = {}) {
|
||||
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
|
||||
target[_registedParams_] = target[_registedParams_] || new Map<string, IExportPropertyParameters>();
|
||||
target[_registeredParams_] = target[_registeredParams_] || new Map<string, IExportPropertyParameters>();
|
||||
// Here we just add some information that class decorator will use
|
||||
target[_registedParams_].set(propertyKey, options);
|
||||
target[_registeredParams_].set(propertyKey, options);
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user