Skip to content

Commit 4f1dcf7

Browse files
committed
Added a dedicated polyscript/xworker export
1 parent 516bafa commit 4f1dcf7

File tree

9 files changed

+25
-10
lines changed

9 files changed

+25
-10
lines changed

docs/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,11 @@ xworker.window.setTimeout(print, 100, "timers too")
385385

386386
ℹ️ - Please note that even if non blocking, if too many operations are orchestrated from a *worker*, instead of the *main* thread, the overall performance might still be slower due the communication channel and all the primitives involved in the synchronization process. Feel free to use the `window` feature as a great enabler for unthinkable or quick solutions but keep in mind it is still an indirection.
387387

388+
### Just the XWorker
389+
390+
If you only need the `XWorker` class from *JS*, or the internal `Hook` class to define custom worker (only) hooks remotely, you can `import { XWorker, Hook } from 'polyscript/xworker'` and see how far you can go with it.
391+
392+
388393
#### The `sync` utility
389394

390395
This helper does not interfere with the global context but it still ensure a function can be exposed form *main* and be used from *thread* and/or vice-versa.

docs/core.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/core.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

esm/custom.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import { registry as defaultRegistry, prefixes, configs } from './interpreters.j
77
import { getRuntimeID } from './loader.js';
88
import { io } from './interpreter/_utils.js';
99
import { addAllListeners } from './listeners.js';
10-
import { Hook } from './worker/hooks.js';
10+
import { Hook, XWorker } from './xworker.js';
1111
import workerURL from './worker/url.js';
12-
import XWorker from './xworker.js';
1312

1413
export const CUSTOM_SELECTORS = [];
1514

esm/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import { listener, addAllListeners } from './listeners.js';
99

1010
import { define as $define, whenDefined as $whenDefined } from './custom.js';
1111
import { env as $env } from './listeners.js';
12-
import { Hook as $Hook } from './worker/hooks.js';
13-
import $XWorker from './xworker.js';
12+
import { Hook as $Hook, XWorker as $XWorker } from './xworker.js';
1413

1514
// avoid multiple initialization of the same library
1615
const [

esm/worker/class.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as JSON from '@ungap/structured-clone/json';
22
import coincident from 'coincident/window';
33
import xworker from './xworker.js';
44
import { getConfigURLAndType } from '../loader.js';
5-
import { assign, defineProperties } from '../utils.js';
5+
import { assign, create, defineProperties } from '../utils.js';
66
import { getText } from '../fetch-utils.js';
77
import { Hook } from './hooks.js';
88

@@ -66,7 +66,7 @@ export default (...args) =>
6666
const { data } = event;
6767
if (data instanceof Error) {
6868
event.stopImmediatePropagation();
69-
worker.onerror(Object.create(event, {
69+
worker.onerror(create(event, {
7070
type: { value: 'error' },
7171
error: { value: data }
7272
}));

esm/xworker.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
import xworker from './worker/class.js';
2+
import { Hook } from './worker/hooks.js';
23

3-
export default xworker();
4+
const XWorker = xworker();
5+
6+
export { Hook, XWorker };

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@
6565
"import": "./esm/exports.js",
6666
"default": "./cjs/exports.js"
6767
},
68+
"./xworker": {
69+
"types": "./types/polyscript/esm/xworker.d.ts",
70+
"import": "./esm/xworker.js",
71+
"default": "./cjs/xworker.js"
72+
},
6873
"./package.json": "./package.json"
6974
},
7075
"dependencies": {

tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@
88
"emitDeclarationOnly": true,
99
"declarationDir": "types"
1010
},
11-
"include": ["esm/index.js", "esm/exports.js"]
11+
"include": [
12+
"esm/index.js",
13+
"esm/exports.js",
14+
"esm/xworker.js"
15+
]
1216
}

0 commit comments

Comments
 (0)