edges-svelte 2.2.0 → 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 +29 -51
- 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 +77 -148
- package/dist/context/Context.d.ts +3 -0
- package/dist/plugin/EdgesAutoHandlePlugin.d.ts +2 -66
- package/dist/plugin/EdgesAutoHandlePlugin.js +187 -83
- package/dist/provider/Provider.d.ts +0 -38
- package/dist/provider/Provider.js +82 -24
- package/dist/server/AutoWrapHandle.d.ts +1 -7
- package/dist/server/AutoWrapHandle.js +3 -8
- package/dist/server/EdgesHandle.d.ts +1 -8
- package/dist/server/EdgesHandle.js +5 -60
- package/dist/server/EdgesHandleSimplified.d.ts +1 -13
- package/dist/server/EdgesHandleSimplified.js +0 -8
- 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 -48
- package/dist/types.d.ts +0 -86
- package/dist/utils/batch.d.ts +1 -21
- package/dist/utils/batch.js +34 -54
- package/dist/utils/dev.d.ts +0 -21
- package/dist/utils/dev.js +3 -31
- package/dist/utils/environment.d.ts +1 -4
- package/dist/utils/environment.js +1 -4
- package/package.json +1 -4
package/dist/utils/batch.js
CHANGED
|
@@ -1,69 +1,65 @@
|
|
|
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
|
-
/**
|
|
7
|
-
* Batch multiple state updates into a single render cycle
|
|
8
|
-
*/
|
|
9
6
|
batch(fn) {
|
|
10
7
|
if (!browser) {
|
|
11
|
-
// On server, execute immediately
|
|
12
8
|
fn();
|
|
13
9
|
return;
|
|
14
10
|
}
|
|
15
|
-
|
|
16
|
-
const startBatching = !this.scheduled;
|
|
17
|
-
if (startBatching) {
|
|
18
|
-
this.scheduled = true;
|
|
19
|
-
}
|
|
11
|
+
this.depth += 1;
|
|
20
12
|
try {
|
|
21
13
|
fn();
|
|
22
14
|
}
|
|
23
15
|
finally {
|
|
24
|
-
|
|
16
|
+
this.depth -= 1;
|
|
17
|
+
if (this.depth === 0) {
|
|
25
18
|
this.flush();
|
|
26
19
|
}
|
|
27
20
|
}
|
|
28
21
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
+
}
|
|
32
40
|
queueUpdate(key, value, callback) {
|
|
33
|
-
if (!browser ||
|
|
34
|
-
// Execute immediately if not batching
|
|
41
|
+
if (!browser || this.depth === 0) {
|
|
35
42
|
if (callback)
|
|
36
43
|
callback(value);
|
|
37
44
|
return;
|
|
38
45
|
}
|
|
39
46
|
this.pendingUpdates.set(key, { key, value, callback });
|
|
40
47
|
}
|
|
41
|
-
/**
|
|
42
|
-
* Register a callback to be called when batch completes
|
|
43
|
-
*/
|
|
44
48
|
onBatchComplete(callback) {
|
|
45
49
|
this.batchCallbacks.add(callback);
|
|
46
50
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Flush all pending updates
|
|
49
|
-
*/
|
|
50
51
|
flush() {
|
|
51
52
|
if (this.pendingUpdates.size === 0) {
|
|
52
|
-
this.scheduled = false;
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
|
-
// Use microtask to batch DOM updates
|
|
56
55
|
queueMicrotask(() => {
|
|
57
56
|
const updates = Array.from(this.pendingUpdates.values());
|
|
58
57
|
this.pendingUpdates.clear();
|
|
59
|
-
this.scheduled = false;
|
|
60
|
-
// Apply all updates
|
|
61
58
|
for (const update of updates) {
|
|
62
59
|
if (update.callback) {
|
|
63
60
|
update.callback(update.value);
|
|
64
61
|
}
|
|
65
62
|
}
|
|
66
|
-
// Notify batch complete
|
|
67
63
|
for (const callback of this.batchCallbacks) {
|
|
68
64
|
callback();
|
|
69
65
|
}
|
|
@@ -71,36 +67,20 @@ class BatchManager {
|
|
|
71
67
|
});
|
|
72
68
|
}
|
|
73
69
|
}
|
|
74
|
-
// Global batch manager instance
|
|
75
70
|
const batchManager = new BatchManager();
|
|
76
|
-
/**
|
|
77
|
-
* Batch multiple state updates to avoid unnecessary re-renders
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```ts
|
|
81
|
-
* batch(() => {
|
|
82
|
-
* store1.set(value1);
|
|
83
|
-
* store2.set(value2);
|
|
84
|
-
* store3.set(value3);
|
|
85
|
-
* });
|
|
86
|
-
* ```
|
|
87
|
-
*/
|
|
88
71
|
export const batch = (fn) => batchManager.batch(fn);
|
|
89
|
-
/**
|
|
90
|
-
* Queue an update for batching (internal use)
|
|
91
|
-
*/
|
|
92
72
|
export const queueUpdate = (key, value, callback) => batchManager.queueUpdate(key, value, callback);
|
|
93
|
-
/**
|
|
94
|
-
* Register a callback for batch completion (internal use)
|
|
95
|
-
*/
|
|
96
73
|
export const onBatchComplete = (callback) => batchManager.onBatchComplete(callback);
|
|
97
|
-
|
|
98
|
-
* Transaction-like API for complex state updates
|
|
99
|
-
*/
|
|
74
|
+
export const isBatching = () => batchManager.isBatching();
|
|
100
75
|
export const transaction = async (fn) => {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
76
|
+
if (!browser) {
|
|
77
|
+
return fn();
|
|
78
|
+
}
|
|
79
|
+
batchManager.begin();
|
|
80
|
+
try {
|
|
81
|
+
return await fn();
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
batchManager.end();
|
|
85
|
+
}
|
|
106
86
|
};
|
package/dist/utils/dev.d.ts
CHANGED
|
@@ -1,30 +1,9 @@
|
|
|
1
1
|
import type { UnknownFunc } from '../types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Development-mode validations and warnings
|
|
4
|
-
*/
|
|
5
2
|
export declare const DevTools: {
|
|
6
|
-
/**
|
|
7
|
-
* Validates factory uniqueness in development
|
|
8
|
-
*/
|
|
9
3
|
validateFactoryUniqueness(factory: UnknownFunc, key: string): void;
|
|
10
|
-
/**
|
|
11
|
-
* Get cached size of a value (optimized to avoid repeated JSON.stringify)
|
|
12
|
-
*/
|
|
13
4
|
getSize(value: unknown): number;
|
|
14
|
-
/**
|
|
15
|
-
* Warns about large state objects (optimized with memoization)
|
|
16
|
-
*/
|
|
17
5
|
warnOnLargeState(key: string, value: unknown): void;
|
|
18
|
-
/**
|
|
19
|
-
* Validates state mutations
|
|
20
|
-
*/
|
|
21
6
|
checkStateMutation(key: string, oldValue: unknown, newValue: unknown): void;
|
|
22
|
-
/**
|
|
23
|
-
* Performance metrics collection
|
|
24
|
-
*/
|
|
25
7
|
measurePerformance<T>(name: string, fn: () => T): T;
|
|
26
|
-
/**
|
|
27
|
-
* Debug state tree visualization
|
|
28
|
-
*/
|
|
29
8
|
visualizeStateTree(stateMap: Map<string, unknown>): void;
|
|
30
9
|
};
|
package/dist/utils/dev.js
CHANGED
|
@@ -1,28 +1,18 @@
|
|
|
1
1
|
import { browser, dev } from './environment.js';
|
|
2
2
|
const seenFactories = new WeakSet();
|
|
3
3
|
const largeStateWarnings = new Set();
|
|
4
|
-
// Memoize size calculations to avoid repeated JSON.stringify calls
|
|
5
4
|
const sizeCache = new WeakMap();
|
|
6
|
-
/**
|
|
7
|
-
* Development-mode validations and warnings
|
|
8
|
-
*/
|
|
9
5
|
export const DevTools = {
|
|
10
|
-
/**
|
|
11
|
-
* Validates factory uniqueness in development
|
|
12
|
-
*/
|
|
13
6
|
validateFactoryUniqueness(factory, key) {
|
|
14
7
|
if (!dev)
|
|
15
8
|
return;
|
|
16
9
|
if (seenFactories.has(factory)) {
|
|
17
10
|
console.warn(`[edges-svelte] Factory collision detected for key "${key}". ` +
|
|
18
|
-
`This might cause unexpected behavior
|
|
19
|
-
`
|
|
11
|
+
`This might cause unexpected behavior.` +
|
|
12
|
+
`Set a unique __storeKey__ property on your factory function.`);
|
|
20
13
|
}
|
|
21
14
|
seenFactories.add(factory);
|
|
22
15
|
},
|
|
23
|
-
/**
|
|
24
|
-
* Get cached size of a value (optimized to avoid repeated JSON.stringify)
|
|
25
|
-
*/
|
|
26
16
|
getSize(value) {
|
|
27
17
|
if (typeof value === 'object' && value !== null) {
|
|
28
18
|
if (sizeCache.has(value)) {
|
|
@@ -34,9 +24,6 @@ export const DevTools = {
|
|
|
34
24
|
}
|
|
35
25
|
return JSON.stringify(value).length;
|
|
36
26
|
},
|
|
37
|
-
/**
|
|
38
|
-
* Warns about large state objects (optimized with memoization)
|
|
39
|
-
*/
|
|
40
27
|
warnOnLargeState(key, value) {
|
|
41
28
|
if (!dev)
|
|
42
29
|
return;
|
|
@@ -45,31 +32,22 @@ export const DevTools = {
|
|
|
45
32
|
try {
|
|
46
33
|
const size = this.getSize(value);
|
|
47
34
|
if (size > 50000) {
|
|
48
|
-
// 50KB threshold
|
|
49
35
|
largeStateWarnings.add(key);
|
|
50
|
-
console.warn(`[edges-svelte] Large state detected for key "${key}" (${Math.round(size / 1024)}KB). ` +
|
|
51
|
-
`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.`);
|
|
52
37
|
}
|
|
53
38
|
}
|
|
54
39
|
catch {
|
|
55
40
|
// Ignore serialization errors in dev warnings
|
|
56
41
|
}
|
|
57
42
|
},
|
|
58
|
-
/**
|
|
59
|
-
* Validates state mutations
|
|
60
|
-
*/
|
|
61
43
|
checkStateMutation(key, oldValue, newValue) {
|
|
62
44
|
if (!dev || !browser)
|
|
63
45
|
return;
|
|
64
|
-
// Check for direct object mutations
|
|
65
46
|
if (typeof oldValue === 'object' && oldValue !== null && oldValue === newValue && !Array.isArray(oldValue)) {
|
|
66
47
|
console.error(`[edges-svelte] Direct mutation detected for key "${key}". ` +
|
|
67
48
|
`State should be immutable. Use spread operator or Object.assign() to create new objects.`);
|
|
68
49
|
}
|
|
69
50
|
},
|
|
70
|
-
/**
|
|
71
|
-
* Performance metrics collection
|
|
72
|
-
*/
|
|
73
51
|
measurePerformance(name, fn) {
|
|
74
52
|
if (!dev)
|
|
75
53
|
return fn();
|
|
@@ -77,14 +55,10 @@ export const DevTools = {
|
|
|
77
55
|
const result = fn();
|
|
78
56
|
const duration = performance.now() - start;
|
|
79
57
|
if (duration > 16) {
|
|
80
|
-
// Longer than a frame
|
|
81
58
|
console.warn(`[edges-svelte] Slow operation "${name}" took ${duration.toFixed(2)}ms. ` + `Consider optimizing for better performance.`);
|
|
82
59
|
}
|
|
83
60
|
return result;
|
|
84
61
|
},
|
|
85
|
-
/**
|
|
86
|
-
* Debug state tree visualization
|
|
87
|
-
*/
|
|
88
62
|
visualizeStateTree(stateMap) {
|
|
89
63
|
if (!dev || !browser)
|
|
90
64
|
return;
|
|
@@ -105,7 +79,6 @@ export const DevTools = {
|
|
|
105
79
|
console.groupEnd();
|
|
106
80
|
}
|
|
107
81
|
};
|
|
108
|
-
// Export for browser devtools integration
|
|
109
82
|
if (browser && dev) {
|
|
110
83
|
window.__EDGES_DEVTOOLS__ = {
|
|
111
84
|
version: '1.3.0',
|
|
@@ -127,7 +100,6 @@ if (browser && dev) {
|
|
|
127
100
|
const sizes = {};
|
|
128
101
|
for (const [key, value] of stateMap) {
|
|
129
102
|
try {
|
|
130
|
-
// Use memoized getSize for better performance
|
|
131
103
|
const size = DevTools.getSize(value);
|
|
132
104
|
sizes[key] = size;
|
|
133
105
|
totalSize += size;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Universal browser detection that works in both SvelteKit and non-SvelteKit environments
|
|
3
|
-
* This fixes SSR issues when the package is used in different contexts
|
|
4
|
-
*/
|
|
5
1
|
export declare const browser: boolean;
|
|
6
2
|
export declare const dev: boolean;
|
|
3
|
+
export declare const build: boolean;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Universal browser detection that works in both SvelteKit and non-SvelteKit environments
|
|
3
|
-
* This fixes SSR issues when the package is used in different contexts
|
|
4
|
-
*/
|
|
5
1
|
export const browser = !import.meta.env.SSR && typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
6
2
|
export const dev = import.meta.env.DEV;
|
|
3
|
+
export const build = import.meta.env.PROD;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "edges-svelte",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Pixel1917",
|
|
6
6
|
"description": "A blazing-fast, extremely lightweight and SSR-friendly store for Svelte",
|
|
@@ -107,9 +107,6 @@
|
|
|
107
107
|
"state management",
|
|
108
108
|
"ssr store"
|
|
109
109
|
],
|
|
110
|
-
"dependencies": {
|
|
111
|
-
"devalue": "^5.1.1"
|
|
112
|
-
},
|
|
113
110
|
"scripts": {
|
|
114
111
|
"dev": "vite dev",
|
|
115
112
|
"build": "vite build && npm run prepack",
|