@azure-net/kit 2.2.7 → 3.0.1

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.
@@ -53,13 +53,8 @@ export const createAsyncSignal = (handler, options = {}) => {
53
53
  const pending = $derived(status === 'pending');
54
54
  let abortController = null;
55
55
  let currentPromise = null;
56
- const ensurePromise = () => {
57
- if (currentPromise)
58
- return currentPromise;
59
- currentPromise = run();
60
- return currentPromise;
61
- };
62
- const run = async () => {
56
+ let currentRunId = 0;
57
+ const run = async (runId) => {
63
58
  if (abortController) {
64
59
  abortController.abort();
65
60
  }
@@ -89,13 +84,24 @@ export const createAsyncSignal = (handler, options = {}) => {
89
84
  }
90
85
  return undefined;
91
86
  }
87
+ finally {
88
+ if (currentRunId === runId) {
89
+ currentPromise = null;
90
+ }
91
+ }
92
+ };
93
+ const start = () => {
94
+ const runId = ++currentRunId;
95
+ const localPromise = run(runId);
96
+ currentPromise = localPromise;
97
+ return localPromise;
92
98
  };
93
99
  const execute = async () => {
94
100
  if (status === 'pending' && currentPromise) {
95
101
  await currentPromise;
96
102
  return;
97
103
  }
98
- await ensurePromise();
104
+ await start();
99
105
  };
100
106
  if (EnvironmentUtil.isBrowser) {
101
107
  const signalKey = key ?? asyncSignalManager.generateKey();
@@ -144,7 +150,9 @@ export const createAsyncSignal = (handler, options = {}) => {
144
150
  return pending;
145
151
  },
146
152
  get ready() {
147
- return ensurePromise();
153
+ if (currentPromise)
154
+ return currentPromise;
155
+ return start();
148
156
  },
149
157
  execute,
150
158
  refresh: execute,
@@ -1,4 +1,5 @@
1
1
  import { ObjectUtil } from 'azure-net-tools';
2
+ import { untrack } from 'svelte';
2
3
  export const createQuery = (options) => {
3
4
  const { initial: initialValue, signal: initialSignal, excludeKeys, debounceMs = 0, autoRefresh = true } = options;
4
5
  const baseInitial = ObjectUtil.deepClone(initialValue);
@@ -14,6 +15,7 @@ export const createQuery = (options) => {
14
15
  const keys = resolveKeys();
15
16
  let isFirstRun = true;
16
17
  let debounceTimer = null;
18
+ const lastValues = new Map();
17
19
  const scheduleRefresh = () => {
18
20
  if (!signal)
19
21
  return;
@@ -21,23 +23,34 @@ export const createQuery = (options) => {
21
23
  clearTimeout(debounceTimer);
22
24
  if (debounceMs > 0) {
23
25
  debounceTimer = setTimeout(() => {
24
- void signal?.refresh();
26
+ untrack(() => {
27
+ void signal?.refresh();
28
+ });
25
29
  }, debounceMs);
26
30
  }
27
31
  else {
28
- void signal.refresh();
32
+ untrack(() => {
33
+ void signal?.refresh();
34
+ });
29
35
  }
30
36
  };
31
37
  if (autoRefresh) {
32
38
  $effect(() => {
39
+ let hasChanged = false;
33
40
  keys.forEach((key) => {
34
- void data[key];
41
+ const nextValue = data[key];
42
+ if (!Object.is(lastValues.get(key), nextValue)) {
43
+ hasChanged = true;
44
+ lastValues.set(key, nextValue);
45
+ }
35
46
  });
36
47
  if (isFirstRun) {
37
48
  isFirstRun = false;
38
49
  return;
39
50
  }
40
- scheduleRefresh();
51
+ if (hasChanged) {
52
+ scheduleRefresh();
53
+ }
41
54
  });
42
55
  }
43
56
  const patch = (values) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure-net/kit",
3
- "version": "2.2.7",
3
+ "version": "3.0.1",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",