UNPKG

nope-js-node

Version:

NoPE Runtime for Nodejs. For Browser-Support please use nope-browser

116 lines (115 loc) 4.21 kB
"use strict"; 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; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HelloWorldModule = void 0; const inversify_1 = require("inversify"); const module_1 = require("../../module"); const observables_1 = require("../../observables"); const promise_1 = require("../../promise"); let HelloWorldModule = class HelloWorldModule extends module_1.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 promise_1.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 observables_1.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([ (0, inversify_1.injectable)() ], HelloWorldModule); exports.HelloWorldModule = HelloWorldModule;