@cognite/signal-utils 1.0.1 → 1.48411.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.
Files changed (47) hide show
  1. package/README.md +7 -6
  2. package/dist/core/array-signal.d.ts +52 -52
  3. package/dist/core/array-signal.js +105 -34
  4. package/dist/core/array-signal.js.map +1 -0
  5. package/dist/core/batch.d.ts +21 -21
  6. package/dist/core/batch.js +26 -6
  7. package/dist/core/batch.js.map +1 -0
  8. package/dist/core/computed.d.ts +17 -17
  9. package/dist/core/computed.js +27 -10
  10. package/dist/core/computed.js.map +1 -0
  11. package/dist/core/effect.d.ts +29 -29
  12. package/dist/core/effect.js +34 -6
  13. package/dist/core/effect.js.map +1 -0
  14. package/dist/core/signal.d.ts +73 -73
  15. package/dist/core/signal.js +25 -17
  16. package/dist/core/signal.js.map +1 -0
  17. package/dist/core/untracked.d.ts +26 -26
  18. package/dist/core/untracked.js +31 -6
  19. package/dist/core/untracked.js.map +1 -0
  20. package/dist/extensions/fragmentSignal.d.ts +84 -84
  21. package/dist/extensions/fragmentSignal.js +38 -20
  22. package/dist/extensions/fragmentSignal.js.map +1 -0
  23. package/dist/extensions.d.ts +1 -1
  24. package/dist/extensions.js +3 -2
  25. package/dist/extensions.js.map +1 -0
  26. package/dist/index.d.ts +10 -10
  27. package/dist/index.js +9 -8
  28. package/dist/index.js.map +1 -0
  29. package/dist/misc/debounced-computed.d.ts +20 -20
  30. package/dist/misc/debounced-computed.js +37 -16
  31. package/dist/misc/debounced-computed.js.map +1 -0
  32. package/dist/react/use-signal-value.d.ts +7 -7
  33. package/dist/react/use-signal-value.js +11 -6
  34. package/dist/react/use-signal-value.js.map +1 -0
  35. package/dist/react.d.ts +1 -1
  36. package/dist/react.js +3 -2
  37. package/dist/react.js.map +1 -0
  38. package/dist/utils/arrays.d.ts +22 -22
  39. package/dist/utils/arrays.js +41 -13
  40. package/dist/utils/arrays.js.map +1 -0
  41. package/dist/utils/debounce.d.ts +8 -8
  42. package/dist/utils/debounce.js +30 -11
  43. package/dist/utils/debounce.js.map +1 -0
  44. package/dist/utils/repeat.d.ts +5 -5
  45. package/dist/utils/repeat.js +12 -0
  46. package/dist/utils/repeat.js.map +1 -0
  47. package/package.json +7 -3
@@ -1,25 +1,25 @@
1
- import { ReadonlySignal } from '../core/signal';
1
+ import type { ReadonlySignal } from "../core/signal";
2
2
  /**
3
- * Represents a debounced computed value.
4
- *
5
- * @template T - The type of the computed value.
6
- *
7
- * @property {ReadonlySignal<T>} value - The debounced computed value.
8
- * @property {VoidFunction} dispose - A function to dispose updates to the computed value.
9
- */
3
+ * Represents a debounced computed value.
4
+ *
5
+ * @template T - The type of the computed value.
6
+ *
7
+ * @property {ReadonlySignal<T>} value - The debounced computed value.
8
+ * @property {VoidFunction} dispose - A function to dispose updates to the computed value.
9
+ */
10
10
  export type DebouncedComputed<T> = {
11
- value: ReadonlySignal<T>;
12
- dispose: VoidFunction;
11
+ value: ReadonlySignal<T>;
12
+ dispose: VoidFunction;
13
13
  };
14
14
  /**
15
- * Creates a debounced computed value based on the provided function.
16
- * The value will be set immediately, and debounce thereafter. This means the computed value will be updated at a maximum
17
- * frequency of once every `delayInMs` milliseconds.
18
- *
19
- * @template T - The type of the computed value.
20
- * @param {() => T} func - The function that returns the computed value.
21
- * @param {number} [delayInMs] - The minimum amount of time that must pass between between each value update. If not provided, a default delay will be used.
22
- * @param {boolean} [immediate=false] - If true, the function will be called at the start of the wait period, rather than the end.
23
- * @returns {DebouncedComputed<T>} An object containing the debounced computed value and a dispose function.
24
- */
15
+ * Creates a debounced computed value based on the provided function.
16
+ * The value will be set immediately, and debounce thereafter. This means the computed value will be updated at a maximum
17
+ * frequency of once every `delayInMs` milliseconds.
18
+ *
19
+ * @template T - The type of the computed value.
20
+ * @param {() => T} func - The function that returns the computed value.
21
+ * @param {number} [delayInMs] - The minimum amount of time that must pass between between each value update. If not provided, a default delay will be used.
22
+ * @param {boolean} [immediate=false] - If true, the function will be called at the start of the wait period, rather than the end.
23
+ * @returns {DebouncedComputed<T>} An object containing the debounced computed value and a dispose function.
24
+ */
25
25
  export declare function debouncedComputed<T>(func: () => T, delayInMs?: number, immediate?: boolean): DebouncedComputed<T>;
@@ -1,17 +1,38 @@
1
- import { signal as e } from "../core/signal.js";
2
- import { computed as t } from "../core/computed.js";
3
- import { effect as n } from "../core/effect.js";
4
- import { debounce as r } from "../utils/debounce.js";
5
- //#region libs/shared/signal-utils/src/misc/debounced-computed.ts
6
- function i(i, a, o = !1) {
7
- let s = !1, c = e(void 0), l = r(c, a, o), u = t(i), d = n(() => {
8
- let e = u();
9
- s ? l(e) : (c(e), s = !0);
10
- });
11
- return {
12
- value: t(() => c()),
13
- dispose: d
14
- };
1
+ import { computed } from "../core/computed.js";
2
+ import { effect } from "../core/effect.js";
3
+ import { signal } from "../core/signal.js";
4
+ import { debounce } from "../utils/debounce.js";
5
+ /**
6
+ * Creates a debounced computed value based on the provided function.
7
+ * The value will be set immediately, and debounce thereafter. This means the computed value will be updated at a maximum
8
+ * frequency of once every `delayInMs` milliseconds.
9
+ *
10
+ * @template T - The type of the computed value.
11
+ * @param {() => T} func - The function that returns the computed value.
12
+ * @param {number} [delayInMs] - The minimum amount of time that must pass between between each value update. If not provided, a default delay will be used.
13
+ * @param {boolean} [immediate=false] - If true, the function will be called at the start of the wait period, rather than the end.
14
+ * @returns {DebouncedComputed<T>} An object containing the debounced computed value and a dispose function.
15
+ */ export function debouncedComputed(func, delayInMs, immediate = false) {
16
+ let isInitialized = false;
17
+ let innerValue = signal(undefined); // We set the initial value in the effect
18
+ const updateInnerValue = debounce(innerValue, delayInMs, immediate);
19
+ const inputComputed = computed(func);
20
+ const dispose = effect(()=>{
21
+ const newValue = inputComputed();
22
+ if (!isInitialized) {
23
+ // We want to set the value immediately on the first run.
24
+ // No debounce is applied here.
25
+ innerValue(newValue);
26
+ isInitialized = true;
27
+ } else {
28
+ updateInnerValue(newValue);
29
+ }
30
+ });
31
+ const value = computed(()=>innerValue());
32
+ return {
33
+ value,
34
+ dispose
35
+ };
15
36
  }
16
- //#endregion
17
- export { i as debouncedComputed };
37
+
38
+ //# sourceMappingURL=debounced-computed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/misc/debounced-computed.ts"],"sourcesContent":["import { computed } from '../core/computed';\nimport { effect } from '../core/effect';\nimport type { ReadonlySignal } from '../core/signal';\nimport { signal } from '../core/signal';\nimport { debounce } from '../utils/debounce';\n\n/**\n * Represents a debounced computed value.\n *\n * @template T - The type of the computed value.\n *\n * @property {ReadonlySignal<T>} value - The debounced computed value.\n * @property {VoidFunction} dispose - A function to dispose updates to the computed value.\n */\nexport type DebouncedComputed<T> = {\n value: ReadonlySignal<T>;\n dispose: VoidFunction;\n};\n\n/**\n * Creates a debounced computed value based on the provided function.\n * The value will be set immediately, and debounce thereafter. This means the computed value will be updated at a maximum\n * frequency of once every `delayInMs` milliseconds.\n *\n * @template T - The type of the computed value.\n * @param {() => T} func - The function that returns the computed value.\n * @param {number} [delayInMs] - The minimum amount of time that must pass between between each value update. If not provided, a default delay will be used.\n * @param {boolean} [immediate=false] - If true, the function will be called at the start of the wait period, rather than the end.\n * @returns {DebouncedComputed<T>} An object containing the debounced computed value and a dispose function.\n */\nexport function debouncedComputed<T>(\n func: () => T,\n delayInMs?: number,\n immediate: boolean = false\n): DebouncedComputed<T> {\n let isInitialized = false;\n let innerValue = signal(undefined as T); // We set the initial value in the effect\n const updateInnerValue = debounce(innerValue, delayInMs, immediate);\n const inputComputed = computed(func);\n\n const dispose = effect(() => {\n const newValue = inputComputed();\n if (!isInitialized) {\n // We want to set the value immediately on the first run.\n // No debounce is applied here.\n innerValue(newValue);\n isInitialized = true;\n } else {\n updateInnerValue(newValue);\n }\n });\n\n const value = computed(() => innerValue());\n return { value, dispose };\n}\n"],"names":["computed","effect","signal","debounce","debouncedComputed","func","delayInMs","immediate","isInitialized","innerValue","undefined","updateInnerValue","inputComputed","dispose","newValue","value"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,sBAAmB;AAC5C,SAASC,MAAM,QAAQ,oBAAiB;AAExC,SAASC,MAAM,QAAQ,oBAAiB;AACxC,SAASC,QAAQ,QAAQ,uBAAoB;AAe7C;;;;;;;;;;CAUC,GACD,OAAO,SAASC,kBACdC,IAAa,EACbC,SAAkB,EAClBC,YAAqB,KAAK;IAE1B,IAAIC,gBAAgB;IACpB,IAAIC,aAAaP,OAAOQ,YAAiB,yCAAyC;IAClF,MAAMC,mBAAmBR,SAASM,YAAYH,WAAWC;IACzD,MAAMK,gBAAgBZ,SAASK;IAE/B,MAAMQ,UAAUZ,OAAO;QACrB,MAAMa,WAAWF;QACjB,IAAI,CAACJ,eAAe;YAClB,yDAAyD;YACzD,+BAA+B;YAC/BC,WAAWK;YACXN,gBAAgB;QAClB,OAAO;YACLG,iBAAiBG;QACnB;IACF;IAEA,MAAMC,QAAQf,SAAS,IAAMS;IAC7B,OAAO;QAAEM;QAAOF;IAAQ;AAC1B"}
@@ -1,9 +1,9 @@
1
- import { ReadonlySignal } from '../core/signal';
1
+ import type { ReadonlySignal } from "../core/signal";
2
2
  /**
3
- * A custom hook that returns the signal's value and keeps the value up-to-date.
4
- *
5
- * @template T - The type of the value held by the signal.
6
- * @param {ReadonlySignal<T>} signal - The signal.
7
- * @returns {T} - The current value of the signal.
8
- */
3
+ * A custom hook that returns the signal's value and keeps the value up-to-date.
4
+ *
5
+ * @template T - The type of the value held by the signal.
6
+ * @param {ReadonlySignal<T>} signal - The signal.
7
+ * @returns {T} - The current value of the signal.
8
+ */
9
9
  export declare function useSignalValue<T>(signal: ReadonlySignal<T>): T;
@@ -1,7 +1,12 @@
1
- import { useSyncExternalStore as e } from "react";
2
- //#region libs/shared/signal-utils/src/react/use-signal-value.ts
3
- function t(t) {
4
- return e(t.subscribe, t.peek);
1
+ import { useSyncExternalStore } from "react";
2
+ /**
3
+ * A custom hook that returns the signal's value and keeps the value up-to-date.
4
+ *
5
+ * @template T - The type of the value held by the signal.
6
+ * @param {ReadonlySignal<T>} signal - The signal.
7
+ * @returns {T} - The current value of the signal.
8
+ */ export function useSignalValue(signal) {
9
+ return useSyncExternalStore(signal.subscribe, signal.peek);
5
10
  }
6
- //#endregion
7
- export { t as useSignalValue };
11
+
12
+ //# sourceMappingURL=use-signal-value.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/react/use-signal-value.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\nimport type { ReadonlySignal } from '../core/signal';\n\n/**\n * A custom hook that returns the signal's value and keeps the value up-to-date.\n *\n * @template T - The type of the value held by the signal.\n * @param {ReadonlySignal<T>} signal - The signal.\n * @returns {T} - The current value of the signal.\n */\nexport function useSignalValue<T>(signal: ReadonlySignal<T>): T {\n return useSyncExternalStore(signal.subscribe, signal.peek);\n}\n"],"names":["useSyncExternalStore","useSignalValue","signal","subscribe","peek"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,QAAQ;AAI7C;;;;;;CAMC,GACD,OAAO,SAASC,eAAkBC,MAAyB;IACzD,OAAOF,qBAAqBE,OAAOC,SAAS,EAAED,OAAOE,IAAI;AAC3D"}
package/dist/react.d.ts CHANGED
@@ -1 +1 @@
1
- export { useSignalValue } from './react/use-signal-value';
1
+ export { useSignalValue } from "./react/use-signal-value";
package/dist/react.js CHANGED
@@ -1,2 +1,3 @@
1
- import { useSignalValue as e } from "./react/use-signal-value.js";
2
- export { e as useSignalValue };
1
+ export { useSignalValue } from "./react/use-signal-value.js";
2
+
3
+ //# sourceMappingURL=react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/react.ts"],"sourcesContent":["export { useSignalValue } from './react/use-signal-value';\n"],"names":["useSignalValue"],"mappings":"AAAA,SAASA,cAAc,QAAQ,8BAA2B"}
@@ -1,30 +1,30 @@
1
1
  /**
2
- * Inserts an element at a specific index in the array.
3
- *
4
- * @param array
5
- * @param index
6
- * @param item
7
- */
2
+ * Inserts an element at a specific index in the array.
3
+ *
4
+ * @param array
5
+ * @param index
6
+ * @param item
7
+ */
8
8
  export declare function insertAt<T>(array: T[], index: number, item: T): void;
9
9
  /**
10
- * Removes an element from the array.
11
- *
12
- * @param array
13
- * @param item
14
- */
10
+ * Removes an element from the array.
11
+ *
12
+ * @param array
13
+ * @param item
14
+ */
15
15
  export declare function remove<T>(array: T[], item: T): void;
16
16
  /**
17
- * Removes an element at the index from the array.
18
- *
19
- * @param array
20
- * @param item
21
- */
17
+ * Removes an element at the index from the array.
18
+ *
19
+ * @param array
20
+ * @param item
21
+ */
22
22
  export declare function removeAt(array: unknown[], index: number): void;
23
23
  /**
24
- * Swaps two elements in the array on index `i` and `j`.
25
- *
26
- * @param array
27
- * @param i
28
- * @param j
29
- */
24
+ * Swaps two elements in the array on index `i` and `j`.
25
+ *
26
+ * @param array
27
+ * @param i
28
+ * @param j
29
+ */
30
30
  export declare function swap(array: unknown[], i: number, j: number): void;
@@ -1,17 +1,45 @@
1
- //#region libs/shared/signal-utils/src/utils/arrays.ts
2
- function e(e, t, n) {
3
- e.splice(t, 0, n);
1
+ /**
2
+ * Inserts an element at a specific index in the array.
3
+ *
4
+ * @param array
5
+ * @param index
6
+ * @param item
7
+ */ export function insertAt(array, index, item) {
8
+ array.splice(index, 0, item);
4
9
  }
5
- function t(e, t) {
6
- let r = e.indexOf(t);
7
- r !== -1 && n(e, r);
10
+ /**
11
+ * Removes an element from the array.
12
+ *
13
+ * @param array
14
+ * @param item
15
+ */ export function remove(array, item) {
16
+ const index = array.indexOf(item);
17
+ if (index !== -1) {
18
+ removeAt(array, index);
19
+ }
8
20
  }
9
- function n(e, t) {
10
- e.splice(t, 1);
21
+ /**
22
+ * Removes an element at the index from the array.
23
+ *
24
+ * @param array
25
+ * @param item
26
+ */ export function removeAt(array, index) {
27
+ array.splice(index, 1);
11
28
  }
12
- function r(e, t, n) {
13
- if (t < 0 || n < 0 || t >= e.length || n >= e.length) throw Error("Index out of bounds");
14
- [e[t], e[n]] = [e[n], e[t]];
29
+ /**
30
+ * Swaps two elements in the array on index `i` and `j`.
31
+ *
32
+ * @param array
33
+ * @param i
34
+ * @param j
35
+ */ export function swap(array, i, j) {
36
+ if (i < 0 || j < 0 || i >= array.length || j >= array.length) {
37
+ throw new Error('Index out of bounds');
38
+ }
39
+ [array[i], array[j]] = [
40
+ array[j],
41
+ array[i]
42
+ ];
15
43
  }
16
- //#endregion
17
- export { e as insertAt, t as remove, n as removeAt, r as swap };
44
+
45
+ //# sourceMappingURL=arrays.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/arrays.ts"],"sourcesContent":["/**\n * Inserts an element at a specific index in the array.\n *\n * @param array\n * @param index\n * @param item\n */\nexport function insertAt<T>(array: T[], index: number, item: T): void {\n array.splice(index, 0, item);\n}\n\n/**\n * Removes an element from the array.\n *\n * @param array\n * @param item\n */\nexport function remove<T>(array: T[], item: T): void {\n const index = array.indexOf(item);\n if (index !== -1) {\n removeAt(array, index);\n }\n}\n\n/**\n * Removes an element at the index from the array.\n *\n * @param array\n * @param item\n */\nexport function removeAt(array: unknown[], index: number): void {\n array.splice(index, 1);\n}\n\n/**\n * Swaps two elements in the array on index `i` and `j`.\n *\n * @param array\n * @param i\n * @param j\n */\nexport function swap(array: unknown[], i: number, j: number): void {\n if (i < 0 || j < 0 || i >= array.length || j >= array.length) {\n throw new Error('Index out of bounds');\n }\n [array[i], array[j]] = [array[j], array[i]];\n}\n"],"names":["insertAt","array","index","item","splice","remove","indexOf","removeAt","swap","i","j","length","Error"],"mappings":"AAAA;;;;;;CAMC,GACD,OAAO,SAASA,SAAYC,KAAU,EAAEC,KAAa,EAAEC,IAAO;IAC5DF,MAAMG,MAAM,CAACF,OAAO,GAAGC;AACzB;AAEA;;;;;CAKC,GACD,OAAO,SAASE,OAAUJ,KAAU,EAAEE,IAAO;IAC3C,MAAMD,QAAQD,MAAMK,OAAO,CAACH;IAC5B,IAAID,UAAU,CAAC,GAAG;QAChBK,SAASN,OAAOC;IAClB;AACF;AAEA;;;;;CAKC,GACD,OAAO,SAASK,SAASN,KAAgB,EAAEC,KAAa;IACtDD,MAAMG,MAAM,CAACF,OAAO;AACtB;AAEA;;;;;;CAMC,GACD,OAAO,SAASM,KAAKP,KAAgB,EAAEQ,CAAS,EAAEC,CAAS;IACzD,IAAID,IAAI,KAAKC,IAAI,KAAKD,KAAKR,MAAMU,MAAM,IAAID,KAAKT,MAAMU,MAAM,EAAE;QAC5D,MAAM,IAAIC,MAAM;IAClB;IACA,CAACX,KAAK,CAACQ,EAAE,EAAER,KAAK,CAACS,EAAE,CAAC,GAAG;QAACT,KAAK,CAACS,EAAE;QAAET,KAAK,CAACQ,EAAE;KAAC;AAC7C"}
@@ -1,10 +1,10 @@
1
1
  /**
2
- * Wraps a function in a debounce function that will only execute
3
- * the provided function at a maximum frequency of once every `delayInMs` milliseconds.
4
- *
5
- * @param callback The function to debounce.
6
- * @param delayInMs The minimum amount of time that must pass between calls to the function.
7
- * @param immediate If true, the function will be called at the start of the wait period, rather than the end.
8
- * @returns
9
- */
2
+ * Wraps a function in a debounce function that will only execute
3
+ * the provided function at a maximum frequency of once every `delayInMs` milliseconds.
4
+ *
5
+ * @param callback The function to debounce.
6
+ * @param delayInMs The minimum amount of time that must pass between calls to the function.
7
+ * @param immediate If true, the function will be called at the start of the wait period, rather than the end.
8
+ * @returns
9
+ */
10
10
  export declare function debounce<T extends (...args: any[]) => void>(callback: T, delayInMs?: number, immediate?: boolean): <U>(this: U, ...args: Parameters<typeof callback>) => void;
@@ -1,12 +1,31 @@
1
- //#region libs/shared/signal-utils/src/utils/debounce.ts
2
- function e(e, t = 250, n = !1) {
3
- let r = null;
4
- return function(...i) {
5
- let a = () => {
6
- r = null, n || e.apply(this, i);
7
- }, o = n && r === null;
8
- r !== null && clearTimeout(r), r = setTimeout(a, t), o && e.apply(this, i);
9
- };
1
+ // https://stackoverflow.com/questions/72205837/safe-type-debounce-function-in-typescript
2
+ /**
3
+ * Wraps a function in a debounce function that will only execute
4
+ * the provided function at a maximum frequency of once every `delayInMs` milliseconds.
5
+ *
6
+ * @param callback The function to debounce.
7
+ * @param delayInMs The minimum amount of time that must pass between calls to the function.
8
+ * @param immediate If true, the function will be called at the start of the wait period, rather than the end.
9
+ * @returns
10
+ */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
+ export function debounce(callback, delayInMs = 250, immediate = false) {
12
+ let timeout = null;
13
+ return function(...args) {
14
+ const later = ()=>{
15
+ timeout = null;
16
+ if (!immediate) {
17
+ callback.apply(this, args);
18
+ }
19
+ };
20
+ const callNow = immediate && timeout === null;
21
+ if (timeout !== null) {
22
+ clearTimeout(timeout);
23
+ }
24
+ timeout = setTimeout(later, delayInMs);
25
+ if (callNow) {
26
+ callback.apply(this, args);
27
+ }
28
+ };
10
29
  }
11
- //#endregion
12
- export { e as debounce };
30
+
31
+ //# sourceMappingURL=debounce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/debounce.ts"],"sourcesContent":["// https://stackoverflow.com/questions/72205837/safe-type-debounce-function-in-typescript\n\n/**\n * Wraps a function in a debounce function that will only execute\n * the provided function at a maximum frequency of once every `delayInMs` milliseconds.\n *\n * @param callback The function to debounce.\n * @param delayInMs The minimum amount of time that must pass between calls to the function.\n * @param immediate If true, the function will be called at the start of the wait period, rather than the end.\n * @returns\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function debounce<T extends (...args: any[]) => void>(\n callback: T,\n delayInMs: number = 250,\n immediate = false\n) {\n let timeout: ReturnType<typeof setTimeout> | null = null;\n return function <U>(this: U, ...args: Parameters<typeof callback>): void {\n const later = (): void => {\n timeout = null;\n if (!immediate) {\n callback.apply(this, args);\n }\n };\n const callNow = immediate && timeout === null;\n if (timeout !== null) {\n clearTimeout(timeout);\n }\n timeout = setTimeout(later, delayInMs);\n if (callNow) {\n callback.apply(this, args);\n }\n };\n}\n"],"names":["debounce","callback","delayInMs","immediate","timeout","args","later","apply","callNow","clearTimeout","setTimeout"],"mappings":"AAAA,yFAAyF;AAEzF;;;;;;;;CAQC,GACD,8DAA8D;AAC9D,OAAO,SAASA,SACdC,QAAW,EACXC,YAAoB,GAAG,EACvBC,YAAY,KAAK;IAEjB,IAAIC,UAAgD;IACpD,OAAO,SAAsB,GAAGC,IAAiC;QAC/D,MAAMC,QAAQ;YACZF,UAAU;YACV,IAAI,CAACD,WAAW;gBACdF,SAASM,KAAK,CAAC,IAAI,EAAEF;YACvB;QACF;QACA,MAAMG,UAAUL,aAAaC,YAAY;QACzC,IAAIA,YAAY,MAAM;YACpBK,aAAaL;QACf;QACAA,UAAUM,WAAWJ,OAAOJ;QAC5B,IAAIM,SAAS;YACXP,SAASM,KAAK,CAAC,IAAI,EAAEF;QACvB;IACF;AACF"}
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Repeats the execution of a given function a specified number of times.
3
- *
4
- * @param fn - The function to be executed repeatedly. It should not take any arguments and should not return any value.
5
- * @param times - The number of times to execute the function.
6
- */
2
+ * Repeats the execution of a given function a specified number of times.
3
+ *
4
+ * @param fn - The function to be executed repeatedly. It should not take any arguments and should not return any value.
5
+ * @param times - The number of times to execute the function.
6
+ */
7
7
  export declare function repeat(fn: VoidFunction, times: number): void;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Repeats the execution of a given function a specified number of times.
3
+ *
4
+ * @param fn - The function to be executed repeatedly. It should not take any arguments and should not return any value.
5
+ * @param times - The number of times to execute the function.
6
+ */ export function repeat(fn, times) {
7
+ for(let i = 0; i < times; i++){
8
+ fn();
9
+ }
10
+ }
11
+
12
+ //# sourceMappingURL=repeat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/repeat.ts"],"sourcesContent":["/**\n * Repeats the execution of a given function a specified number of times.\n *\n * @param fn - The function to be executed repeatedly. It should not take any arguments and should not return any value.\n * @param times - The number of times to execute the function.\n */\nexport function repeat(fn: VoidFunction, times: number): void {\n for (let i = 0; i < times; i++) {\n fn();\n }\n}\n"],"names":["repeat","fn","times","i"],"mappings":"AAAA;;;;;CAKC,GACD,OAAO,SAASA,OAAOC,EAAgB,EAAEC,KAAa;IACpD,IAAK,IAAIC,IAAI,GAAGA,IAAID,OAAOC,IAAK;QAC9BF;IACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cognite/signal-utils",
3
- "version": "1.0.1",
3
+ "version": "1.48411.0",
4
4
  "description": "A thin, framework-agnostic wrapper around Preact Signals for reactive state management.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -29,15 +29,19 @@
29
29
  "@preact/signals-core": "^1.8.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@nx/eslint-plugin": "22.7.8",
33
32
  "@testing-library/react": "16.0.1",
34
33
  "@types/react": "18.3.14",
35
34
  "@vitejs/plugin-react": "^5.2.0",
36
35
  "react": "^18.3.1",
37
- "vite": "8.2.2",
36
+ "vite": "8.2.4",
38
37
  "vitest": "^4.1.10"
39
38
  },
40
39
  "peerDependencies": {
41
40
  "react": "^18.3.1"
41
+ },
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "https://github.com/cognitedata/infrastructure.git",
45
+ "directory": "lib/ts/shared/signal-utils"
42
46
  }
43
47
  }