Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d1149d3877 | |||
| 758dcd671c | |||
| 4c59d38971 | |||
| 385acfd951 | |||
| 97eba85337 | |||
| 61936bbdd1 | |||
| 4ab1b917a9 | |||
| f299cff4c9 |
19287
package-lock.json
generated
19287
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
23
package.json
23
package.json
@@ -1,28 +1,29 @@
|
||||
{
|
||||
"name": "@designestate/dees-comms",
|
||||
"version": "1.0.14",
|
||||
"version": "1.0.18",
|
||||
"private": false,
|
||||
"description": "a comms module for communicating within the DOM",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/ --web)",
|
||||
"build": "(tsbuild --web && tsbundle npm)"
|
||||
"build": "(tsbuild --web --allowimplicitany && tsbundle npm)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.29",
|
||||
"@gitzone/tsbundle": "^1.0.89",
|
||||
"@gitzone/tstest": "^1.0.60",
|
||||
"@pushrocks/tapbundle": "^4.0.0",
|
||||
"@types/node": "^17.0.10",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.15.0"
|
||||
"@gitzone/tsbuild": "^2.1.61",
|
||||
"@gitzone/tsbundle": "^1.0.102",
|
||||
"@gitzone/tstest": "^1.0.70",
|
||||
"@pushrocks/tapbundle": "^5.0.3",
|
||||
"@types/node": "^17.0.23"
|
||||
},
|
||||
"dependencies": {
|
||||
"@apiglobal/typedrequest": "^1.0.65",
|
||||
"@apiglobal/typedrequest-interfaces": "^1.0.15"
|
||||
"@apiglobal/typedrequest": "^2.0.1",
|
||||
"@apiglobal/typedrequest-interfaces": "^1.0.15",
|
||||
"@pushrocks/smartdelay": "^2.0.13",
|
||||
"broadcast-channel": "^3.7.0"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as deesComms from '../ts/index';
|
||||
import * as deesComms from '../ts/index.js';
|
||||
|
||||
let deesCommsTest: deesComms.DeesComms;
|
||||
|
||||
tap.test('first test', async (tools) => {
|
||||
deesCommsTest = new deesComms.DeesComms();
|
||||
let counter = 1;
|
||||
deesCommsTest.createTypedHandler<any>('test', async (requestData) => {
|
||||
console.log(`got the request ${counter++}`);
|
||||
return { hitheretoo: `greetings to ${requestData.hithere}` };
|
||||
});
|
||||
|
||||
@@ -15,6 +17,15 @@ tap.test('first test', async (tools) => {
|
||||
hithere: 'hello',
|
||||
});
|
||||
console.log(JSON.stringify(result));
|
||||
|
||||
// lets fire a request
|
||||
const typedrequest2 = deesCommsTest.createTypedRequest<any>('test2');
|
||||
// TODO: return response after timeout
|
||||
/* const result2 = await typedrequest2.fire({
|
||||
hithere: 'hello',
|
||||
});
|
||||
console.log(JSON.stringify(result2)); */
|
||||
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { TypedRequest } from '@apiglobal/typedrequest';
|
||||
import * as plugins from './dees-comms.plugins';
|
||||
import * as plugins from './dees-comms.plugins.js';
|
||||
|
||||
let BroadcastChannel = globalThis.BroadcastChannel;
|
||||
if (!BroadcastChannel) {
|
||||
BroadcastChannel = plugins.BroadCastChannelPolyfill as any;
|
||||
}
|
||||
|
||||
/**
|
||||
* a comm class for client side communication between workers and tabs.
|
||||
@@ -15,11 +20,12 @@ export class DeesComms {
|
||||
typedRouterRef: this.typedrouter,
|
||||
});
|
||||
|
||||
// receiving messages
|
||||
private subscriptionChannel = new BroadcastChannel('dees-comms');
|
||||
|
||||
|
||||
constructor() {
|
||||
this.subscriptionChannel.onmessage = async (eventArg) => {
|
||||
const message = eventArg.data;
|
||||
const message = (eventArg as any).method ? eventArg : eventArg.data;
|
||||
console.log(JSON.stringify(message));
|
||||
const response = await this.typedrouter.routeAndAddResponse(message);
|
||||
if (response) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import * as plugins from './dees-comms.plugins';
|
||||
import * as plugins from './dees-comms.plugins.js';
|
||||
|
||||
/**
|
||||
* a message that can be sent
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
// pushrocks scope
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces';
|
||||
import * as typedrequest from '@apiglobal/typedrequest';
|
||||
|
||||
export { typedrequestInterfaces, typedrequest };
|
||||
export { smartdelay, typedrequestInterfaces, typedrequest };
|
||||
|
||||
// third party scope
|
||||
import { BroadcastChannel as BroadCastChannelPolyfill } from 'broadcast-channel';
|
||||
|
||||
export {
|
||||
BroadCastChannelPolyfill
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
export * from './dees-comms.classes.deescomms';
|
||||
export * from './dees-comms.classes.deescomms.js';
|
||||
|
||||
9
tsconfig.json
Normal file
9
tsconfig.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext"
|
||||
}
|
||||
}
|
||||
17
tslint.json
17
tslint.json
@@ -1,17 +0,0 @@
|
||||
{
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
||||
Reference in New Issue
Block a user