UNPKG

nope-js-node

Version:

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

160 lines (159 loc) 5.54 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.HelloWorldModuleWithDecorators = void 0; const inversify_1 = require("inversify"); const module_1 = require("../../module"); const observables_1 = require("../../observables"); const promise_1 = require("../../promise"); const decorators_1 = require("../../decorators"); const index_browser_1 = require("../../logger/index.browser"); let HelloWorldModuleWithDecorators = class HelloWorldModuleWithDecorators extends module_1.InjectableNopeBaseModule { constructor() { super(...arguments); // @ts-ignore this.testProp = new observables_1.NopeObservable(); // @ts-ignore this.currentTime = new observables_1.NopeObservable(); } /** * Custom Function * * @param {string} greetingsTo * @return {*} * @memberof TestModule */ async helloWorld(greetingsTo) { return "Hello " + greetingsTo + "! Greetings from " + this.identifier; } /** * Test Function to Update the Property. * * @memberof HelloWorldModuleWithDecorator */ async updateTestProp() { this.testProp.setContent("Internally Updated using updateTestProp()"); } /** * Function which will delay the Execution. * * @param {number} n * @return {*} * @memberof HelloWorldModuleWithDecorator */ sleep(n) { let timer = null; const _this = this; return new promise_1.NopePromise((resolve, reject) => { timer = setTimeout(resolve, n); }, (reason) => { _this._logger.info("Canceling Sleep Function because of:", reason); if (timer != null) { clearTimeout(timer); } }); } async init() { this._logger = (0, index_browser_1.getNopeLogger)("HelloWorldModule"); this._logger.info("Created by dispatcher:", this._core.id); 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(); // Every 1000 ms publish an update of the current time. this._interval = setInterval(() => { _this.currentTime.setContent(new Date().toISOString()); }, 1000); const _this = this; this.testProp.setContent("INITAL_VALUE"); this.testProp.subscribe((value, sender) => { _this._logger.info(_this.identifier, 'got update for "testProp" = ', value, "from", sender); }); } async dispose() { clearInterval(this._interval); this._logger.info("Deleting Module"); await super.dispose(); } }; __decorate([ (0, decorators_1.nopeProperty)({ mode: ["publish"], topic: "testProp", schema: {}, }) ], HelloWorldModuleWithDecorators.prototype, "testProp", void 0); __decorate([ (0, decorators_1.nopeProperty)({ mode: ["publish"], topic: "currentTime", schema: { type: "string", }, }) ], HelloWorldModuleWithDecorators.prototype, "currentTime", void 0); __decorate([ (0, decorators_1.nopeMethod)({ schema: { type: "function", inputs: [ { name: "greetingsTo", schema: { type: "string", description: "Name who should be greeted.", }, }, ], outputs: { type: "string", description: "The Greeting", }, }, }) ], HelloWorldModuleWithDecorators.prototype, "helloWorld", null); __decorate([ (0, decorators_1.nopeMethod)({ schema: { type: "function", inputs: [], outputs: { type: "null", }, }, }) ], HelloWorldModuleWithDecorators.prototype, "updateTestProp", null); __decorate([ (0, decorators_1.nopeMethod)({ schema: { type: "function", inputs: [ { name: "amount", schema: { type: "number", }, }, ], outputs: { type: "null", }, }, }) ], HelloWorldModuleWithDecorators.prototype, "sleep", null); HelloWorldModuleWithDecorators = __decorate([ (0, inversify_1.injectable)() ], HelloWorldModuleWithDecorators); exports.HelloWorldModuleWithDecorators = HelloWorldModuleWithDecorators;