@solid-primitives/deep 0.2.1 → 0.2.3

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 (2) hide show
  1. package/dist/index.d.cts +80 -0
  2. package/package.json +3 -3
@@ -0,0 +1,80 @@
1
+ import { Store } from 'solid-js/store';
2
+
3
+ /**
4
+ * Tracks all properties of a {@link store} by iterating over them recursively.
5
+ *
6
+ * @param store reactive store dependency
7
+ * @returns same {@link store} that was passed in
8
+ *
9
+ * @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/deep#trackDeep
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * createEffect(on(
14
+ * () => trackDeep(store),
15
+ * () => {
16
+ * // this effect will run when any property of store changes
17
+ * }
18
+ * ));
19
+ * ```
20
+ */
21
+ declare function trackDeep<T extends Store<object>>(store: T): T;
22
+ /**
23
+ * @deprecated Renamed to {@link trackDeep}
24
+ */
25
+ declare const deepTrack: typeof trackDeep;
26
+
27
+ /**
28
+ * Tracks all nested changes to passed {@link store}.
29
+ *
30
+ * @param store a reactive store proxy
31
+ * @returns same {@link store} that was passed in
32
+ *
33
+ * @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/deep#trackStore
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * createEffect(on(
38
+ * () => trackStore(store),
39
+ * () => {
40
+ * // this effect will run when any property of store changes
41
+ * }
42
+ * ));
43
+ * ```
44
+ */
45
+ declare function trackStore<T extends object>(store: Store<T>): T;
46
+
47
+ type Static<T = unknown> = {
48
+ [K in number | string]: T;
49
+ } | T[];
50
+ type AllNestedObjects<T> = T extends Static<infer U> ? AllNestedObjects<U> | T : never;
51
+ type NestedUpdate<T> = {
52
+ path: (string | number)[];
53
+ value: AllNestedObjects<T>;
54
+ };
55
+ /**
56
+ * Creates a function for tracking and capturing updates to a {@link store}.
57
+ *
58
+ * Each execution of the returned function will return an array of updates to the store since the last execution.
59
+ *
60
+ * @param store - The store to track.
61
+ * @returns A function that returns an array of updates to the store since the last execution.
62
+ *
63
+ * @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/deep#captureStoreUpdates
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * const [state, setState] = createStore({ todos: [] });
68
+ *
69
+ * const getDelta = captureStoreUpdates(state);
70
+ *
71
+ * getDelta(); // [{ path: [], value: { todos: [] } }]
72
+ *
73
+ * setState("todos", ["foo"]);
74
+ *
75
+ * getDelta(); // [{ path: ["todos"], value: ["foo"] }]
76
+ * ```
77
+ */
78
+ declare function captureStoreUpdates<T extends Static>(store: T): () => NestedUpdate<T>[];
79
+
80
+ export { AllNestedObjects, NestedUpdate, captureStoreUpdates, deepTrack, trackDeep, trackStore };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solid-primitives/deep",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Primitives for tracking and observing nested reactive objects in Solid.",
5
5
  "author": "Samuel Burbano <me@iosamuel.dev>",
6
6
  "contributors": [
@@ -52,13 +52,13 @@
52
52
  },
53
53
  "typesVersions": {},
54
54
  "dependencies": {
55
- "@solid-primitives/memo": "^1.3.2"
55
+ "@solid-primitives/memo": "^1.3.4"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "solid-js": "^1.6.12"
59
59
  },
60
60
  "devDependencies": {
61
- "solid-js": "1.7.6"
61
+ "solid-js": "1.7.9"
62
62
  },
63
63
  "scripts": {
64
64
  "dev": "jiti ../../scripts/dev.ts",