10 Commits

Author SHA1 Message Date
20dcc9dc00 1.0.7 2020-10-07 13:01:11 +00:00
f273094369 fix(core): update 2020-10-07 13:01:09 +00:00
7fb3688cb9 1.0.6 2020-10-06 21:49:04 +00:00
ddf28a8d0e fix(core): update 2020-10-06 21:49:03 +00:00
b26aa04388 1.0.5 2020-10-06 17:18:21 +00:00
3726e29768 fix(core): update 2020-10-06 17:18:20 +00:00
e500c8a7f6 1.0.4 2020-10-06 16:25:44 +00:00
243d1f17a3 fix(core): update 2020-10-06 16:25:44 +00:00
a04cafdb63 1.0.3 2020-10-06 16:23:41 +00:00
1832377126 fix(core): update 2020-10-06 16:23:41 +00:00
6 changed files with 298 additions and 335 deletions

562
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "@designestate/dees-comms",
"version": "1.0.2",
"version": "1.0.7",
"private": false,
"description": "a comms module for communicating within the DOM",
"main": "dist_ts/index.js",
@@ -21,8 +21,9 @@
"tslint-config-prettier": "^1.15.0"
},
"dependencies": {
"@apiglobal/typedrequest": "^1.0.49",
"@apiglobal/typedrequest-interfaces": "^1.0.15"
"@apiglobal/typedrequest": "^1.0.53",
"@apiglobal/typedrequest-interfaces": "^1.0.15",
"broadcast-channel": "^3.2.0"
},
"files": [
"ts/**/*",

View File

@@ -3,8 +3,18 @@ import * as deesComms from '../ts/index';
let deesCommsTest: deesComms.DeesComms;
tap.test('first test', async () => {
tap.test('first test', async (tools) => {
deesCommsTest = new deesComms.DeesComms();
deesCommsTest.createTypedHandler<any>('test', async (requestData) => {
return {'hitheretoo': 'greetings'};
});
// lets fire a request
const typedrequest = deesCommsTest.createTypedRequest<any>('test');
const result = await typedrequest.fire({
'hithere': 'hello'
});
console.log(JSON.stringify(result));
});
tap.start();

View File

@@ -1,21 +1,29 @@
import { TypedRequest } from '@apiglobal/typedrequest';
import * as plugins from './dees-comms.plugins';
let BroadcastChannel = globalThis.BroadcastChannel;
if (!BroadcastChannel) {
BroadcastChannel = plugins.BroadCastChannelPolyfill as any;
}
/**
* a comm class for client side communication between workers and tabs.
*/
export class DeesComms {
// sending messages
private postChannel = new BroadcastChannel('dees-comms');
private typedrouter = new plugins.typedrequest.TypedRouter();
public typedrouter = new plugins.typedrequest.TypedRouter();
private subscriptionChannel = new BroadcastChannel('dees-comms');
constructor() {
this.subscriptionChannel.onmessage = (eventArg) => {
this.subscriptionChannel.onmessage = async (eventArg) => {
const message = eventArg.data;
this.typedrouter.routeAndAddResponse(message);
console.log(JSON.stringify(message));
const response = await this.typedrouter.routeAndAddResponse(message);
if (response) {
this.postMessage(response);
}
};
}
@@ -25,7 +33,13 @@ export class DeesComms {
public createTypedRequest<T extends plugins.typedrequestInterfaces.ITypedRequest>(
methodName: T['method']
): 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;
}
@@ -41,5 +55,10 @@ export class DeesComms {
/**
* 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));
}
}

View File

@@ -3,3 +3,10 @@ import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces';
import * as typedrequest from '@apiglobal/typedrequest';
export { typedrequestInterfaces, typedrequest };
// thirdparty scope
import { BroadcastChannel as BroadCastChannelPolyfill } from 'broadcast-channel';
export {
BroadCastChannelPolyfill
};

View File

@@ -1,11 +1 @@
import * as plugins from './dees-comms.plugins';
/**
* a comm class for client side communication between workers and tabs.
*/
export class DeesComms {
public postChannel = new BroadcastChannel('dees-comms');
public subscriptionChannel = new BroadcastChannel('dees-comms');
public async postMessage() {}
}
export * from './dees-comms.classes.deescomms';