From 79227d5950f14a6b61432bdd484e9ac0bc780755 Mon Sep 17 00:00:00 2001 From: Martin Karkowski Date: Wed, 19 Jan 2022 18:38:43 +0100 Subject: [PATCH] Adding comments and adapting imports --- 00-compile.bat | 4 + lib/communication/index.nodejs.ts | 2 +- .../ConnectivityManager.ts | 97 +++++++++--- lib/dispatcher/ConnectivityManager/index.ts | 8 +- lib/dispatcher/index.ts | 74 ++++++++- lib/index.browser.ts | 10 +- lib/index.nodejs.ts | 35 ++--- lib/observables/index.ts | 141 +++++++++++++++++- lib/types/nope/nopeDescriptor.interface.ts | 20 +-- lib/types/nope/nopeDispatcher.interface.ts | 16 +- ...-Started copy.md => 00-Getting-Started.md} | 0 wiki/11-Observables.ipynb | 83 +++++++++-- wiki/12-Dispatcher.ipynb | 56 ++++++- 13 files changed, 450 insertions(+), 96 deletions(-) rename wiki/{00-Getting-Started copy.md => 00-Getting-Started.md} (100%) diff --git a/00-compile.bat b/00-compile.bat index 242c68a..fc7e332 100644 --- a/00-compile.bat +++ b/00-compile.bat @@ -3,6 +3,10 @@ set DIR=%~dp0 cd "%DIR%" SETLOCAL 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 compile-nodejs) && ( (npm run-script compile-browser) && ( diff --git a/lib/communication/index.nodejs.ts b/lib/communication/index.nodejs.ts index ea1e100..d2a8de6 100644 --- a/lib/communication/index.nodejs.ts +++ b/lib/communication/index.nodejs.ts @@ -5,7 +5,7 @@ * @create date 2021-08-04 15:30:10 * @modify date 2022-01-10 16:01:15 * @desc [description] - * + * */ export { Bridge } from "./bridge"; diff --git a/lib/dispatcher/ConnectivityManager/ConnectivityManager.ts b/lib/dispatcher/ConnectivityManager/ConnectivityManager.ts index 468da00..7970f78 100644 --- a/lib/dispatcher/ConnectivityManager/ConnectivityManager.ts +++ b/lib/dispatcher/ConnectivityManager/ConnectivityManager.ts @@ -96,11 +96,11 @@ export class NopeConnectivityManager implements INopeConnectivityManager { >; /** - * Generates the current Status Message of the Dispatcher. + * see {@link INopeConnectivityManager.info} * * @author M.Karkowski - * @protected - * @return {*} {IDispatcherInfo} The current status of our dispatcher. + * @readonly + * @type {INopeStatusInfo} * @memberof NopeConnectivityManager */ public get info(): INopeStatusInfo { @@ -178,9 +178,11 @@ export class NopeConnectivityManager implements INopeConnectivityManager { } /** - * Creates an instance of nopeDispatcher. - * @param {nopeRpcDispatcherOptions} options The Options, used by the Dispatcher. - * @param {() => INopeObservable} _generateObservable A Helper, to generate Observables. + * Creates an instance of NopeConnectivityManager. + * @author M.Karkowski + * @param {INopeINopeConnectivityOptions} options The Options, used by the Manager. + * @param {() => INopeObservable} _generateObservable A Helper, to generate Observables. + * @param {string} [id=null] specific id. Otherwise a ID is generated * @memberof NopeConnectivityManager */ 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 { return Date.now() - this._connectedSince; } @@ -246,11 +255,23 @@ export class NopeConnectivityManager implements INopeConnectivityManager { */ protected __isMaster: boolean = null; + /** + * see {@link INopeConnectivityManager.isMaster} + * + * @author M.Karkowski + * @memberof NopeConnectivityManager + */ public set isMaster(value: boolean) { this.__isMaster = value; } - // See interface description. + /** + * see {@link INopeConnectivityManager.isMaster} + * + * @author M.Karkowski + * @type {boolean} + * @memberof NopeConnectivityManager + */ public get isMaster(): boolean { if (this.__isMaster === null) { const upTime = this.upTime; @@ -264,7 +285,14 @@ export class NopeConnectivityManager implements INopeConnectivityManager { return this.__isMaster; } - // See interface description. + /** + * see {@link INopeConnectivityManager.master} + * + * @author M.Karkowski + * @readonly + * @type {INopeStatusInfo} + * @memberof NopeConnectivityManager + */ public get master(): INopeStatusInfo { const data = Array.from(this.dispatchers.originalData.values()); @@ -284,7 +312,14 @@ export class NopeConnectivityManager implements INopeConnectivityManager { return masters[0]; } - // See interface description. + /** + * see {@link INopeConnectivityManager.now} + * + * @author M.Karkowski + * @readonly + * @type {number} + * @memberof NopeConnectivityManager + */ public get now(): number { return Date.now() + this._deltaTime; } @@ -406,8 +441,8 @@ export class NopeConnectivityManager implements INopeConnectivityManager { * * @author M.Karkowski * @protected - * @param {string} dispatcher - * @param {boolean} [quite=false] + * @param {string} dispatcher The Id of the dispatcher + * @param {boolean} [quite=false] if set to quite, the *dispatchers* attribute wont be udpated. * @memberof NopeConnectivityManager */ 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. + * + * @author M.Karkowski + * @protected + * @memberof NopeConnectivityManager */ protected _sendStatus(): void { this._communicator.emit("StatusChanged", this.info); } /** - * Helper function, which will synchronize the Timestamp. - * Timestamp must be provided in UTC (https://www.timeanddate.de/stadt/info/zeitzone/utc) + * see {@link INopeConnectivityManager.syncTime} * * @author M.Karkowski - * @param {number} timestamp The UTC-Timestamp - * @param {number} [delay=0] The Delay, since the Timestamp has been generated + * @param {number} timestamp + * @param {number} [delay=0] * @memberof NopeConnectivityManager */ public syncTime(timestamp: number, delay = 0) { @@ -451,14 +489,23 @@ export class NopeConnectivityManager implements INopeConnectivityManager { this._deltaTime = _internalTimestamp - timestamp - delay / 2; } + /** + * see {@link INopeConnectivityManager.getStatus} + * + * @author M.Karkowski + * @param {string} id + * @return {*} + * @memberof NopeConnectivityManager + */ public getStatus(id: string) { return this._externalDispatchers.get(id); } /** - * Helper Function to manually emit a Bonjour! + * see {@link INopeConnectivityManager.emitBonjour} * - * @return {*} {Promise} + * @author M.Karkowski + * @return {Promise} * @memberof NopeConnectivityManager */ public async emitBonjour(): Promise { @@ -467,8 +514,9 @@ export class NopeConnectivityManager implements INopeConnectivityManager { } /** - * Function to reset the Dispatcher. + * see {@link INopeConnectivityManager.reset} * + * @author M.Karkowski * @memberof NopeConnectivityManager */ public reset(): void { @@ -477,8 +525,7 @@ export class NopeConnectivityManager implements INopeConnectivityManager { } /** - * Adapts the Timing Options and resets the internally used - * Timers etc. + * see {@link INopeConnectivityManager.setTimings} * * @author M.Karkowski * @param {Partial} 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[] { const hosts = new Set(); for (const info of this.dispatchers.originalData.values()) { diff --git a/lib/dispatcher/ConnectivityManager/index.ts b/lib/dispatcher/ConnectivityManager/index.ts index 5f83589..7341662 100644 --- a/lib/dispatcher/ConnectivityManager/index.ts +++ b/lib/dispatcher/ConnectivityManager/index.ts @@ -1,9 +1,11 @@ /** + * @module connectivityManager * @author Martin Karkowski * @email m.karkowski@zema.de - * @create date 2022-01-04 13:31:35 - * @modify date 2022-01-04 13:33:29 - * @desc [description] + * + * # NopeConnectivityManager + * + * */ export { diff --git a/lib/dispatcher/index.ts b/lib/dispatcher/index.ts index a3d3581..51b7076 100644 --- a/lib/dispatcher/index.ts +++ b/lib/dispatcher/index.ts @@ -1,18 +1,80 @@ /** + * @module dispatcher * @author Martin Karkowski * @email m.karkowski@zema.de - * @create date 2021-08-27 19:49:25 - * @modify date 2021-09-04 07:48:28 - * @desc [description] + * # NoPE - Dispatcher + * + *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 { exportFunctionToDispatcher, - nopeEmitter, - nopeProperty, - nopeMethod, IExportFunctionToDispatcherParameters, + nopeEmitter, + nopeMethod, + nopeProperty, } from "../decorators/index"; export * from "../types/nope/nopeDispatcher.interface"; export { getDispatcher } from "./getDispatcher"; export { getLinkedDispatcher } from "./getLinkedDispatcher"; +export { baseServices, connectivityManager, instanceManager, rpcManager }; diff --git a/lib/index.browser.ts b/lib/index.browser.ts index 8cb7e94..5390f46 100644 --- a/lib/index.browser.ts +++ b/lib/index.browser.ts @@ -9,24 +9,30 @@ import "reflect-metadata"; import * as communcation from "./communication/index.browser"; 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 loader from "./loader/index.browser"; import * as logger from "./logger/index.browser"; import * as modules from "./module/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"; export { getLayer } from "./communication/index.browser"; export * from "./logger/index.browser"; export { communcation, + decorators, dispatcher, + eventEmitter, helpers, loader, logger, types, modules, observables, - promises, + promise, + pubSub, }; diff --git a/lib/index.nodejs.ts b/lib/index.nodejs.ts index f96dd21..4e9397b 100644 --- a/lib/index.nodejs.ts +++ b/lib/index.nodejs.ts @@ -7,30 +7,21 @@ */ import "reflect-metadata"; -import * as communcation from "./communication/index.nodejs"; -import * as dispatcher from "./dispatcher/index"; -import * as helpers from "./helpers/index.nodejs"; -import * as loader from "./loader/index.nodejs"; -import * as logger from "./logger/index.nodejs"; -import * as modules from "./module/index"; -import * as observables from "./observables/index"; -import * as promises from "./promise/index"; -import * as types from "./types/index"; - +export * as communcation from "./communication/index.nodejs"; +export * as decorators from "./decorators"; +export * as dispatcher from "./dispatcher"; +export * as eventEmitters from "./eventEmitter"; +export * as helpers from "./helpers/index.nodejs"; +export * as loader from "./loader/index.nodejs"; +export * from "./logger/index.nodejs"; +export * as logger from "./logger/index.nodejs"; +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 { readInArgs as readInRunNopeBackendArgs, runNopeBackend, } from "./cli/runNopeBackend"; export { getLayer } from "./communication/index.nodejs"; -export * from "./logger/index.nodejs"; -export { - communcation, - dispatcher, - helpers, - loader, - logger, - types, - modules, - observables, - promises, -}; diff --git a/lib/observables/index.ts b/lib/observables/index.ts index 11bff57..88e0a7b 100644 --- a/lib/observables/index.ts +++ b/lib/observables/index.ts @@ -1,9 +1,144 @@ /** + * @module observables * @author Martin Karkowski * @email m.karkowski@zema.de - * @create date 2021-08-27 20:29:38 - * @modify date 2021-08-27 20:29:38 - * @desc [description] + * + * # Observables + * + * ## 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"; diff --git a/lib/types/nope/nopeDescriptor.interface.ts b/lib/types/nope/nopeDescriptor.interface.ts index b39647a..d11d3c7 100644 --- a/lib/types/nope/nopeDescriptor.interface.ts +++ b/lib/types/nope/nopeDescriptor.interface.ts @@ -20,7 +20,7 @@ export type INopeDescriptorSchemaBaseTypes = | "function"; /** - * A (JSON-Schema and) Nope-Descriptor allows to use multiple types. + * A (JSON-Schema and) Nope-Descriptor allows to use multiple types. * Therefore this type uses some additonal types. Alternativly, a reference * **`$ref`** can be used to describe some data. Therefore the schema * must be availalbe on the reference. @@ -32,14 +32,14 @@ export type INopeDescriptorSchemaTypes = /** * # INopeDescriptor - * + * * A generic descriptor of data or a function. This descriptors will be used to describe `NoPE` data-points or functions. The Descriptor is based on **JSON-Schemas** (see [here](https://json-schema.org/) for more details). - * - * + * + * * ## Describing data - * - * A valid example - *describing some data* - is given below (in the form of `JSON`-data). This example matches a **JSON-Schema**: * - * + * + * A valid example - *describing some data* - is given below (in the form of `JSON`-data). This example matches a **JSON-Schema**: * + * * ```json * { * "title": "Person", @@ -62,9 +62,9 @@ export type INopeDescriptorSchemaTypes = * } * ``` * ## Describing functions - * + * * A valid example - *describing a function* - is given below (in the form of `JSON`-data): - * + * * ```json * { * "type": "function", @@ -86,7 +86,7 @@ export type INopeDescriptorSchemaTypes = * "type":"boolean" * } * } - * ] + * ] * } * ``` * diff --git a/lib/types/nope/nopeDispatcher.interface.ts b/lib/types/nope/nopeDispatcher.interface.ts index 95d2803..fbeaabd 100644 --- a/lib/types/nope/nopeDispatcher.interface.ts +++ b/lib/types/nope/nopeDispatcher.interface.ts @@ -11,14 +11,14 @@ import { ICommunicationBridge } from "./nopeCommunication.interface"; import { IHost, INopeINopeConnectivityTimeOptions, - INopeStatusInfo + INopeStatusInfo, } from "./nopeConnectivityManager.interface"; import { INopeCore } from "./nopeCore.interface"; import { INopeDescriptor } from "./nopeDescriptor.interface"; import { IEventAdditionalData, IEventCallback, - INopeObserver + INopeObserver, } from "./nopeEventEmitter.interface"; import { INopeModule, INopeModuleDescription } from "./nopeModule.interface"; import { INopeObservable } from "./nopeObservable.interface"; @@ -33,7 +33,7 @@ export type IGenerateRemoteInstanceCallback = ( ) => Promise; export type IGenerateRemoteInstanceForOtherDispatcherCallback< I extends INopeModule - > = (dispatcher: INopeDispatcher, identifier: string, ...args) => Promise; +> = (dispatcher: INopeDispatcher, identifier: string, ...args) => Promise; export type IValidPromise = Promise | INopePromise; @@ -102,7 +102,7 @@ export interface IHostOverview extends IHost { } export interface IDispatcherConstructor { - new( + new ( options: INopeDispatcherOptions, _generateObservable: () => INopeObservable ): INopeDispatcher; @@ -143,12 +143,12 @@ export interface INopeDispatcherDescription extends INopeStatusInfo { /** * # NoPE - Dispatcher - * + * * 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 | + * + * | element | description | * |-|-| * | `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` | 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 | diff --git a/wiki/00-Getting-Started copy.md b/wiki/00-Getting-Started.md similarity index 100% rename from wiki/00-Getting-Started copy.md rename to wiki/00-Getting-Started.md diff --git a/wiki/11-Observables.ipynb b/wiki/11-Observables.ipynb index de5ba8c..afd0349 100644 --- a/wiki/11-Observables.ipynb +++ b/wiki/11-Observables.ipynb @@ -18,7 +18,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -40,9 +40,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "current value = 5\n" + ] + } + ], "source": [ "// Set the content to \"1337\"\n", "obs.setContent(5);\n", @@ -84,9 +92,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "setter received 1337 {}\n", + "data is valid: false\n", + "current value = 5\n" + ] + } + ], "source": [ "obs.setter = (value, options) => {\n", " // Print, which data we received\n", @@ -117,9 +135,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "current value = 1337\n" + ] + } + ], "source": [ "obs.setter = null\n", "\n", @@ -140,9 +166,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "current value = 1337\n" + ] + } + ], "source": [ "let content = obs.getContent();\n", "console.log(\"current value =\", content)" @@ -161,9 +195,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "current value (with getter) = Allways this result\n" + ] + } + ], "source": [ "// Define a getter\n", "obs.getter = (value) => \"Allways this result\";\n", @@ -181,14 +223,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "current value (after removing the getter) = 1337\n" + ] + } + ], "source": [ "// Reset the getter.\n", "obs.getter = null;\n", "console.log(\"current value (after removing the getter) =\", obs.getContent());" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/wiki/12-Dispatcher.ipynb b/wiki/12-Dispatcher.ipynb index e47e9a4..f86f538 100644 --- a/wiki/12-Dispatcher.ipynb +++ b/wiki/12-Dispatcher.ipynb @@ -25,9 +25,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "Identifier 'nope' has already been declared", + "output_type": "error", + "traceback": [ + "evalmachine.: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": [ "// First lets install nope using npm\n", "const nope = require(\"../dist-nodejs/index.nodejs\")\n", @@ -60,9 +81,33 @@ " checkInterval: 0\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": { @@ -76,8 +121,7 @@ "mimetype": "application/javascript", "name": "javascript", "version": "17.3.1" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2