@ichaingo/web-worker 1.3.96 → 1.3.97
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/dist/index.js +15 -15
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { createContext as
|
|
2
|
+
import { jsx as p } from "react/jsx-runtime";
|
|
3
|
+
import { createContext as k, useState as t, useEffect as f, useContext as i } from "react";
|
|
4
4
|
import { logger as g } from "@ichaingo/logger";
|
|
5
|
-
const a =
|
|
6
|
-
function
|
|
7
|
-
const [u, l] =
|
|
8
|
-
return
|
|
5
|
+
const a = k({ worker: null, message: null });
|
|
6
|
+
function w({ children: n }) {
|
|
7
|
+
const [u, l] = t(null), [c, m] = t(null);
|
|
8
|
+
return f(() => {
|
|
9
9
|
const e = new Worker(new URL(
|
|
10
10
|
/* @vite-ignore */
|
|
11
|
-
"
|
|
11
|
+
"./assets/webWorker-CvepzMkT.js",
|
|
12
12
|
import.meta.url
|
|
13
13
|
), { type: "module" });
|
|
14
14
|
return e.postMessage({ type: "INIT", data: { url: process.env.NEXT_PUBLIC_WS_URL, debug: !1 } }), e.onmessage = (r) => {
|
|
15
|
-
const { type:
|
|
16
|
-
if (
|
|
15
|
+
const { type: s, data: W } = (r == null ? void 0 : r.data) || {};
|
|
16
|
+
if (s === "INIT_OK")
|
|
17
17
|
l(e);
|
|
18
|
-
else if (
|
|
18
|
+
else if (s === "RECEIVE_MESSAGE")
|
|
19
19
|
try {
|
|
20
|
-
const o = JSON.parse(
|
|
21
|
-
|
|
20
|
+
const o = JSON.parse(W);
|
|
21
|
+
m(o);
|
|
22
22
|
} catch (o) {
|
|
23
23
|
g.error(o, "WebWorker", "parse message error");
|
|
24
24
|
}
|
|
@@ -27,12 +27,12 @@ function E({ children: n }) {
|
|
|
27
27
|
}, () => {
|
|
28
28
|
e.terminate();
|
|
29
29
|
};
|
|
30
|
-
}, []), /* @__PURE__ */
|
|
30
|
+
}, []), /* @__PURE__ */ p(a.Provider, { value: { worker: u, message: c }, children: n });
|
|
31
31
|
}
|
|
32
32
|
function C() {
|
|
33
|
-
return
|
|
33
|
+
return i(a);
|
|
34
34
|
}
|
|
35
35
|
export {
|
|
36
|
-
|
|
36
|
+
w as default,
|
|
37
37
|
C as useWebWorker
|
|
38
38
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ichaingo/web-worker",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.97",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"@ichaingo/
|
|
23
|
-
"@ichaingo/
|
|
22
|
+
"@ichaingo/logger": "1.3.97",
|
|
23
|
+
"@ichaingo/web-socket": "1.3.97"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"rollup-plugin-preserve-use-client": "^3.0.1"
|