Adding comments and adapting imports
This commit is contained in:
parent
469e6601ba
commit
79227d5950
@ -3,6 +3,10 @@ set DIR=%~dp0
|
|||||||
cd "%DIR%"
|
cd "%DIR%"
|
||||||
SETLOCAL
|
SETLOCAL
|
||||||
echo Compiling Backend
|
echo Compiling Backend
|
||||||
|
|
||||||
|
REM Add the Node Options for SSL these are requrired since Node v.17
|
||||||
|
set NODE_OPTIONS=--openssl-legacy-provider
|
||||||
|
|
||||||
(npm run-script prettier-format) && (
|
(npm run-script prettier-format) && (
|
||||||
(npm run-script compile-nodejs) && (
|
(npm run-script compile-nodejs) && (
|
||||||
(npm run-script compile-browser) && (
|
(npm run-script compile-browser) && (
|
||||||
|
@ -96,11 +96,11 @@ export class NopeConnectivityManager implements INopeConnectivityManager {
|
|||||||
>;
|
>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the current Status Message of the Dispatcher.
|
* see {@link INopeConnectivityManager.info}
|
||||||
*
|
*
|
||||||
* @author M.Karkowski
|
* @author M.Karkowski
|
||||||
* @protected
|
* @readonly
|
||||||
* @return {*} {IDispatcherInfo} The current status of our dispatcher.
|
* @type {INopeStatusInfo}
|
||||||
* @memberof NopeConnectivityManager
|
* @memberof NopeConnectivityManager
|
||||||
*/
|
*/
|
||||||
public get info(): INopeStatusInfo {
|
public get info(): INopeStatusInfo {
|
||||||
@ -178,9 +178,11 @@ export class NopeConnectivityManager implements INopeConnectivityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance of nopeDispatcher.
|
* Creates an instance of NopeConnectivityManager.
|
||||||
* @param {nopeRpcDispatcherOptions} options The Options, used by the Dispatcher.
|
* @author M.Karkowski
|
||||||
* @param {() => INopeObservable<IExternalEventMsg>} _generateObservable A Helper, to generate Observables.
|
* @param {INopeINopeConnectivityOptions} options The Options, used by the Manager.
|
||||||
|
* @param {<T>() => INopeObservable<T>} _generateObservable A Helper, to generate Observables.
|
||||||
|
* @param {string} [id=null] specific id. Otherwise a ID is generated
|
||||||
* @memberof NopeConnectivityManager
|
* @memberof NopeConnectivityManager
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
@ -231,7 +233,14 @@ export class NopeConnectivityManager implements INopeConnectivityManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// See interface description.
|
/**
|
||||||
|
* see {@link INopeConnectivityManager.upTime}
|
||||||
|
*
|
||||||
|
* @author M.Karkowski
|
||||||
|
* @readonly
|
||||||
|
* @type {number}
|
||||||
|
* @memberof NopeConnectivityManager
|
||||||
|
*/
|
||||||
public get upTime(): number {
|
public get upTime(): number {
|
||||||
return Date.now() - this._connectedSince;
|
return Date.now() - this._connectedSince;
|
||||||
}
|
}
|
||||||
@ -246,11 +255,23 @@ export class NopeConnectivityManager implements INopeConnectivityManager {
|
|||||||
*/
|
*/
|
||||||
protected __isMaster: boolean = null;
|
protected __isMaster: boolean = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* see {@link INopeConnectivityManager.isMaster}
|
||||||
|
*
|
||||||
|
* @author M.Karkowski
|
||||||
|
* @memberof NopeConnectivityManager
|
||||||
|
*/
|
||||||
public set isMaster(value: boolean) {
|
public set isMaster(value: boolean) {
|
||||||
this.__isMaster = value;
|
this.__isMaster = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// See interface description.
|
/**
|
||||||
|
* see {@link INopeConnectivityManager.isMaster}
|
||||||
|
*
|
||||||
|
* @author M.Karkowski
|
||||||
|
* @type {boolean}
|
||||||
|
* @memberof NopeConnectivityManager
|
||||||
|
*/
|
||||||
public get isMaster(): boolean {
|
public get isMaster(): boolean {
|
||||||
if (this.__isMaster === null) {
|
if (this.__isMaster === null) {
|
||||||
const upTime = this.upTime;
|
const upTime = this.upTime;
|
||||||
@ -264,7 +285,14 @@ export class NopeConnectivityManager implements INopeConnectivityManager {
|
|||||||
return this.__isMaster;
|
return this.__isMaster;
|
||||||
}
|
}
|
||||||
|
|
||||||
// See interface description.
|
/**
|
||||||
|
* see {@link INopeConnectivityManager.master}
|
||||||
|
*
|
||||||
|
* @author M.Karkowski
|
||||||
|
* @readonly
|
||||||
|
* @type {INopeStatusInfo}
|
||||||
|
* @memberof NopeConnectivityManager
|
||||||
|
*/
|
||||||
public get master(): INopeStatusInfo {
|
public get master(): INopeStatusInfo {
|
||||||
const data = Array.from(this.dispatchers.originalData.values());
|
const data = Array.from(this.dispatchers.originalData.values());
|
||||||
|
|
||||||
@ -284,7 +312,14 @@ export class NopeConnectivityManager implements INopeConnectivityManager {
|
|||||||
return masters[0];
|
return masters[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// See interface description.
|
/**
|
||||||
|
* see {@link INopeConnectivityManager.now}
|
||||||
|
*
|
||||||
|
* @author M.Karkowski
|
||||||
|
* @readonly
|
||||||
|
* @type {number}
|
||||||
|
* @memberof NopeConnectivityManager
|
||||||
|
*/
|
||||||
public get now(): number {
|
public get now(): number {
|
||||||
return Date.now() + this._deltaTime;
|
return Date.now() + this._deltaTime;
|
||||||
}
|
}
|
||||||
@ -406,8 +441,8 @@ export class NopeConnectivityManager implements INopeConnectivityManager {
|
|||||||
*
|
*
|
||||||
* @author M.Karkowski
|
* @author M.Karkowski
|
||||||
* @protected
|
* @protected
|
||||||
* @param {string} dispatcher
|
* @param {string} dispatcher The Id of the dispatcher
|
||||||
* @param {boolean} [quite=false]
|
* @param {boolean} [quite=false] if set to quite, the *dispatchers* attribute wont be udpated.
|
||||||
* @memberof NopeConnectivityManager
|
* @memberof NopeConnectivityManager
|
||||||
*/
|
*/
|
||||||
protected _removeDispatcher(dispatcher: string, quite = false): void {
|
protected _removeDispatcher(dispatcher: string, quite = false): void {
|
||||||
@ -432,18 +467,21 @@ export class NopeConnectivityManager implements INopeConnectivityManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to send the current status to other statusmanagers.
|
* Helper to send the current status to other statusmanagers.
|
||||||
|
*
|
||||||
|
* @author M.Karkowski
|
||||||
|
* @protected
|
||||||
|
* @memberof NopeConnectivityManager
|
||||||
*/
|
*/
|
||||||
protected _sendStatus(): void {
|
protected _sendStatus(): void {
|
||||||
this._communicator.emit("StatusChanged", this.info);
|
this._communicator.emit("StatusChanged", this.info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function, which will synchronize the Timestamp.
|
* see {@link INopeConnectivityManager.syncTime}
|
||||||
* Timestamp must be provided in UTC (https://www.timeanddate.de/stadt/info/zeitzone/utc)
|
|
||||||
*
|
*
|
||||||
* @author M.Karkowski
|
* @author M.Karkowski
|
||||||
* @param {number} timestamp The UTC-Timestamp
|
* @param {number} timestamp
|
||||||
* @param {number} [delay=0] The Delay, since the Timestamp has been generated
|
* @param {number} [delay=0]
|
||||||
* @memberof NopeConnectivityManager
|
* @memberof NopeConnectivityManager
|
||||||
*/
|
*/
|
||||||
public syncTime(timestamp: number, delay = 0) {
|
public syncTime(timestamp: number, delay = 0) {
|
||||||
@ -451,14 +489,23 @@ export class NopeConnectivityManager implements INopeConnectivityManager {
|
|||||||
this._deltaTime = _internalTimestamp - timestamp - delay / 2;
|
this._deltaTime = _internalTimestamp - timestamp - delay / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* see {@link INopeConnectivityManager.getStatus}
|
||||||
|
*
|
||||||
|
* @author M.Karkowski
|
||||||
|
* @param {string} id
|
||||||
|
* @return {*}
|
||||||
|
* @memberof NopeConnectivityManager
|
||||||
|
*/
|
||||||
public getStatus(id: string) {
|
public getStatus(id: string) {
|
||||||
return this._externalDispatchers.get(id);
|
return this._externalDispatchers.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper Function to manually emit a Bonjour!
|
* see {@link INopeConnectivityManager.emitBonjour}
|
||||||
*
|
*
|
||||||
* @return {*} {Promise<void>}
|
* @author M.Karkowski
|
||||||
|
* @return {Promise<void>}
|
||||||
* @memberof NopeConnectivityManager
|
* @memberof NopeConnectivityManager
|
||||||
*/
|
*/
|
||||||
public async emitBonjour(): Promise<void> {
|
public async emitBonjour(): Promise<void> {
|
||||||
@ -467,8 +514,9 @@ export class NopeConnectivityManager implements INopeConnectivityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to reset the Dispatcher.
|
* see {@link INopeConnectivityManager.reset}
|
||||||
*
|
*
|
||||||
|
* @author M.Karkowski
|
||||||
* @memberof NopeConnectivityManager
|
* @memberof NopeConnectivityManager
|
||||||
*/
|
*/
|
||||||
public reset(): void {
|
public reset(): void {
|
||||||
@ -477,8 +525,7 @@ export class NopeConnectivityManager implements INopeConnectivityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapts the Timing Options and resets the internally used
|
* see {@link INopeConnectivityManager.setTimings}
|
||||||
* Timers etc.
|
|
||||||
*
|
*
|
||||||
* @author M.Karkowski
|
* @author M.Karkowski
|
||||||
* @param {Partial<INopeINopeConnectivityTimeOptions>} options
|
* @param {Partial<INopeINopeConnectivityTimeOptions>} options
|
||||||
@ -562,7 +609,13 @@ export class NopeConnectivityManager implements INopeConnectivityManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// See interface description
|
/**
|
||||||
|
* see {@link INopeConnectivityManager.getAllHosts}
|
||||||
|
*
|
||||||
|
* @author M.Karkowski
|
||||||
|
* @return {*} {string[]}
|
||||||
|
* @memberof NopeConnectivityManager
|
||||||
|
*/
|
||||||
public getAllHosts(): string[] {
|
public getAllHosts(): string[] {
|
||||||
const hosts = new Set<string>();
|
const hosts = new Set<string>();
|
||||||
for (const info of this.dispatchers.originalData.values()) {
|
for (const info of this.dispatchers.originalData.values()) {
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
/**
|
/**
|
||||||
|
* @module connectivityManager
|
||||||
* @author Martin Karkowski
|
* @author Martin Karkowski
|
||||||
* @email m.karkowski@zema.de
|
* @email m.karkowski@zema.de
|
||||||
* @create date 2022-01-04 13:31:35
|
*
|
||||||
* @modify date 2022-01-04 13:33:29
|
* # NopeConnectivityManager
|
||||||
* @desc [description]
|
*
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
@ -1,18 +1,80 @@
|
|||||||
/**
|
/**
|
||||||
|
* @module dispatcher
|
||||||
* @author Martin Karkowski
|
* @author Martin Karkowski
|
||||||
* @email m.karkowski@zema.de
|
* @email m.karkowski@zema.de
|
||||||
* @create date 2021-08-27 19:49:25
|
* # NoPE - Dispatcher
|
||||||
* @modify date 2021-09-04 07:48:28
|
*
|
||||||
* @desc [description]
|
*The NoPE-Dispatcher is designed as Layer between the different Modules / Dispatchers. They allow distributed computing or just a simple ***Service oriented Architecture*** (*SOA*). A dispatcher is used to link the modules, share data and events and provide a remote procedure call (rpc) interface.
|
||||||
|
*
|
||||||
|
*## Building Blocks of a Dispatcher:
|
||||||
|
*
|
||||||
|
*| element | description |
|
||||||
|
*|-|-|
|
||||||
|
*| `connectivityManager`: {@link connectivityManager} | establishes a connection to other dispatchers and manages the status of the remotely connected dispatchers. It checks their health and removes dead dispatchers. |
|
||||||
|
*| `eventDistributor`: {@link PubSubSystem} | shares events accross the network (or internally). You can use this element to listen for specific events. The subscription to those events allows `mqtt`-patterns. Additionaly, you are allowed to emit event on specific topics, or pattern based topics |
|
||||||
|
*| `dataDistributor`: {@link DataPubSubSystem} | shares data accross the network (or internally). In comperisson to events, data is persistent and is available all the time. You can use this sub-module to listen for specific data-changes (install data-hooks), pull specific data or push data. You can pull / push data using a `mqtt`-pattern based path. |
|
||||||
|
*| `rpcManager`: {@link rpcManager} | Used to perform `remote procedure calls` (see [here](https://de.wikipedia.org/wiki/Remote_Procedure_Call)). The manager keeps track of the available services. You must use the sub-module to register/unregister (new) services. |
|
||||||
|
*| `instanceManager`: {@link instanceManager} | Used to create/dispose (remote) instances. The manager keeps track of the available instances in the network, allows to create `wrappers` for those instances. You must use the sub-module to register/unregister (new) instances. To allow the system to provide a service for creating instances of as specific type, you can provide a generator and provide it as `service`. |
|
||||||
|
*
|
||||||
|
*## Create a Dispatcher
|
||||||
|
*
|
||||||
|
*To start exploring the capabilities of the dispatcher we will firstly create a dispatcher with the code below:
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*```javascript
|
||||||
|
* // First lets install nope using npm
|
||||||
|
* const nope = require("../dist-nodejs/index.nodejs")
|
||||||
|
*
|
||||||
|
* // Lets create our dispatcher
|
||||||
|
* const dispatcher = nope.dispatcher.getDispatcher({
|
||||||
|
* // We will use the event layer (which just runs internally)
|
||||||
|
* communicator: nope.getLayer("event"),
|
||||||
|
*
|
||||||
|
* // We will adapt the timings (normally, we send a hartbeat and check for dead dispatchers)
|
||||||
|
* timings: {
|
||||||
|
*
|
||||||
|
* // Interval for the alive message given in [ms]. If "0" is provided,
|
||||||
|
* // no alive messages are provided
|
||||||
|
* sendAliveInterval: 0,
|
||||||
|
*
|
||||||
|
* // Interval, to check the other dispatcher for being slow, dead, etc..
|
||||||
|
* // should be lager then the "sendAliveInterval". The value is given in [ms]
|
||||||
|
* // If "0" is provided, no alive messages are provided
|
||||||
|
* checkInterval: 0
|
||||||
|
*
|
||||||
|
* }
|
||||||
|
* });
|
||||||
|
*```
|
||||||
|
*
|
||||||
|
*## Settings for creating:
|
||||||
|
*
|
||||||
|
*The relevant Settings are described by the {@link INopeDispatcherOptions}. This options allows to define:
|
||||||
|
* * the communication bridge. (use `getLayer` to receive a bridge with the specified layer)
|
||||||
|
* * define a specific `id`
|
||||||
|
* * provide a logger (otherwise the dispatcher wont log anything)
|
||||||
|
* * define the timings for `heartbeats` and `checks` (see {@link INopeINopeConnectivityTimeOptions} for more details)
|
||||||
|
* * a `defaultSelector` which is used as selector for a service provide
|
||||||
|
*
|
||||||
|
*## Playing with the dispatcher:
|
||||||
|
*
|
||||||
|
*To play with a dispatcher, you can use the `nope-js` repl tool. this tool creates a `dispatcher` and you are able to interact with the dispatcher in an interactive console.
|
||||||
|
*
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import * as baseServices from "./baseServices";
|
||||||
|
import * as connectivityManager from "./ConnectivityManager";
|
||||||
|
import * as instanceManager from "./InstanceManager";
|
||||||
|
import * as rpcManager from "./RpcManager";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
exportFunctionToDispatcher,
|
exportFunctionToDispatcher,
|
||||||
nopeEmitter,
|
|
||||||
nopeProperty,
|
|
||||||
nopeMethod,
|
|
||||||
IExportFunctionToDispatcherParameters,
|
IExportFunctionToDispatcherParameters,
|
||||||
|
nopeEmitter,
|
||||||
|
nopeMethod,
|
||||||
|
nopeProperty,
|
||||||
} from "../decorators/index";
|
} from "../decorators/index";
|
||||||
export * from "../types/nope/nopeDispatcher.interface";
|
export * from "../types/nope/nopeDispatcher.interface";
|
||||||
export { getDispatcher } from "./getDispatcher";
|
export { getDispatcher } from "./getDispatcher";
|
||||||
export { getLinkedDispatcher } from "./getLinkedDispatcher";
|
export { getLinkedDispatcher } from "./getLinkedDispatcher";
|
||||||
|
export { baseServices, connectivityManager, instanceManager, rpcManager };
|
||||||
|
@ -9,24 +9,30 @@
|
|||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import * as communcation from "./communication/index.browser";
|
import * as communcation from "./communication/index.browser";
|
||||||
import * as dispatcher from "./dispatcher/index";
|
import * as dispatcher from "./dispatcher/index";
|
||||||
|
import * as decorators from "./decorators";
|
||||||
|
import * as eventEmitter from "./eventEmitter";
|
||||||
import * as helpers from "./helpers/index.browser";
|
import * as helpers from "./helpers/index.browser";
|
||||||
import * as loader from "./loader/index.browser";
|
import * as loader from "./loader/index.browser";
|
||||||
import * as logger from "./logger/index.browser";
|
import * as logger from "./logger/index.browser";
|
||||||
import * as modules from "./module/index";
|
import * as modules from "./module/index";
|
||||||
import * as observables from "./observables/index";
|
import * as observables from "./observables/index";
|
||||||
import * as promises from "./promise/index";
|
import * as promise from "./promise/index";
|
||||||
|
import * as pubSub from "./pubSub";
|
||||||
import * as types from "./types/index";
|
import * as types from "./types/index";
|
||||||
|
|
||||||
export { getLayer } from "./communication/index.browser";
|
export { getLayer } from "./communication/index.browser";
|
||||||
export * from "./logger/index.browser";
|
export * from "./logger/index.browser";
|
||||||
export {
|
export {
|
||||||
communcation,
|
communcation,
|
||||||
|
decorators,
|
||||||
dispatcher,
|
dispatcher,
|
||||||
|
eventEmitter,
|
||||||
helpers,
|
helpers,
|
||||||
loader,
|
loader,
|
||||||
logger,
|
logger,
|
||||||
types,
|
types,
|
||||||
modules,
|
modules,
|
||||||
observables,
|
observables,
|
||||||
promises,
|
promise,
|
||||||
|
pubSub,
|
||||||
};
|
};
|
||||||
|
@ -7,30 +7,21 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import * as communcation from "./communication/index.nodejs";
|
export * as communcation from "./communication/index.nodejs";
|
||||||
import * as dispatcher from "./dispatcher/index";
|
export * as decorators from "./decorators";
|
||||||
import * as helpers from "./helpers/index.nodejs";
|
export * as dispatcher from "./dispatcher";
|
||||||
import * as loader from "./loader/index.nodejs";
|
export * as eventEmitters from "./eventEmitter";
|
||||||
import * as logger from "./logger/index.nodejs";
|
export * as helpers from "./helpers/index.nodejs";
|
||||||
import * as modules from "./module/index";
|
export * as loader from "./loader/index.nodejs";
|
||||||
import * as observables from "./observables/index";
|
export * from "./logger/index.nodejs";
|
||||||
import * as promises from "./promise/index";
|
export * as logger from "./logger/index.nodejs";
|
||||||
import * as types from "./types/index";
|
export * as modules from "./module/index";
|
||||||
|
export * as observables from "./observables";
|
||||||
|
export * as promises from "./promise";
|
||||||
|
export * as pubSub from "./pubSub";
|
||||||
|
export * as types from "./types";
|
||||||
export {
|
export {
|
||||||
readInArgs as readInRunNopeBackendArgs,
|
readInArgs as readInRunNopeBackendArgs,
|
||||||
runNopeBackend,
|
runNopeBackend,
|
||||||
} from "./cli/runNopeBackend";
|
} from "./cli/runNopeBackend";
|
||||||
export { getLayer } from "./communication/index.nodejs";
|
export { getLayer } from "./communication/index.nodejs";
|
||||||
export * from "./logger/index.nodejs";
|
|
||||||
export {
|
|
||||||
communcation,
|
|
||||||
dispatcher,
|
|
||||||
helpers,
|
|
||||||
loader,
|
|
||||||
logger,
|
|
||||||
types,
|
|
||||||
modules,
|
|
||||||
observables,
|
|
||||||
promises,
|
|
||||||
};
|
|
||||||
|
@ -1,9 +1,144 @@
|
|||||||
/**
|
/**
|
||||||
|
* @module observables
|
||||||
* @author Martin Karkowski
|
* @author Martin Karkowski
|
||||||
* @email m.karkowski@zema.de
|
* @email m.karkowski@zema.de
|
||||||
* @create date 2021-08-27 20:29:38
|
*
|
||||||
* @modify date 2021-08-27 20:29:38
|
* # Observables
|
||||||
* @desc [description]
|
*
|
||||||
|
* ## Usage of `nope.observables`
|
||||||
|
*
|
||||||
|
* Import Nope.
|
||||||
|
*
|
||||||
|
* ```typescript
|
||||||
|
* import * as nope from "nope";
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* In our nodebook, we have to use **javascript** instead of **typescript**:
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* // First lets install nope using npm
|
||||||
|
* const nope = require("../dist-nodejs/index.nodejs");
|
||||||
|
*
|
||||||
|
* // Create our Observable:
|
||||||
|
* const obs = new nope.observables.NopeObservable();
|
||||||
|
* ```
|
||||||
|
* ### `setContent`: Change the content of the Observable.
|
||||||
|
*
|
||||||
|
* To change the content of an observable use the function `setContent`.
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* // Set the content to "1337"
|
||||||
|
* obs.setContent(5);
|
||||||
|
*
|
||||||
|
* // Print the content (see getContent)
|
||||||
|
* console.log("current value =", obs.getContent());
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* > ` current value = 5`
|
||||||
|
*
|
||||||
|
* #### `setter`: Define a specific setter for the observable.
|
||||||
|
*
|
||||||
|
* You can specify a specifc getter for the observable for instance, to limit the number to the following constrains `> 0` and `< 10`.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* The setter function will receive multiple parameters, as listed below:
|
||||||
|
*
|
||||||
|
* 1. `value`,
|
||||||
|
* 2. `options` containing:
|
||||||
|
* - `sender`: The Element, which changed the data
|
||||||
|
* - `timestamp`: The timestamp of the change
|
||||||
|
* - `args`: additional args.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* The setter function have to return a `dict` with the following keys:
|
||||||
|
*
|
||||||
|
* | key | type | content |
|
||||||
|
* | - | - | - |
|
||||||
|
* | `valid` | `bool` | A Flag, to show whether the data are valid or not. If the data is invalid, the observable wont store them |
|
||||||
|
* | `value` | `any` | The Data that has been adapted |
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Below, we will implement an example to show the setter above.
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* obs.setter = (value, options) => {
|
||||||
|
* // Print, which data we received
|
||||||
|
* console.log("setter received", value, options);
|
||||||
|
* // Show the result of our comparison
|
||||||
|
* console.log("data is valid:", value > 0 && value < 10);
|
||||||
|
* return {
|
||||||
|
* // The Value
|
||||||
|
* value: value,
|
||||||
|
* // Valid
|
||||||
|
* valid: value > 0 && value < 10,
|
||||||
|
* };
|
||||||
|
* };
|
||||||
|
*
|
||||||
|
* // Set the content to "1337" ==> But our setter will prevent using this value because it isnt valid.
|
||||||
|
* obs.setContent(1337);
|
||||||
|
*
|
||||||
|
* // Print the content (see getContent) ==> we expect to get "5"
|
||||||
|
* console.log("current value =", obs.getContent());
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* > ```
|
||||||
|
* > setter received 1337 {}
|
||||||
|
* > data is valid: false
|
||||||
|
* > current value = 5
|
||||||
|
* > ```
|
||||||
|
*
|
||||||
|
* To remove such a getter just set the getter property to `null`.
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* obs.setter = null;
|
||||||
|
*
|
||||||
|
* // Set the content to "1337" we do not have any setter ==> we will use this parameter
|
||||||
|
* obs.setContent(1337);
|
||||||
|
*
|
||||||
|
* // Print the content (see getContent) ==> we expect to get "1337"
|
||||||
|
* console.log("current value =", obs.getContent());
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* > `current value = 1337`
|
||||||
|
*
|
||||||
|
* ### `getContent`: Get the current content of the Observable.
|
||||||
|
*
|
||||||
|
* To extract the content of our observable, we are able to use the function `getContent`
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* let content = obs.getContent();
|
||||||
|
* console.log("current value =", content);
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* > `current value = 1337`
|
||||||
|
*
|
||||||
|
* If no data is assigned, this will result in `undefined`. Otherwise the current data is returned.
|
||||||
|
*
|
||||||
|
* #### `getter`: Define a specific getter for the observable.
|
||||||
|
*
|
||||||
|
* You can specify a specifc getter for the observable for instance, to allways return a `string`
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* // Define a getter
|
||||||
|
* obs.getter = (value) => "Allways this result";
|
||||||
|
* console.log("current value (with getter) =", obs.getContent());
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* > `current value (with getter) = Allways this result`
|
||||||
|
*
|
||||||
|
* To remove such a getter just set the getter property to `null`.
|
||||||
|
*
|
||||||
|
* The Original value is not changed ==> we expect to get "1337"
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* // Reset the getter.
|
||||||
|
* obs.getter = null;
|
||||||
|
* console.log("current value (after removing the getter) =", obs.getContent());
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* > `current value (after removing the getter) = 1337`
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from "../types/nope/nopeObservable.interface";
|
export * from "../types/nope/nopeObservable.interface";
|
||||||
|
@ -11,14 +11,14 @@ import { ICommunicationBridge } from "./nopeCommunication.interface";
|
|||||||
import {
|
import {
|
||||||
IHost,
|
IHost,
|
||||||
INopeINopeConnectivityTimeOptions,
|
INopeINopeConnectivityTimeOptions,
|
||||||
INopeStatusInfo
|
INopeStatusInfo,
|
||||||
} from "./nopeConnectivityManager.interface";
|
} from "./nopeConnectivityManager.interface";
|
||||||
import { INopeCore } from "./nopeCore.interface";
|
import { INopeCore } from "./nopeCore.interface";
|
||||||
import { INopeDescriptor } from "./nopeDescriptor.interface";
|
import { INopeDescriptor } from "./nopeDescriptor.interface";
|
||||||
import {
|
import {
|
||||||
IEventAdditionalData,
|
IEventAdditionalData,
|
||||||
IEventCallback,
|
IEventCallback,
|
||||||
INopeObserver
|
INopeObserver,
|
||||||
} from "./nopeEventEmitter.interface";
|
} from "./nopeEventEmitter.interface";
|
||||||
import { INopeModule, INopeModuleDescription } from "./nopeModule.interface";
|
import { INopeModule, INopeModuleDescription } from "./nopeModule.interface";
|
||||||
import { INopeObservable } from "./nopeObservable.interface";
|
import { INopeObservable } from "./nopeObservable.interface";
|
||||||
@ -33,7 +33,7 @@ export type IGenerateRemoteInstanceCallback<I extends INopeModule> = (
|
|||||||
) => Promise<I>;
|
) => Promise<I>;
|
||||||
export type IGenerateRemoteInstanceForOtherDispatcherCallback<
|
export type IGenerateRemoteInstanceForOtherDispatcherCallback<
|
||||||
I extends INopeModule
|
I extends INopeModule
|
||||||
> = (dispatcher: INopeDispatcher, identifier: string, ...args) => Promise<I>;
|
> = (dispatcher: INopeDispatcher, identifier: string, ...args) => Promise<I>;
|
||||||
|
|
||||||
export type IValidPromise<T> = Promise<T> | INopePromise<T>;
|
export type IValidPromise<T> = Promise<T> | INopePromise<T>;
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ export interface IHostOverview extends IHost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IDispatcherConstructor {
|
export interface IDispatcherConstructor {
|
||||||
new(
|
new (
|
||||||
options: INopeDispatcherOptions,
|
options: INopeDispatcherOptions,
|
||||||
_generateObservable: <T>() => INopeObservable<T>
|
_generateObservable: <T>() => INopeObservable<T>
|
||||||
): INopeDispatcher;
|
): INopeDispatcher;
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 1,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
@ -40,9 +40,17 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 2,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"current value = 5\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"// Set the content to \"1337\"\n",
|
"// Set the content to \"1337\"\n",
|
||||||
"obs.setContent(5);\n",
|
"obs.setContent(5);\n",
|
||||||
@ -84,9 +92,19 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 3,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"setter received 1337 {}\n",
|
||||||
|
"data is valid: false\n",
|
||||||
|
"current value = 5\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"obs.setter = (value, options) => {\n",
|
"obs.setter = (value, options) => {\n",
|
||||||
" // Print, which data we received\n",
|
" // Print, which data we received\n",
|
||||||
@ -117,9 +135,17 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 4,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"current value = 1337\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"obs.setter = null\n",
|
"obs.setter = null\n",
|
||||||
"\n",
|
"\n",
|
||||||
@ -140,9 +166,17 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 5,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"current value = 1337\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"let content = obs.getContent();\n",
|
"let content = obs.getContent();\n",
|
||||||
"console.log(\"current value =\", content)"
|
"console.log(\"current value =\", content)"
|
||||||
@ -161,9 +195,17 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 6,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"current value (with getter) = Allways this result\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"// Define a getter\n",
|
"// Define a getter\n",
|
||||||
"obs.getter = (value) => \"Allways this result\";\n",
|
"obs.getter = (value) => \"Allways this result\";\n",
|
||||||
@ -181,14 +223,29 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 7,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"current value (after removing the getter) = 1337\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"// Reset the getter.\n",
|
"// Reset the getter.\n",
|
||||||
"obs.getter = null;\n",
|
"obs.getter = null;\n",
|
||||||
"console.log(\"current value (after removing the getter) =\", obs.getContent());"
|
"console.log(\"current value (after removing the getter) =\", obs.getContent());"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
|
@ -25,9 +25,30 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 2,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [
|
||||||
|
{
|
||||||
|
"ename": "SyntaxError",
|
||||||
|
"evalue": "Identifier 'nope' has already been declared",
|
||||||
|
"output_type": "error",
|
||||||
|
"traceback": [
|
||||||
|
"evalmachine.<anonymous>:1",
|
||||||
|
"// First lets install nope using npm",
|
||||||
|
"^",
|
||||||
|
"",
|
||||||
|
"SyntaxError: Identifier 'nope' has already been declared",
|
||||||
|
" at Script.runInThisContext (node:vm:129:12)",
|
||||||
|
" at Object.runInThisContext (node:vm:305:38)",
|
||||||
|
" at run ([eval]:1054:15)",
|
||||||
|
" at onRunRequest ([eval]:888:18)",
|
||||||
|
" at onMessage ([eval]:848:13)",
|
||||||
|
" at process.emit (node:events:390:28)",
|
||||||
|
" at emit (node:internal/child_process:915:12)",
|
||||||
|
" at processTicksAndRejections (node:internal/process/task_queues:84:21)"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"// First lets install nope using npm\n",
|
"// First lets install nope using npm\n",
|
||||||
"const nope = require(\"../dist-nodejs/index.nodejs\")\n",
|
"const nope = require(\"../dist-nodejs/index.nodejs\")\n",
|
||||||
@ -60,9 +81,33 @@
|
|||||||
" checkInterval: 0\n",
|
" checkInterval: 0\n",
|
||||||
" \n",
|
" \n",
|
||||||
" }\n",
|
" }\n",
|
||||||
"});\n",
|
"});"
|
||||||
"console.log(dispatcher)"
|
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Settings for creating:\n",
|
||||||
|
"\n",
|
||||||
|
"The relevant Settings are described by the `INopeDispatcherOptions`. This options allows to define:\n",
|
||||||
|
"* the communication bridge. (use `getLayer` to receive a bridge with the specified layer)\n",
|
||||||
|
"* define a specific `id`\n",
|
||||||
|
"* provide a logger (otherwise the dispatcher wont log anything)\n",
|
||||||
|
"* define the timings for `heartbeats` and `checks` (see `INopeINopeConnectivityTimeOptions` for more details)\n",
|
||||||
|
"* a `defaultSelector` which is used as selector for a service provide\n",
|
||||||
|
"\n",
|
||||||
|
"## Playing with the dispatcher:\n",
|
||||||
|
"\n",
|
||||||
|
"To play with a dispatcher, you can use the `nope-js` repl tool. this tool creates a `dispatcher` and you are able to interact with the dispatcher in an interactive console."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
@ -76,8 +121,7 @@
|
|||||||
"mimetype": "application/javascript",
|
"mimetype": "application/javascript",
|
||||||
"name": "javascript",
|
"name": "javascript",
|
||||||
"version": "17.3.1"
|
"version": "17.3.1"
|
||||||
},
|
}
|
||||||
"orig_nbformat": 4
|
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 2
|
"nbformat_minor": 2
|
||||||
|
Loading…
Reference in New Issue
Block a user