@azure-net/kit 3.0.0 → 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.
@@ -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": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",