nexa-runtime 0.11.0 → 0.11.2
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/scheduler.js +31 -25
- package/package.json +2 -2
package/dist/scheduler.js
CHANGED
|
@@ -1,37 +1,43 @@
|
|
|
1
1
|
import { setPostFlushCallback } from 'nexa-reactivity';
|
|
2
|
-
const pendingJobs = new Set();
|
|
3
|
-
let isFlushing = false;
|
|
4
2
|
const globalObj = (typeof globalThis !== 'undefined' ? globalThis : (typeof window !== 'undefined' ? window : {}));
|
|
5
|
-
//
|
|
3
|
+
// ── Shared job queue on global reactivity state ──
|
|
4
|
+
// All scheduler instances (even from different bundles/versions)
|
|
5
|
+
// share the same pendingJobs/isFlushing via __NEXA_REACTIVITY_STATE__.
|
|
6
|
+
// This prevents the bug where Vite pre-bundles produce duplicate
|
|
7
|
+
// scheduler instances with independent job queues.
|
|
6
8
|
const state = globalObj.__NEXA_REACTIVITY_STATE__;
|
|
7
|
-
if (state) {
|
|
8
|
-
|
|
9
|
+
if (!state) {
|
|
10
|
+
const f = { __nexa_pendingJobs: new Set(), __nexa_flushingJobs: false };
|
|
11
|
+
globalObj.__NEXA_REACTIVITY_STATE__ = f;
|
|
9
12
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
const S = globalObj.__NEXA_REACTIVITY_STATE__;
|
|
14
|
+
const getJobs = () => S.__nexa_pendingJobs;
|
|
15
|
+
const isFlushing = () => S.__nexa_flushingJobs;
|
|
16
|
+
const setFlushing = (v) => { S.__nexa_flushingJobs = v; };
|
|
17
|
+
if (!getJobs()) {
|
|
18
|
+
S.__nexa_pendingJobs = new Set();
|
|
19
|
+
S.__nexa_flushingJobs = false;
|
|
13
20
|
}
|
|
14
21
|
export function queueJob(instance) {
|
|
15
|
-
|
|
22
|
+
getJobs().add(instance);
|
|
16
23
|
}
|
|
17
24
|
export function flushJobs() {
|
|
18
|
-
|
|
25
|
+
const jobs = getJobs();
|
|
26
|
+
if (isFlushing() || jobs.size === 0)
|
|
19
27
|
return;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
pendingJobs.clear();
|
|
27
|
-
for (const instance of jobs) {
|
|
28
|
-
if (instance.update && typeof instance.update.run === 'function' && instance.update.active) {
|
|
29
|
-
instance.update.run();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
28
|
+
setFlushing(true);
|
|
29
|
+
while (jobs.size > 0) {
|
|
30
|
+
const batch = Array.from(jobs).sort((a, b) => a.depth - b.depth);
|
|
31
|
+
jobs.clear();
|
|
32
|
+
for (const instance of batch) {
|
|
33
|
+
instance.update?.run();
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
|
-
|
|
35
|
-
isFlushing = false;
|
|
36
|
-
}
|
|
36
|
+
setFlushing(false);
|
|
37
37
|
}
|
|
38
|
+
// Register flushJobs as the post-flush callback.
|
|
39
|
+
// Even if another scheduler instance overwrites it, both versions
|
|
40
|
+
// process the same global S.__nexa_pendingJobs queue.
|
|
41
|
+
state
|
|
42
|
+
? (state.postFlushCallback = flushJobs)
|
|
43
|
+
: setPostFlushCallback(flushJobs);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nexa-runtime",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"nexa-reactivity": "0.11.
|
|
16
|
+
"nexa-reactivity": "0.11.2"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"dist"
|