@kdeveloper/kvark 0.1.1 → 0.2.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 (2) hide show
  1. package/README.md +19 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -100,6 +100,25 @@ const doubleAtom = atom({
100
100
  });
101
101
  ```
102
102
 
103
+ ### `onMount`
104
+
105
+ Optional lifecycle hook that runs when the atom **first gains a subscriber** in a store (for example when a React component using `useAtomValue` mounts). It receives a synchronous `set(value)` that marks the atom `fresh` and notifies listeners — useful for timers, subscriptions, or imperative updates that should not go through `get`.
106
+
107
+ You may return a cleanup function; it runs when the **last** subscriber unsubscribes (for example when the last mounted consumer unmounts). If several components subscribe to the same atom, `onMount` runs once and the cleanup runs once after all of them unsubscribe.
108
+
109
+ ```ts
110
+ const clockAtom = atom({
111
+ debugLabel: "clock",
112
+ get: async () => new Date().toISOString(),
113
+ onMount: (set) => {
114
+ const id = setInterval(() => {
115
+ set(new Date().toISOString());
116
+ }, 1000);
117
+ return () => clearInterval(id);
118
+ },
119
+ });
120
+ ```
121
+
103
122
  ### Parallel loading
104
123
 
105
124
  Declaring multiple dependencies causes the Store to resolve them in parallel before calling `get`. Inside `get` you control the parallelism explicitly.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kdeveloper/kvark",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Atomic state management with explicit dependency graphs",
5
5
  "license": "MIT",
6
6
  "files": [