Preparing Observers.

This commit is contained in:
Martin Karkowski 2020-09-11 09:06:49 +02:00
parent bcec3b3a78
commit 510eb7fdfa
3 changed files with 51 additions and 15 deletions

View File

@ -2,11 +2,12 @@
* @author Martin Karkowski * @author Martin Karkowski
* @email m.karkowski@zema.de * @email m.karkowski@zema.de
* @create date 2020-08-25 23:27:28 * @create date 2020-08-25 23:27:28
* @modify date 2020-09-10 08:18:46 * @modify date 2020-09-11 09:06:27
* @desc [description] * @desc [description]
*/ */
import { getSingleton } from "../helpers/singletonMethod"; import { getSingleton } from "../helpers/singletonMethod";
import { nopeObservable } from "../observables/nopeObservable";
import { getDispatcher } from "./getDispatcher"; import { getDispatcher } from "./getDispatcher";
import { ICommunicationInterface } from './nopeDispatcher'; import { ICommunicationInterface } from './nopeDispatcher';
import { IExportFunctionToDispatcherParameters, IExportMethodToDispatcherParameters, IExportPropertyToDispatcherParameters } from "./nopeDispatcherDecorators"; import { IExportFunctionToDispatcherParameters, IExportMethodToDispatcherParameters, IExportPropertyToDispatcherParameters } from "./nopeDispatcherDecorators";
@ -25,7 +26,7 @@ export function getLinkedDispatcher(communicator: ICommunicationInterface) {
}>(), }>(),
parameters: new Map<string, { parameters: new Map<string, {
uri: string, uri: string,
callback: (...args) => Promise<any>, item: nopeObservable<any>,
options: IExportPropertyToDispatcherParameters options: IExportPropertyToDispatcherParameters
}>(), }>(),
functions: new Map<string, { functions: new Map<string, {
@ -53,11 +54,35 @@ export function getLinkedDispatcher(communicator: ICommunicationInterface) {
} }
// Iterate over the Functions // Iterate over the Functions
// for (const [uri, settings] of container.instance.parameters.entries()) { for (const [uri, settings] of container.instance.parameters.entries()) {
// dispatcher.registerFunction(settings.callback, {
// id: uri 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; return dispatcher;
} }

View File

@ -1,4 +1,5 @@
import { getSingleton } from "../helpers/singletonMethod"; import { getSingleton } from "../helpers/singletonMethod";
import { nopeObservable } from "../observables/nopeObservable";
// Symbols for the Property Registery: // Symbols for the Property Registery:
const _registeredDispatcherMethods_ = Symbol('_registeredDispatcherMethods_'); const _registeredDispatcherMethods_ = Symbol('_registeredDispatcherMethods_');
@ -10,11 +11,16 @@ export interface IExportToDispatcherParameters {
} }
export interface IExportMethodToDispatcherParameters { export interface IExportMethodToDispatcherParameters {
// Different uri (instead of using the name)
uri?: string, uri?: string,
// Contains Either the Property Name or the idx name.
deletableCallbacks?: Array<number> | Array<string>
} }
export interface IExportFunctionToDispatcherParameters { export interface IExportFunctionToDispatcherParameters {
uri: string, uri?: string,
// Contains Either the Property Name or the idx name.
deletableCallbacks?: Array<number> | Array<string>
} }
export interface IExportPropertyToDispatcherParameters { export interface IExportPropertyToDispatcherParameters {
@ -31,7 +37,7 @@ const container = getSingleton('nopeBackendDispatcher.container', () => {
}>(), }>(),
parameters: new Map<string, { parameters: new Map<string, {
uri: string, uri: string,
callback: (...args) => Promise<any>, item: nopeObservable<any>,
options: IExportPropertyToDispatcherParameters options: IExportPropertyToDispatcherParameters
}>(), }>(),
functions: new Map<string, { functions: new Map<string, {
@ -60,9 +66,9 @@ export function exportsElementsToDispatcher(options: IExportToDispatcherParamete
// Online if they are present, iterate over them // Online if they are present, iterate over them
if (registeredMethods) { if (registeredMethods) {
registeredMethods.forEach((options, methodName) => { registeredMethods.forEach((_options, methodName) => {
// Register the Methods // Register the Methods
const uri = (options.uri || Base.prototype.name) + (options.uri || methodName); const uri = (options.uri || Base.prototype.name) + (_options.uri || methodName);
container.instance.methods.set(uri, { container.instance.methods.set(uri, {
callback: async (...args) => _this[methodName](...args), callback: async (...args) => _this[methodName](...args),
uri, uri,
@ -73,11 +79,11 @@ export function exportsElementsToDispatcher(options: IExportToDispatcherParamete
// Online if they are present, iterate over them // Online if they are present, iterate over them
if (registeredParams) { if (registeredParams) {
registeredParams.forEach((options, parameterName) => { registeredParams.forEach((_options, parameterName) => {
// Register the Methods // Register the Methods
const uri = (options.uri || Base.prototype.name) + (options.uri || parameterName); const uri = (options.uri || Base.prototype.name) + (_options.uri || parameterName);
container.instance.parameters.set(uri, { container.instance.parameters.set(uri, {
callback: async (...args) => _this[parameterName](...args), item: _this[parameterName],
uri, uri,
options options
}); });

View File

@ -21,7 +21,12 @@ export class nopeRemoteObservable<T, S = T, G = T> {
path: string, path: string,
} }
) { ) {
// Assing the Pathes
this._pathes = {
get: this.options.path + '.get',
set: this.options.path + '.set',
subscribe: this.options.path + '.subscribe'
}
} }
public get currentRemoteValue() { public get currentRemoteValue() {