edges-svelte 2.2.1 → 3.0.0
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 +28 -50
- package/dist/client/NavigationStateObserver.svelte +9 -0
- package/dist/client/NavigationStateObserver.svelte.d.ts +3 -0
- package/dist/client/NavigationSync.svelte.d.ts +6 -0
- package/dist/client/NavigationSync.svelte.js +76 -140
- package/dist/context/Context.d.ts +3 -0
- package/dist/plugin/EdgesAutoHandlePlugin.d.ts +2 -4
- package/dist/plugin/EdgesAutoHandlePlugin.js +186 -19
- package/dist/provider/Provider.js +79 -3
- package/dist/server/AutoWrapHandle.d.ts +1 -7
- package/dist/server/AutoWrapHandle.js +3 -4
- package/dist/server/EdgesHandle.d.ts +1 -5
- package/dist/server/EdgesHandle.js +5 -56
- package/dist/server/EdgesHandleSimplified.d.ts +1 -5
- package/dist/server/ServerSync.d.ts +3 -0
- package/dist/server/ServerSync.js +125 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +1 -0
- package/dist/store/State.svelte.d.ts +1 -4
- package/dist/store/State.svelte.js +72 -31
- package/dist/types.d.ts +0 -6
- package/dist/utils/batch.d.ts +1 -0
- package/dist/utils/batch.js +34 -14
- package/dist/utils/dev.js +1 -2
- package/dist/utils/environment.d.ts +1 -0
- package/dist/utils/environment.js +1 -0
- package/package.json +1 -1
package/dist/utils/batch.js
CHANGED
|
@@ -1,28 +1,44 @@
|
|
|
1
1
|
import { browser } from './environment.js';
|
|
2
2
|
class BatchManager {
|
|
3
3
|
pendingUpdates = new Map();
|
|
4
|
-
|
|
4
|
+
depth = 0;
|
|
5
5
|
batchCallbacks = new Set();
|
|
6
6
|
batch(fn) {
|
|
7
7
|
if (!browser) {
|
|
8
8
|
fn();
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
if (startBatching) {
|
|
13
|
-
this.scheduled = true;
|
|
14
|
-
}
|
|
11
|
+
this.depth += 1;
|
|
15
12
|
try {
|
|
16
13
|
fn();
|
|
17
14
|
}
|
|
18
15
|
finally {
|
|
19
|
-
|
|
16
|
+
this.depth -= 1;
|
|
17
|
+
if (this.depth === 0) {
|
|
20
18
|
this.flush();
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
21
|
}
|
|
22
|
+
begin() {
|
|
23
|
+
if (!browser)
|
|
24
|
+
return;
|
|
25
|
+
this.depth += 1;
|
|
26
|
+
}
|
|
27
|
+
end() {
|
|
28
|
+
if (!browser)
|
|
29
|
+
return;
|
|
30
|
+
if (this.depth === 0)
|
|
31
|
+
return;
|
|
32
|
+
this.depth -= 1;
|
|
33
|
+
if (this.depth === 0) {
|
|
34
|
+
this.flush();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
isBatching() {
|
|
38
|
+
return browser && this.depth > 0;
|
|
39
|
+
}
|
|
24
40
|
queueUpdate(key, value, callback) {
|
|
25
|
-
if (!browser ||
|
|
41
|
+
if (!browser || this.depth === 0) {
|
|
26
42
|
if (callback)
|
|
27
43
|
callback(value);
|
|
28
44
|
return;
|
|
@@ -34,13 +50,11 @@ class BatchManager {
|
|
|
34
50
|
}
|
|
35
51
|
flush() {
|
|
36
52
|
if (this.pendingUpdates.size === 0) {
|
|
37
|
-
this.scheduled = false;
|
|
38
53
|
return;
|
|
39
54
|
}
|
|
40
55
|
queueMicrotask(() => {
|
|
41
56
|
const updates = Array.from(this.pendingUpdates.values());
|
|
42
57
|
this.pendingUpdates.clear();
|
|
43
|
-
this.scheduled = false;
|
|
44
58
|
for (const update of updates) {
|
|
45
59
|
if (update.callback) {
|
|
46
60
|
update.callback(update.value);
|
|
@@ -57,10 +71,16 @@ const batchManager = new BatchManager();
|
|
|
57
71
|
export const batch = (fn) => batchManager.batch(fn);
|
|
58
72
|
export const queueUpdate = (key, value, callback) => batchManager.queueUpdate(key, value, callback);
|
|
59
73
|
export const onBatchComplete = (callback) => batchManager.onBatchComplete(callback);
|
|
74
|
+
export const isBatching = () => batchManager.isBatching();
|
|
60
75
|
export const transaction = async (fn) => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
76
|
+
if (!browser) {
|
|
77
|
+
return fn();
|
|
78
|
+
}
|
|
79
|
+
batchManager.begin();
|
|
80
|
+
try {
|
|
81
|
+
return await fn();
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
batchManager.end();
|
|
85
|
+
}
|
|
66
86
|
};
|
package/dist/utils/dev.js
CHANGED
|
@@ -33,8 +33,7 @@ export const DevTools = {
|
|
|
33
33
|
const size = this.getSize(value);
|
|
34
34
|
if (size > 50000) {
|
|
35
35
|
largeStateWarnings.add(key);
|
|
36
|
-
console.warn(`[edges-svelte] Large state detected for key "${key}" (${Math.round(size / 1024)}KB). ` +
|
|
37
|
-
`Consider splitting into smaller stores or enabling compression.`);
|
|
36
|
+
console.warn(`[edges-svelte] Large state detected for key "${key}" (${Math.round(size / 1024)}KB). ` + `Consider splitting into smaller stores.`);
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
39
|
catch {
|