@atolljs/core 0.1.6 → 0.1.7
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/contract/sharedMemory.d.ts +2 -0
- package/dist/contract/types.d.ts +2 -0
- package/dist/devtools.d.ts +223 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +17 -16
- package/dist/index10.js +14 -185
- package/dist/index11.js +310 -47
- package/dist/index12.js +46 -59
- package/dist/index13.js +59 -20
- package/dist/index14.js +24 -60
- package/dist/index15.js +56 -43
- package/dist/index16.js +44 -50
- package/dist/index17.js +52 -38
- package/dist/index18.js +36 -83
- package/dist/index19.js +81 -47
- package/dist/index20.js +48 -51
- package/dist/index21.js +57 -0
- package/dist/index5.js +156 -35
- package/dist/index6.js +32 -485
- package/dist/index7.js +508 -19
- package/dist/index8.js +19 -33
- package/dist/index9.js +29 -14
- package/dist/pool/workerClient.d.ts +2 -0
- package/dist/pool/workerPool.d.ts +4 -0
- package/package.json +1 -1
- package/src/contract/sharedMemory.ts +19 -3
- package/src/contract/types.ts +2 -0
- package/src/devtools.ts +490 -0
- package/src/index.ts +14 -0
- package/src/pool/workerClient.ts +3 -0
- package/src/pool/workerPool.ts +56 -7
- package/src/worker/workerBootstrap.ts +3 -0
package/dist/index15.js
CHANGED
|
@@ -1,48 +1,61 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { fmtBytes as e, scoped as t } from "./index6.js";
|
|
2
|
+
import { bindSharedMemories as n } from "./index7.js";
|
|
3
|
+
import { MemoryManager as r } from "./index9.js";
|
|
4
|
+
import { TaskRegistry as i } from "./index14.js";
|
|
5
|
+
//#region src/shared/sharedWorkerHost.ts
|
|
6
|
+
var a = t("shared-worker"), o = null, s = 0;
|
|
7
|
+
function c(t, i) {
|
|
8
|
+
if (o) return o.buffer.byteLength < t && a.warn(`client requested ${e(t)} but buffer is ${e(o.buffer.byteLength)} — first client's capacity wins`), o;
|
|
9
|
+
let s = new r(i);
|
|
10
|
+
return s.ensureCapacity(t), o = s.memory, n(s.getBuffer()), a.info(`shared buffer allocated (${e(o.buffer.byteLength)})`), o;
|
|
7
11
|
}
|
|
8
|
-
function
|
|
9
|
-
|
|
12
|
+
function l(e) {
|
|
13
|
+
let t = ++s;
|
|
14
|
+
a.info(`client #${t} connected`), e.onmessage = async (n) => {
|
|
15
|
+
let r = n.data;
|
|
16
|
+
if (r?.type === "SHARED_CONNECT") {
|
|
17
|
+
let n = c(r.memoryBytes ?? 0, r.memory);
|
|
18
|
+
e.postMessage({
|
|
19
|
+
type: "SHARED_MEMORY",
|
|
20
|
+
buffer: n.buffer,
|
|
21
|
+
clientIndex: t
|
|
22
|
+
});
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (r?.type === "EXECUTE_TASK") {
|
|
26
|
+
let { messageId: n, taskId: s, args: c } = r;
|
|
27
|
+
if (!o) {
|
|
28
|
+
e.postMessage({
|
|
29
|
+
messageId: n,
|
|
30
|
+
success: !1,
|
|
31
|
+
error: "Shared memory not initialized in worker."
|
|
32
|
+
});
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
let l = performance.now();
|
|
36
|
+
try {
|
|
37
|
+
let r = await i.execute(s, ...c || []);
|
|
38
|
+
a.debug(`task ${s} → ${(performance.now() - l).toFixed(1)}ms (client #${t})`), e.postMessage({
|
|
39
|
+
messageId: n,
|
|
40
|
+
success: !0,
|
|
41
|
+
result: r
|
|
42
|
+
});
|
|
43
|
+
} catch (t) {
|
|
44
|
+
a.warn(`task ${s} failed: ${t.message || String(t)}`), e.postMessage({
|
|
45
|
+
messageId: n,
|
|
46
|
+
success: !1,
|
|
47
|
+
error: t.message || String(t)
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
r?.type === "SHARED_DISCONNECT" && (e.close(), a.info(`client #${t} disconnected`));
|
|
53
|
+
}, e.start();
|
|
10
54
|
}
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let t = "def" in i ? i.def : i;
|
|
15
|
-
n[r] = {
|
|
16
|
-
taskId: t.taskId ?? `${e}.${r}`,
|
|
17
|
-
...t.dataType ? { dataType: t.dataType } : {},
|
|
18
|
-
...t.argsSchema ? { argsSchema: t.argsSchema } : {},
|
|
19
|
-
...t.resultSchema ? { resultSchema: t.resultSchema } : {}
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
name: e,
|
|
24
|
-
tasks: n
|
|
55
|
+
function u() {
|
|
56
|
+
self.onconnect = (e) => {
|
|
57
|
+
l(e.ports[0]);
|
|
25
58
|
};
|
|
26
59
|
}
|
|
27
|
-
function o(e, r) {
|
|
28
|
-
let i = Object.keys(e.tasks).filter((e) => {
|
|
29
|
-
let t = r[e];
|
|
30
|
-
return typeof t != "function" && typeof t?.run != "function";
|
|
31
|
-
});
|
|
32
|
-
if (i.length > 0) throw Error(`implementService("${e.name}"): missing handlers for ${i.join(", ")}`);
|
|
33
|
-
for (let [n, i] of Object.entries(e.tasks)) {
|
|
34
|
-
let e = r[n];
|
|
35
|
-
t.register(i, typeof e == "function" ? e.bind(r) : e.run.bind(e));
|
|
36
|
-
}
|
|
37
|
-
return n.info(`service "${e.name}" implemented — ${Object.keys(e.tasks).join(", ")}`), {
|
|
38
|
-
service: e,
|
|
39
|
-
handlers: r
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function s(e, t) {
|
|
43
|
-
let n = {};
|
|
44
|
-
for (let [r, i] of Object.entries(e.tasks)) n[r] = (...e) => t.runTask(i, ...e);
|
|
45
|
-
return n;
|
|
46
|
-
}
|
|
47
60
|
//#endregion
|
|
48
|
-
export {
|
|
61
|
+
export { l as attachSharedPort, u as sharedWorkerHost };
|
package/dist/index16.js
CHANGED
|
@@ -1,54 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
n(t.buffer), o = !0, a.info(`shared memory initialized (${e(t.buffer.byteLength)})`);
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
if (s.type === "EXECUTE_TASK") {
|
|
24
|
-
let { messageId: e, taskId: t, args: n } = s;
|
|
25
|
-
if (!o) {
|
|
26
|
-
a.warn(`rejected ${t} — shared memory not initialized`), self.postMessage({
|
|
27
|
-
messageId: e,
|
|
28
|
-
success: !1,
|
|
29
|
-
error: "Shared memory not initialized in worker."
|
|
30
|
-
});
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
let r = performance.now();
|
|
34
|
-
try {
|
|
35
|
-
let o = await i.execute(t, ...n || []);
|
|
36
|
-
a.debug(`task ${t} → ${(performance.now() - r).toFixed(1)}ms`), self.postMessage({
|
|
37
|
-
messageId: e,
|
|
38
|
-
success: !0,
|
|
39
|
-
result: o
|
|
40
|
-
});
|
|
41
|
-
} catch (n) {
|
|
42
|
-
a.warn(`task ${t} failed: ${n.message || String(n)}`), self.postMessage({
|
|
43
|
-
messageId: e,
|
|
44
|
-
success: !1,
|
|
45
|
-
error: n.message || String(n)
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
1
|
+
import { scoped as e } from "./index6.js";
|
|
2
|
+
import { TaskRegistry as t } from "./index14.js";
|
|
3
|
+
//#region src/service.ts
|
|
4
|
+
var n = e("service");
|
|
5
|
+
function r(e = {}) {
|
|
6
|
+
return e;
|
|
7
|
+
}
|
|
8
|
+
function i(e) {
|
|
9
|
+
return e;
|
|
10
|
+
}
|
|
11
|
+
function a(e, t) {
|
|
12
|
+
let n = {};
|
|
13
|
+
for (let [r, i] of Object.entries(t)) {
|
|
14
|
+
let t = "def" in i ? i.def : i;
|
|
15
|
+
n[r] = {
|
|
16
|
+
taskId: t.taskId ?? `${e}.${r}`,
|
|
17
|
+
...t.dataType ? { dataType: t.dataType } : {},
|
|
18
|
+
...t.argsSchema ? { argsSchema: t.argsSchema } : {},
|
|
19
|
+
...t.resultSchema ? { resultSchema: t.resultSchema } : {}
|
|
49
20
|
};
|
|
50
21
|
}
|
|
22
|
+
return {
|
|
23
|
+
name: e,
|
|
24
|
+
tasks: n
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function o(e, r) {
|
|
28
|
+
let i = Object.keys(e.tasks).filter((e) => {
|
|
29
|
+
let t = r[e];
|
|
30
|
+
return typeof t != "function" && typeof t?.run != "function";
|
|
31
|
+
});
|
|
32
|
+
if (i.length > 0) throw Error(`implementService("${e.name}"): missing handlers for ${i.join(", ")}`);
|
|
33
|
+
for (let [n, i] of Object.entries(e.tasks)) {
|
|
34
|
+
let e = r[n];
|
|
35
|
+
t.register(i, typeof e == "function" ? e.bind(r) : e.run.bind(e));
|
|
36
|
+
}
|
|
37
|
+
return n.info(`service "${e.name}" implemented — ${Object.keys(e.tasks).join(", ")}`), {
|
|
38
|
+
service: e,
|
|
39
|
+
handlers: r
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function s(e, t) {
|
|
43
|
+
let n = {};
|
|
44
|
+
for (let [r, i] of Object.entries(e.tasks)) n[r] = (...e) => t.runTask(i, ...e);
|
|
45
|
+
return n;
|
|
51
46
|
}
|
|
52
|
-
c();
|
|
53
47
|
//#endregion
|
|
54
|
-
export {
|
|
48
|
+
export { s as createClient, a as defineService, o as implementService, r as rpc, i as serviceMethod };
|
package/dist/index17.js
CHANGED
|
@@ -1,41 +1,55 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
import { enableWorkerDevtoolsForwarding as e } from "./index5.js";
|
|
2
|
+
import { fmtBytes as t, scoped as n } from "./index6.js";
|
|
3
|
+
import { bindSharedMemories as r, getDefinedSharedMemoryCount as i } from "./index7.js";
|
|
4
|
+
import { TaskRegistry as a } from "./index14.js";
|
|
5
|
+
//#region src/worker/workerBootstrap.ts
|
|
6
|
+
var o = n("worker"), s = !1, c = !1;
|
|
7
|
+
function l() {
|
|
8
|
+
if (!c) {
|
|
9
|
+
if (typeof self > "u") {
|
|
10
|
+
o.warn("workerBootstrap: no worker global found — skipping message wiring");
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
c = !0, self.onmessage = async (n) => {
|
|
14
|
+
let c = n.data;
|
|
15
|
+
if (c.type === "INIT") {
|
|
16
|
+
s = !0, c.devtools && e(), i() > 0 && o.warn("pool sent INIT without memory, but shared-memory contracts are defined — field access will throw until bound"), o.info("initialized (message-only pool — no shared memory)");
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (c.type === "INIT_MEMORY") {
|
|
20
|
+
let n = c.memory;
|
|
21
|
+
r(n.buffer), s = !0, c.devtools && e(), o.info(`shared memory initialized (${t(n.buffer.byteLength)})`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (c.type === "EXECUTE_TASK") {
|
|
25
|
+
let { messageId: e, taskId: t, args: n } = c;
|
|
26
|
+
if (!s) {
|
|
27
|
+
o.warn(`rejected ${t} — shared memory not initialized`), self.postMessage({
|
|
28
|
+
messageId: e,
|
|
29
|
+
success: !1,
|
|
30
|
+
error: "Shared memory not initialized in worker."
|
|
31
|
+
});
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
let r = performance.now();
|
|
35
|
+
try {
|
|
36
|
+
let i = await a.execute(t, ...n || []);
|
|
37
|
+
o.debug(`task ${t} → ${(performance.now() - r).toFixed(1)}ms`), self.postMessage({
|
|
38
|
+
messageId: e,
|
|
39
|
+
success: !0,
|
|
40
|
+
result: i
|
|
41
|
+
});
|
|
42
|
+
} catch (n) {
|
|
43
|
+
o.warn(`task ${t} failed: ${n.message || String(n)}`), self.postMessage({
|
|
44
|
+
messageId: e,
|
|
45
|
+
success: !1,
|
|
46
|
+
error: n.message || String(n)
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
32
51
|
}
|
|
33
|
-
r.info(`worker defined — ${c} method(s)`);
|
|
34
|
-
let u = {
|
|
35
|
-
methods: i,
|
|
36
|
-
services: s
|
|
37
|
-
};
|
|
38
|
-
return e.sharedMemory && (u.sharedMemory = e.sharedMemory), u;
|
|
39
52
|
}
|
|
53
|
+
l();
|
|
40
54
|
//#endregion
|
|
41
|
-
export {
|
|
55
|
+
export { l as installWorkerListener };
|
package/dist/index18.js
CHANGED
|
@@ -1,88 +1,41 @@
|
|
|
1
|
-
import { scoped as e } from "./
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
e !== i && (i = e, t());
|
|
28
|
-
}, 50);
|
|
29
|
-
return () => {
|
|
30
|
-
r = !0, clearInterval(a);
|
|
1
|
+
import { scoped as e } from "./index6.js";
|
|
2
|
+
import { TaskRegistry as t } from "./index14.js";
|
|
3
|
+
import { installWorkerListener as n } from "./index17.js";
|
|
4
|
+
//#region src/worker/defineWorker.ts
|
|
5
|
+
var r = e("worker"), i = [
|
|
6
|
+
"start",
|
|
7
|
+
"terminate",
|
|
8
|
+
"pool",
|
|
9
|
+
"sharedMemory",
|
|
10
|
+
"then",
|
|
11
|
+
"with"
|
|
12
|
+
], a = (e) => typeof e == "object" && !!e && "run" in e, o = new Set(i);
|
|
13
|
+
function s(e) {
|
|
14
|
+
n();
|
|
15
|
+
let i = e.methods ?? {}, s = e.services ?? {}, c = 0, l = (e, n, r, i) => {
|
|
16
|
+
if (o.has(n)) throw Error(`defineWorker: "${n}" is reserved for the client API — rename the method`);
|
|
17
|
+
if (a(r)) {
|
|
18
|
+
let { def: n } = r;
|
|
19
|
+
t.register({
|
|
20
|
+
taskId: n.taskId ?? e,
|
|
21
|
+
...n.dataType ? { dataType: n.dataType } : {},
|
|
22
|
+
...n.argsSchema ? { argsSchema: n.argsSchema } : {},
|
|
23
|
+
...n.resultSchema ? { resultSchema: n.resultSchema } : {}
|
|
24
|
+
}, r.run.bind(r));
|
|
25
|
+
} else t.register({ taskId: e }, r.bind(i));
|
|
26
|
+
c++;
|
|
31
27
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
let e
|
|
36
|
-
i(() => {
|
|
37
|
-
let [n, i] = a(0);
|
|
38
|
-
t = i, r(() => {
|
|
39
|
-
n(), e++;
|
|
40
|
-
});
|
|
41
|
-
}), t?.(1), l = e > 1;
|
|
42
|
-
} catch {
|
|
43
|
-
l = !1;
|
|
44
|
-
}
|
|
45
|
-
return l || o.warn("solid-js resolved to the SSR build — watch() falls back to direct version watching"), l;
|
|
46
|
-
};
|
|
47
|
-
function d(e) {
|
|
48
|
-
let [t, n] = a(e.read(), { equals: !1 }), r = () => n(() => e.read());
|
|
49
|
-
return {
|
|
50
|
-
get: t,
|
|
51
|
-
peek: () => e.read(),
|
|
52
|
-
set: (t) => {
|
|
53
|
-
e.write(t), r();
|
|
54
|
-
},
|
|
55
|
-
observeRemote: () => c(e, r)
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
function f(e, r, a, s) {
|
|
59
|
-
let l = a ? r : ((e) => e), f = a ?? r;
|
|
60
|
-
if (!u()) {
|
|
61
|
-
let t = (e, t) => e === void 0 || t === void 0 ? e === t : (s?.equals ?? Object.is)(e, t), n, r = () => {
|
|
62
|
-
let r = e.read(), i = r == null ? void 0 : l(r);
|
|
63
|
-
if (i === void 0 || t(n, i)) return;
|
|
64
|
-
let a = n;
|
|
65
|
-
n = i, f(i, a);
|
|
66
|
-
};
|
|
67
|
-
r();
|
|
68
|
-
let i = c(e, r);
|
|
69
|
-
return o.debug(`watching connector at offset ${e.byteOffset} (direct)`), () => {
|
|
70
|
-
o.debug(`watch stopped (offset ${e.byteOffset})`), i();
|
|
71
|
-
};
|
|
28
|
+
for (let [e, t] of Object.entries(i)) l(e, e, t, i);
|
|
29
|
+
for (let [e, t] of Object.entries(s)) {
|
|
30
|
+
if (o.has(e)) throw Error(`defineWorker: service name "${e}" is reserved for the client API — rename it`);
|
|
31
|
+
for (let [n, r] of Object.entries(t)) l(`${e}.${n}`, n, r, t);
|
|
72
32
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}, void 0, s?.equals ? { equals: (e, t) => e === void 0 || t === void 0 ? e === t : s.equals(e, t) } : void 0);
|
|
78
|
-
return t((e) => {
|
|
79
|
-
let t = r();
|
|
80
|
-
return t !== void 0 && f(t, e), t;
|
|
81
|
-
}), e;
|
|
82
|
-
});
|
|
83
|
-
return o.debug(`watching connector at offset ${e.byteOffset}`), () => {
|
|
84
|
-
o.debug(`watch stopped (offset ${e.byteOffset})`), m(), h();
|
|
33
|
+
r.info(`worker defined — ${c} method(s)`);
|
|
34
|
+
let u = {
|
|
35
|
+
methods: i,
|
|
36
|
+
services: s
|
|
85
37
|
};
|
|
38
|
+
return e.sharedMemory && (u.sharedMemory = e.sharedMemory), u;
|
|
86
39
|
}
|
|
87
40
|
//#endregion
|
|
88
|
-
export {
|
|
41
|
+
export { i as RESERVED_CLIENT_KEYS, s as defineWorker };
|
package/dist/index19.js
CHANGED
|
@@ -1,54 +1,88 @@
|
|
|
1
|
-
import { scoped as e } from "./
|
|
2
|
-
import {
|
|
3
|
-
//#region src/
|
|
4
|
-
var
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import { scoped as e } from "./index6.js";
|
|
2
|
+
import { createEffect as t, createMemo as n, createRenderEffect as r, createRoot as i, createSignal as a } from "solid-js";
|
|
3
|
+
//#region src/reactive.ts
|
|
4
|
+
var o = e("reactive");
|
|
5
|
+
function s(e, t) {
|
|
6
|
+
if (e === t) return !0;
|
|
7
|
+
if (e == null || t == null) return !1;
|
|
8
|
+
let n = Object.keys(e), r = Object.keys(t);
|
|
9
|
+
return n.length === r.length && n.every((n) => Object.is(e[n], t[n]));
|
|
10
|
+
}
|
|
11
|
+
var c = (e, t) => {
|
|
12
|
+
let n = e._version;
|
|
13
|
+
if (!n) throw Error("This connector does not support remote observation.");
|
|
14
|
+
let r = !1, i = Atomics.load(n.view, n.index);
|
|
15
|
+
if (typeof Atomics.waitAsync == "function") return o.debug(`observing remote writes (offset ${e.byteOffset}, waitAsync)`), (async () => {
|
|
16
|
+
for (; !r;) {
|
|
17
|
+
let a = Atomics.waitAsync(n.view, n.index, i);
|
|
18
|
+
a.async && await a.value, i = Atomics.load(n.view, n.index), r || (o.trace(`remote write observed (offset ${e.byteOffset})`), t());
|
|
16
19
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
for (let t of m) t(e);
|
|
21
|
-
}
|
|
22
|
-
}, a), p = i, f ??= e.onBound(() => {
|
|
23
|
-
let t;
|
|
24
|
-
try {
|
|
25
|
-
t = e.connector(String(r));
|
|
26
|
-
} catch {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
t !== p && (u?.(), u = null, p = null, h());
|
|
30
|
-
}), n.debug(`observing "${String(r)}" (offset ${i.byteOffset})`);
|
|
31
|
-
}, g = () => {
|
|
32
|
-
u?.(), u = null, p = null, d?.(), d = null, f?.(), f = null;
|
|
20
|
+
o.debug(`stopped observing (offset ${e.byteOffset})`);
|
|
21
|
+
})(), () => {
|
|
22
|
+
r = !0;
|
|
33
23
|
};
|
|
24
|
+
o.warn(`Atomics.waitAsync unavailable — observing via 50ms poll (offset ${e.byteOffset})`);
|
|
25
|
+
let a = setInterval(() => {
|
|
26
|
+
let e = Atomics.load(n.view, n.index);
|
|
27
|
+
e !== i && (i = e, t());
|
|
28
|
+
}, 50);
|
|
29
|
+
return () => {
|
|
30
|
+
r = !0, clearInterval(a);
|
|
31
|
+
};
|
|
32
|
+
}, l = null, u = () => {
|
|
33
|
+
if (l !== null) return l;
|
|
34
|
+
try {
|
|
35
|
+
let e = 0, t;
|
|
36
|
+
i(() => {
|
|
37
|
+
let [n, i] = a(0);
|
|
38
|
+
t = i, r(() => {
|
|
39
|
+
n(), e++;
|
|
40
|
+
});
|
|
41
|
+
}), t?.(1), l = e > 1;
|
|
42
|
+
} catch {
|
|
43
|
+
l = !1;
|
|
44
|
+
}
|
|
45
|
+
return l || o.warn("solid-js resolved to the SSR build — watch() falls back to direct version watching"), l;
|
|
46
|
+
};
|
|
47
|
+
function d(e) {
|
|
48
|
+
let [t, n] = a(e.read(), { equals: !1 }), r = () => n(() => e.read());
|
|
34
49
|
return {
|
|
35
|
-
get
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
l = n;
|
|
40
|
-
let e = o(t.read());
|
|
41
|
-
(c === void 0 || !s(c, e)) && (c = e);
|
|
42
|
-
}
|
|
43
|
-
} catch {}
|
|
44
|
-
return c;
|
|
50
|
+
get: t,
|
|
51
|
+
peek: () => e.read(),
|
|
52
|
+
set: (t) => {
|
|
53
|
+
e.write(t), r();
|
|
45
54
|
},
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
observeRemote: () => c(e, r)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function f(e, r, a, s) {
|
|
59
|
+
let l = a ? r : ((e) => e), f = a ?? r;
|
|
60
|
+
if (!u()) {
|
|
61
|
+
let t = (e, t) => e === void 0 || t === void 0 ? e === t : (s?.equals ?? Object.is)(e, t), n, r = () => {
|
|
62
|
+
let r = e.read(), i = r == null ? void 0 : l(r);
|
|
63
|
+
if (i === void 0 || t(n, i)) return;
|
|
64
|
+
let a = n;
|
|
65
|
+
n = i, f(i, a);
|
|
66
|
+
};
|
|
67
|
+
r();
|
|
68
|
+
let i = c(e, r);
|
|
69
|
+
return o.debug(`watching connector at offset ${e.byteOffset} (direct)`), () => {
|
|
70
|
+
o.debug(`watch stopped (offset ${e.byteOffset})`), i();
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
let p = d(e), m = p.observeRemote(), h = i((e) => {
|
|
74
|
+
let r = n(() => {
|
|
75
|
+
let e = p.get();
|
|
76
|
+
return e == null ? void 0 : l(e);
|
|
77
|
+
}, void 0, s?.equals ? { equals: (e, t) => e === void 0 || t === void 0 ? e === t : s.equals(e, t) } : void 0);
|
|
78
|
+
return t((e) => {
|
|
79
|
+
let t = r();
|
|
80
|
+
return t !== void 0 && f(t, e), t;
|
|
81
|
+
}), e;
|
|
82
|
+
});
|
|
83
|
+
return o.debug(`watching connector at offset ${e.byteOffset}`), () => {
|
|
84
|
+
o.debug(`watch stopped (offset ${e.byteOffset})`), m(), h();
|
|
51
85
|
};
|
|
52
86
|
}
|
|
53
87
|
//#endregion
|
|
54
|
-
export {
|
|
88
|
+
export { d as reactive, s as shallowEqual, f as watch };
|
package/dist/index20.js
CHANGED
|
@@ -1,57 +1,54 @@
|
|
|
1
|
-
import { scoped as e } from "./
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}, o = {
|
|
15
|
-
get: () => r,
|
|
16
|
-
subscribe(e) {
|
|
17
|
-
return i.add(e), () => {
|
|
18
|
-
i.delete(e);
|
|
19
|
-
};
|
|
20
|
-
},
|
|
21
|
-
run(i) {
|
|
22
|
-
let o = ++n, s = performance.now();
|
|
23
|
-
a({
|
|
24
|
-
...r,
|
|
25
|
-
pending: !0,
|
|
26
|
-
error: null
|
|
27
|
-
}), e(i).then((e) => {
|
|
28
|
-
o === n && a({
|
|
29
|
-
data: e,
|
|
30
|
-
pending: !1,
|
|
31
|
-
settled: !0,
|
|
32
|
-
elapsedMs: performance.now() - s,
|
|
33
|
-
error: null
|
|
34
|
-
});
|
|
35
|
-
}, (e) => {
|
|
36
|
-
o === n && a({
|
|
37
|
-
...r,
|
|
38
|
-
pending: !1,
|
|
39
|
-
settled: !0,
|
|
40
|
-
error: e
|
|
41
|
-
}), t.error("task run failed", e);
|
|
1
|
+
import { scoped as e } from "./index6.js";
|
|
2
|
+
import { watch as t } from "./index19.js";
|
|
3
|
+
//#region src/observable.ts
|
|
4
|
+
var n = e("observe");
|
|
5
|
+
function r(e, r, i, a) {
|
|
6
|
+
let o = i ?? ((e) => e), s = a?.equals ?? Object.is, c, l = -1, u = null, d = null, f = null, p = null, m = /* @__PURE__ */ new Set(), h = () => {
|
|
7
|
+
if (u || d) return;
|
|
8
|
+
let i;
|
|
9
|
+
try {
|
|
10
|
+
i = e.connector(String(r));
|
|
11
|
+
} catch {
|
|
12
|
+
d = e.onBound(() => {
|
|
13
|
+
d = null, h();
|
|
42
14
|
});
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
u = t(i, o, (e) => {
|
|
18
|
+
if (c === void 0 || !s(c, e)) {
|
|
19
|
+
c = e;
|
|
20
|
+
for (let t of m) t(e);
|
|
21
|
+
}
|
|
22
|
+
}, a), p = i, f ??= e.onBound(() => {
|
|
23
|
+
let t;
|
|
24
|
+
try {
|
|
25
|
+
t = e.connector(String(r));
|
|
26
|
+
} catch {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
t !== p && (u?.(), u = null, p = null, h());
|
|
30
|
+
}), n.debug(`observing "${String(r)}" (offset ${i.byteOffset})`);
|
|
31
|
+
}, g = () => {
|
|
32
|
+
u?.(), u = null, p = null, d?.(), d = null, f?.(), f = null;
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
get() {
|
|
36
|
+
if (u || e.bound) try {
|
|
37
|
+
let t = e.connector(String(r)), n = t._version ? Atomics.load(t._version.view, t._version.index) : 0;
|
|
38
|
+
if (n !== l) {
|
|
39
|
+
l = n;
|
|
40
|
+
let e = o(t.read());
|
|
41
|
+
(c === void 0 || !s(c, e)) && (c = e);
|
|
42
|
+
}
|
|
43
|
+
} catch {}
|
|
44
|
+
return c;
|
|
43
45
|
},
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
subscribe(e) {
|
|
47
|
+
return m.add(e), h(), () => {
|
|
48
|
+
m.delete(e), m.size === 0 && g();
|
|
49
|
+
};
|
|
46
50
|
}
|
|
47
51
|
};
|
|
48
|
-
return o;
|
|
49
|
-
}
|
|
50
|
-
function r(e) {
|
|
51
|
-
return typeof e == "object" && !!e && typeof e.run == "function" && typeof e.runOnce == "function" && typeof e.get == "function" && typeof e.subscribe == "function";
|
|
52
|
-
}
|
|
53
|
-
function i(e) {
|
|
54
|
-
return r(e) ? e : n(e);
|
|
55
52
|
}
|
|
56
53
|
//#endregion
|
|
57
|
-
export {
|
|
54
|
+
export { r as observe };
|