@webreflection/bindings 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @webreflection/bindings
2
2
 
3
+ [![Coverage Status](https://coveralls.io/repos/github/WebReflection/bindings/badge.svg?branch=main)](https://coveralls.io/github/WebReflection/bindings?branch=main)
4
+
3
5
  A (soon to be) collection of bindings for various scenarios.
4
6
 
5
7
  ### Example
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webreflection/bindings",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "A (soon to be) collection of bindings for various scenarios.",
5
5
  "types": {
6
6
  "./message-port": "./src/message-port.d.ts"
@@ -24,12 +24,18 @@
24
24
  "license": "MIT",
25
25
  "type": "module",
26
26
  "scripts": {
27
- "test": "node test/verify-runtime.mjs"
27
+ "coverage": "mkdir -p ./coverage; c8 report --reporter=text-lcov > ./coverage/lcov.info",
28
+ "test": "c8 node test/verify-runtime.mjs"
28
29
  },
29
30
  "dependencies": {
30
31
  "@webreflection/utils": "^0.3.6",
31
32
  "next-resolver": "^0.2.2"
32
33
  },
34
+ "overrides": {
35
+ "c8": {
36
+ "yargs": "^18.0.0"
37
+ }
38
+ },
33
39
  "main": "index.js",
34
40
  "repository": {
35
41
  "type": "git",
@@ -38,5 +44,8 @@
38
44
  "bugs": {
39
45
  "url": "https://github.com/WebReflection/bindings/issues"
40
46
  },
41
- "homepage": "https://github.com/WebReflection/bindings#readme"
47
+ "homepage": "https://github.com/WebReflection/bindings#readme",
48
+ "devDependencies": {
49
+ "c8": "^11.0.0"
50
+ }
42
51
  }
@@ -1,6 +1,7 @@
1
1
  //@ts-check
2
2
 
3
3
  import nextResolver from 'next-resolver';
4
+ import Map from '@webreflection/utils/map';
4
5
  import { nil } from '@webreflection/utils/empty';
5
6
 
6
7
  const { defineProperty } = Object;
@@ -44,7 +45,7 @@ const bindings = (port, local) => {
44
45
  // secure the postMessage method to avoid potential
45
46
  // MessagePort.prototype.postMessage overrides interfering
46
47
  // with the communication channel
47
- const post = port.postMessage.bind(port);
48
+ const post = port.postMessage.bind(port), $ = new Map;
48
49
 
49
50
  let opts = nil;
50
51
 
@@ -66,13 +67,11 @@ const bindings = (port, local) => {
66
67
  };
67
68
 
68
69
  return /** @type {import('./message-port.js').RemoteProxy<Remote>} */(new Proxy(nil, {
69
- get(_, name) {
70
- return (/** @type {any[]} */ ...args) => {
71
- const [id, promise] = next();
72
- post([true, id, name, args]);
73
- return promise;
74
- };
75
- }
70
+ get: (_, name) => $.get(name) ?? $.put(name, (/** @type {any[]} */ ...args) => {
71
+ const [id, promise] = next();
72
+ post([true, id, name, args]);
73
+ return promise;
74
+ }),
76
75
  }));
77
76
  };
78
77