bbcaec5850
Fixing Communicators, Fixing Package Loaders, writing CLIs
118 lines
3.3 KiB
TypeScript
118 lines
3.3 KiB
TypeScript
import { injectable } from "inversify";
|
|
import { NopeBaseModule } from "../../lib/module/BaseModule";
|
|
import { NopeObservable } from "../../lib/observables/nopeObservable";
|
|
import { NopePromise } from "../../lib/promise/nopePromise";
|
|
import { INopeObservable } from "../../lib/types/nope/nopeObservable.interface";
|
|
import { IHelloWorlModule } from "./IHelloWorldModule";
|
|
|
|
@injectable()
|
|
export class HelloWorldModule extends NopeBaseModule implements IHelloWorlModule {
|
|
|
|
public testProp: INopeObservable<string>;
|
|
|
|
/**
|
|
* Custom Function
|
|
*
|
|
* @param {string} greetingsTo
|
|
* @return {*}
|
|
* @memberof TestModule
|
|
*/
|
|
async helloWorld(greetingsTo: string) {
|
|
return 'Hello ' + greetingsTo + '! Greetings from ' + this.identifier;
|
|
}
|
|
|
|
async updateTestProp() {
|
|
this.testProp.setContent('Internally Updated');
|
|
}
|
|
|
|
sleep(n: number){
|
|
let timer: any = null;
|
|
return new NopePromise<void>((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: number) => _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')
|
|
}
|
|
} |