fix(core): update

This commit is contained in:
Philipp Kunz 2020-10-06 17:18:20 +00:00
parent e500c8a7f6
commit 3726e29768
4 changed files with 33 additions and 11 deletions

6
package-lock.json generated
View File

@ -5,9 +5,9 @@
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"@apiglobal/typedrequest": { "@apiglobal/typedrequest": {
"version": "1.0.49", "version": "1.0.50",
"resolved": "https://verdaccio.lossless.one/@apiglobal%2ftypedrequest/-/typedrequest-1.0.49.tgz", "resolved": "https://verdaccio.lossless.one/@apiglobal%2ftypedrequest/-/typedrequest-1.0.50.tgz",
"integrity": "sha512-9pDu8a7aj2SnbiyRyYK7uyWyZYhH2Ej+ovGI1gXKX8CbG28FchoiiSVMCFnWdvCq2X1+Tm2nybSr50vB8vEvuw==", "integrity": "sha512-Jk4hkc6CjHf7mc1lw3RCvZEBgw1trf/kJTiXaOin3wMFLTu9JUC+GTjif/nWLmJfZJTXqpv6utL3msO+YkzRYA==",
"requires": { "requires": {
"@apiglobal/typedrequest-interfaces": "^1.0.15", "@apiglobal/typedrequest-interfaces": "^1.0.15",
"@pushrocks/isounique": "^1.0.4", "@pushrocks/isounique": "^1.0.4",

View File

@ -21,7 +21,7 @@
"tslint-config-prettier": "^1.15.0" "tslint-config-prettier": "^1.15.0"
}, },
"dependencies": { "dependencies": {
"@apiglobal/typedrequest": "^1.0.49", "@apiglobal/typedrequest": "^1.0.50",
"@apiglobal/typedrequest-interfaces": "^1.0.15" "@apiglobal/typedrequest-interfaces": "^1.0.15"
}, },
"files": [ "files": [

View File

@ -3,9 +3,20 @@ import * as deesComms from '../ts/index';
let deesCommsTest: deesComms.DeesComms; let deesCommsTest: deesComms.DeesComms;
tap.test('first test', async () => { tap.test('first test', async (tools) => {
deesCommsTest = new deesComms.DeesComms(); deesCommsTest = new deesComms.DeesComms();
deesCommsTest; deesCommsTest.createTypedHandler<any>('test', async (requestData) => {
return {};
});
// lets fire a request
const typedrequest = deesCommsTest.createTypedRequest<any>('test');
const resultPromise = typedrequest.fire({
method: 'test',
request: {},
response: {}
});
await tools.delayFor(2000);
}); });
tap.start(); tap.start();

View File

@ -7,14 +7,14 @@ import * as plugins from './dees-comms.plugins';
export class DeesComms { export class DeesComms {
// sending messages // sending messages
private postChannel = new BroadcastChannel('dees-comms'); private postChannel = new BroadcastChannel('dees-comms');
private typedrouter = new plugins.typedrequest.TypedRouter(); public typedrouter = new plugins.typedrequest.TypedRouter();
private subscriptionChannel = new BroadcastChannel('dees-comms'); private subscriptionChannel = new BroadcastChannel('dees-comms');
constructor() { constructor() {
this.subscriptionChannel.onmessage = (eventArg) => { this.subscriptionChannel.onmessage = (eventArg) => {
const message = eventArg.data; const message = eventArg.data;
console.log(JSON.stringify(message));
this.typedrouter.routeAndAddResponse(message); this.typedrouter.routeAndAddResponse(message);
}; };
} }
@ -25,7 +25,13 @@ export class DeesComms {
public createTypedRequest<T extends plugins.typedrequestInterfaces.ITypedRequest>( public createTypedRequest<T extends plugins.typedrequestInterfaces.ITypedRequest>(
methodName: T['method'] methodName: T['method']
): TypedRequest<T> { ): TypedRequest<T> {
const typedrequest = new plugins.typedrequest.TypedRequest(this.postMessage, methodName, this.typedrouter); const typedrequest = new plugins.typedrequest.TypedRequest(
async (messageArg) => {
this.postMessage(messageArg);
},
methodName,
this.typedrouter
);
return typedrequest; return typedrequest;
} }
@ -41,5 +47,10 @@ export class DeesComms {
/** /**
* subscribe to messages * subscribe to messages
*/ */
public async subscribe() {} public async createTypedHandler<T extends plugins.typedrequestInterfaces.ITypedRequest>(
methodArg: T['method'],
handlerFunction: plugins.typedrequest.THandlerFunction<T>
) {
this.typedrouter.addTypedHandler(new plugins.typedrequest.TypedHandler<T>(methodArg, handlerFunction));
}
} }