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.
@@ -1,28 +1,44 @@
1
1
  import { browser } from './environment.js';
2
2
  class BatchManager {
3
3
  pendingUpdates = new Map();
4
- scheduled = false;
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
- const startBatching = !this.scheduled;
12
- if (startBatching) {
13
- this.scheduled = true;
14
- }
11
+ this.depth += 1;
15
12
  try {
16
13
  fn();
17
14
  }
18
15
  finally {
19
- if (startBatching) {
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 || !this.scheduled) {
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
- return new Promise((resolve, reject) => {
62
- batch(() => {
63
- fn().then(resolve).catch(reject);
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 {
@@ -1,2 +1,3 @@
1
1
  export declare const browser: boolean;
2
2
  export declare const dev: boolean;
3
+ export declare const build: boolean;
@@ -1,2 +1,3 @@
1
1
  export const browser = !import.meta.env.SSR && typeof window !== 'undefined' && typeof document !== 'undefined';
2
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": "2.2.1",
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",