UNPKG

nope-js-browser

Version:

NoPE Runtime for the Browser. For nodejs please use nope-js-node

113 lines (112 loc) 4.04 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { injectable } from "inversify"; import { InjectableNopeBaseModule } from "../../module"; import { NopeObservable } from "../../observables"; import { NopePromise } from "../../promise"; let HelloWorldModule = class HelloWorldModule extends InjectableNopeBaseModule { /** * Custom Function * * @param {string} greetingsTo * @return {*} * @memberof TestModule */ async helloWorld(greetingsTo) { return "Hello " + greetingsTo + "! Greetings from " + this.identifier; } async updateTestProp() { this.testProp.setContent("Internally Updated"); } sleep(n) { let timer = null; return new NopePromise((resolve, reject) => { timer = setTimeout(resolve, n); }, (reason) => { console.log("Canceling Sleep Function because of:", reason); if (timer != null) { clearTimeout(timer); } }); } async init() { this.author = { forename: "Martin", mail: "m.karkowski@zema.de", surename: "karkowski", }; this.description = "Test Hello World Module for Nope 2.0"; this.version = { date: new Date("12.10.2020"), version: 1, }; await super.init(); const _this = this; this.testProp = new NopeObservable(); this.testProp.subscribe((value, sender) => { console.log(_this.identifier, 'got update for "testProp" = ', value, "from", sender); }); // Register the Function Manually. await this.registerMethod("helloWorld", (...args) => _this.helloWorld(args[0]), { schema: { type: "function", inputs: [ { name: "greetingsTo", schema: { type: "string", description: "Name who should be greeted.", }, }, ], outputs: { type: "string", description: "The Greeting", }, }, }); await this.registerMethod("updateTestProp", () => _this.updateTestProp(), { schema: { type: "function", inputs: [], outputs: { type: "null", }, }, }); await this.registerMethod("sleep", (amount) => _this.sleep(amount), { schema: { type: "function", inputs: [ { name: "amount", schema: { type: "number", }, }, ], outputs: { type: "null", }, }, }); await this.registerProperty("testProp", this.testProp, { mode: ["publish", "subscribe"], schema: { type: "string", }, topic: "testProp", }); } async dispose() { console.log("Deleting Module"); } }; HelloWorldModule = __decorate([ injectable() ], HelloWorldModule); export { HelloWorldModule };