@ersbeth/picoflow 0.2.4 → 1.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.
Files changed (248) hide show
  1. package/.cursor/plans/update-js-e795d61b.plan.md +567 -0
  2. package/.gitlab-ci.yml +24 -0
  3. package/.vscode/settings.json +3 -3
  4. package/CHANGELOG.md +51 -0
  5. package/IMPLEMENTATION_GUIDE.md +1578 -0
  6. package/README.md +9 -134
  7. package/biome.json +32 -32
  8. package/dist/picoflow.js +610 -436
  9. package/dist/types/advanced/array.d.ts +0 -6
  10. package/dist/types/advanced/array.d.ts.map +1 -1
  11. package/dist/types/advanced/index.d.ts +5 -5
  12. package/dist/types/advanced/index.d.ts.map +1 -1
  13. package/dist/types/advanced/map.d.ts +114 -23
  14. package/dist/types/advanced/map.d.ts.map +1 -1
  15. package/dist/types/advanced/resource.d.ts +51 -12
  16. package/dist/types/advanced/resource.d.ts.map +1 -1
  17. package/dist/types/advanced/resourceAsync.d.ts +28 -13
  18. package/dist/types/advanced/resourceAsync.d.ts.map +1 -1
  19. package/dist/types/advanced/stream.d.ts +74 -16
  20. package/dist/types/advanced/stream.d.ts.map +1 -1
  21. package/dist/types/advanced/streamAsync.d.ts +69 -15
  22. package/dist/types/advanced/streamAsync.d.ts.map +1 -1
  23. package/dist/types/basic/constant.d.ts +44 -16
  24. package/dist/types/basic/constant.d.ts.map +1 -1
  25. package/dist/types/basic/derivation.d.ts +73 -24
  26. package/dist/types/basic/derivation.d.ts.map +1 -1
  27. package/dist/types/basic/disposable.d.ts +65 -6
  28. package/dist/types/basic/disposable.d.ts.map +1 -1
  29. package/dist/types/basic/effect.d.ts +27 -16
  30. package/dist/types/basic/effect.d.ts.map +1 -1
  31. package/dist/types/basic/index.d.ts +7 -8
  32. package/dist/types/basic/index.d.ts.map +1 -1
  33. package/dist/types/basic/observable.d.ts +62 -13
  34. package/dist/types/basic/observable.d.ts.map +1 -1
  35. package/dist/types/basic/signal.d.ts +35 -6
  36. package/dist/types/basic/signal.d.ts.map +1 -1
  37. package/dist/types/basic/state.d.ts +25 -4
  38. package/dist/types/basic/state.d.ts.map +1 -1
  39. package/dist/types/basic/trackingContext.d.ts +33 -0
  40. package/dist/types/basic/trackingContext.d.ts.map +1 -0
  41. package/dist/types/creators.d.ts +271 -26
  42. package/dist/types/creators.d.ts.map +1 -1
  43. package/dist/types/index.d.ts +60 -7
  44. package/dist/types/index.d.ts.map +1 -1
  45. package/dist/types/solid/converters.d.ts +5 -5
  46. package/dist/types/solid/converters.d.ts.map +1 -1
  47. package/dist/types/solid/index.d.ts +2 -2
  48. package/dist/types/solid/index.d.ts.map +1 -1
  49. package/dist/types/solid/primitives.d.ts +96 -4
  50. package/dist/types/solid/primitives.d.ts.map +1 -1
  51. package/docs/.vitepress/config.mts +110 -0
  52. package/docs/api/classes/FlowArray.md +489 -0
  53. package/docs/api/classes/FlowConstant.md +350 -0
  54. package/docs/api/classes/FlowDerivation.md +334 -0
  55. package/docs/api/classes/FlowEffect.md +100 -0
  56. package/docs/api/classes/FlowMap.md +512 -0
  57. package/docs/api/classes/FlowObservable.md +306 -0
  58. package/docs/api/classes/FlowResource.md +380 -0
  59. package/docs/api/classes/FlowResourceAsync.md +362 -0
  60. package/docs/api/classes/FlowSignal.md +160 -0
  61. package/docs/api/classes/FlowState.md +368 -0
  62. package/docs/api/classes/FlowStream.md +367 -0
  63. package/docs/api/classes/FlowStreamAsync.md +364 -0
  64. package/docs/api/classes/SolidDerivation.md +75 -0
  65. package/docs/api/classes/SolidResource.md +91 -0
  66. package/docs/api/classes/SolidState.md +71 -0
  67. package/docs/api/classes/TrackingContext.md +33 -0
  68. package/docs/api/functions/array.md +58 -0
  69. package/docs/api/functions/constant.md +45 -0
  70. package/docs/api/functions/derivation.md +53 -0
  71. package/docs/api/functions/effect.md +49 -0
  72. package/docs/api/functions/from.md +220 -0
  73. package/docs/api/functions/isDisposable.md +49 -0
  74. package/docs/api/functions/map.md +57 -0
  75. package/docs/api/functions/resource.md +52 -0
  76. package/docs/api/functions/resourceAsync.md +50 -0
  77. package/docs/api/functions/signal.md +36 -0
  78. package/docs/api/functions/state.md +47 -0
  79. package/docs/api/functions/stream.md +53 -0
  80. package/docs/api/functions/streamAsync.md +50 -0
  81. package/docs/api/index.md +118 -0
  82. package/docs/api/interfaces/FlowDisposable.md +65 -0
  83. package/docs/api/interfaces/SolidObservable.md +19 -0
  84. package/docs/api/type-aliases/FlowArrayAction.md +49 -0
  85. package/docs/api/type-aliases/FlowStreamDisposer.md +15 -0
  86. package/docs/api/type-aliases/FlowStreamSetter.md +27 -0
  87. package/docs/api/type-aliases/FlowStreamUpdater.md +32 -0
  88. package/docs/api/type-aliases/NotPromise.md +18 -0
  89. package/docs/api/type-aliases/SolidGetter.md +17 -0
  90. package/docs/api/typedoc-sidebar.json +1 -0
  91. package/docs/examples/examples.md +2313 -0
  92. package/docs/examples/patterns.md +649 -0
  93. package/docs/guide/advanced/disposal.md +426 -0
  94. package/docs/guide/advanced/solidjs.md +221 -0
  95. package/docs/guide/advanced/upgrading.md +464 -0
  96. package/docs/guide/introduction/concepts.md +56 -0
  97. package/docs/guide/introduction/conventions.md +61 -0
  98. package/docs/guide/introduction/getting-started.md +134 -0
  99. package/docs/guide/introduction/lifecycle.md +371 -0
  100. package/docs/guide/primitives/array.md +400 -0
  101. package/docs/guide/primitives/constant.md +380 -0
  102. package/docs/guide/primitives/derivations.md +348 -0
  103. package/docs/guide/primitives/effects.md +458 -0
  104. package/docs/guide/primitives/map.md +387 -0
  105. package/docs/guide/primitives/overview.md +175 -0
  106. package/docs/guide/primitives/resources.md +858 -0
  107. package/docs/guide/primitives/signal.md +259 -0
  108. package/docs/guide/primitives/state.md +368 -0
  109. package/docs/guide/primitives/streams.md +931 -0
  110. package/docs/index.md +47 -0
  111. package/docs/public/logo.svg +1 -0
  112. package/package.json +57 -41
  113. package/src/advanced/array.ts +208 -210
  114. package/src/advanced/index.ts +7 -7
  115. package/src/advanced/map.ts +178 -68
  116. package/src/advanced/resource.ts +87 -43
  117. package/src/advanced/resourceAsync.ts +62 -42
  118. package/src/advanced/stream.ts +113 -50
  119. package/src/advanced/streamAsync.ts +120 -61
  120. package/src/basic/constant.ts +82 -49
  121. package/src/basic/derivation.ts +128 -84
  122. package/src/basic/disposable.ts +74 -15
  123. package/src/basic/effect.ts +85 -77
  124. package/src/basic/index.ts +7 -8
  125. package/src/basic/observable.ts +94 -36
  126. package/src/basic/signal.ts +133 -105
  127. package/src/basic/state.ts +46 -25
  128. package/src/basic/trackingContext.ts +45 -0
  129. package/src/creators.ts +297 -54
  130. package/src/index.ts +96 -43
  131. package/src/solid/converters.ts +186 -67
  132. package/src/solid/index.ts +8 -2
  133. package/src/solid/primitives.ts +167 -65
  134. package/test/array.test.ts +592 -612
  135. package/test/constant.test.ts +31 -33
  136. package/test/derivation.test.ts +531 -536
  137. package/test/effect.test.ts +21 -21
  138. package/test/map.test.ts +233 -137
  139. package/test/resource.test.ts +119 -121
  140. package/test/resourceAsync.test.ts +98 -100
  141. package/test/signal.test.ts +51 -55
  142. package/test/state.test.ts +186 -168
  143. package/test/stream.test.ts +189 -189
  144. package/test/streamAsync.test.ts +186 -186
  145. package/tsconfig.json +19 -18
  146. package/typedoc.json +37 -0
  147. package/vite.config.ts +23 -23
  148. package/vitest.config.ts +7 -7
  149. package/api/doc/index.md +0 -31
  150. package/api/doc/picoflow.array.md +0 -55
  151. package/api/doc/picoflow.constant.md +0 -55
  152. package/api/doc/picoflow.derivation.md +0 -55
  153. package/api/doc/picoflow.effect.md +0 -55
  154. package/api/doc/picoflow.flowarray._constructor_.md +0 -49
  155. package/api/doc/picoflow.flowarray._lastaction.md +0 -13
  156. package/api/doc/picoflow.flowarray.clear.md +0 -17
  157. package/api/doc/picoflow.flowarray.dispose.md +0 -55
  158. package/api/doc/picoflow.flowarray.get.md +0 -19
  159. package/api/doc/picoflow.flowarray.length.md +0 -13
  160. package/api/doc/picoflow.flowarray.md +0 -273
  161. package/api/doc/picoflow.flowarray.pop.md +0 -17
  162. package/api/doc/picoflow.flowarray.push.md +0 -53
  163. package/api/doc/picoflow.flowarray.set.md +0 -53
  164. package/api/doc/picoflow.flowarray.setitem.md +0 -69
  165. package/api/doc/picoflow.flowarray.shift.md +0 -17
  166. package/api/doc/picoflow.flowarray.splice.md +0 -85
  167. package/api/doc/picoflow.flowarray.unshift.md +0 -53
  168. package/api/doc/picoflow.flowarrayaction.md +0 -37
  169. package/api/doc/picoflow.flowconstant._constructor_.md +0 -49
  170. package/api/doc/picoflow.flowconstant.get.md +0 -25
  171. package/api/doc/picoflow.flowconstant.md +0 -88
  172. package/api/doc/picoflow.flowderivation._constructor_.md +0 -49
  173. package/api/doc/picoflow.flowderivation.get.md +0 -23
  174. package/api/doc/picoflow.flowderivation.md +0 -86
  175. package/api/doc/picoflow.flowdisposable.dispose.md +0 -55
  176. package/api/doc/picoflow.flowdisposable.md +0 -43
  177. package/api/doc/picoflow.floweffect._constructor_.md +0 -54
  178. package/api/doc/picoflow.floweffect.dispose.md +0 -21
  179. package/api/doc/picoflow.floweffect.disposed.md +0 -13
  180. package/api/doc/picoflow.floweffect.md +0 -131
  181. package/api/doc/picoflow.flowgetter.md +0 -15
  182. package/api/doc/picoflow.flowmap._lastdeleted.md +0 -21
  183. package/api/doc/picoflow.flowmap._lastset.md +0 -21
  184. package/api/doc/picoflow.flowmap.delete.md +0 -61
  185. package/api/doc/picoflow.flowmap.md +0 -133
  186. package/api/doc/picoflow.flowmap.setat.md +0 -77
  187. package/api/doc/picoflow.flowobservable.get.md +0 -19
  188. package/api/doc/picoflow.flowobservable.md +0 -68
  189. package/api/doc/picoflow.flowobservable.subscribe.md +0 -55
  190. package/api/doc/picoflow.flowresource._constructor_.md +0 -49
  191. package/api/doc/picoflow.flowresource.fetch.md +0 -27
  192. package/api/doc/picoflow.flowresource.get.md +0 -23
  193. package/api/doc/picoflow.flowresource.md +0 -100
  194. package/api/doc/picoflow.flowresourceasync._constructor_.md +0 -49
  195. package/api/doc/picoflow.flowresourceasync.fetch.md +0 -27
  196. package/api/doc/picoflow.flowresourceasync.get.md +0 -23
  197. package/api/doc/picoflow.flowresourceasync.md +0 -100
  198. package/api/doc/picoflow.flowsignal.dispose.md +0 -59
  199. package/api/doc/picoflow.flowsignal.disposed.md +0 -18
  200. package/api/doc/picoflow.flowsignal.md +0 -112
  201. package/api/doc/picoflow.flowsignal.trigger.md +0 -21
  202. package/api/doc/picoflow.flowstate.md +0 -52
  203. package/api/doc/picoflow.flowstate.set.md +0 -61
  204. package/api/doc/picoflow.flowstream._constructor_.md +0 -49
  205. package/api/doc/picoflow.flowstream.dispose.md +0 -21
  206. package/api/doc/picoflow.flowstream.get.md +0 -23
  207. package/api/doc/picoflow.flowstream.md +0 -100
  208. package/api/doc/picoflow.flowstreamasync._constructor_.md +0 -54
  209. package/api/doc/picoflow.flowstreamasync.dispose.md +0 -21
  210. package/api/doc/picoflow.flowstreamasync.get.md +0 -23
  211. package/api/doc/picoflow.flowstreamasync.md +0 -100
  212. package/api/doc/picoflow.flowstreamdisposer.md +0 -13
  213. package/api/doc/picoflow.flowstreamsetter.md +0 -13
  214. package/api/doc/picoflow.flowstreamupdater.md +0 -19
  215. package/api/doc/picoflow.flowwatcher.md +0 -15
  216. package/api/doc/picoflow.from.md +0 -55
  217. package/api/doc/picoflow.from_1.md +0 -55
  218. package/api/doc/picoflow.from_2.md +0 -55
  219. package/api/doc/picoflow.from_3.md +0 -55
  220. package/api/doc/picoflow.from_4.md +0 -55
  221. package/api/doc/picoflow.from_5.md +0 -55
  222. package/api/doc/picoflow.isdisposable.md +0 -55
  223. package/api/doc/picoflow.map.md +0 -59
  224. package/api/doc/picoflow.md +0 -544
  225. package/api/doc/picoflow.resource.md +0 -55
  226. package/api/doc/picoflow.resourceasync.md +0 -55
  227. package/api/doc/picoflow.signal.md +0 -19
  228. package/api/doc/picoflow.solidderivation._constructor_.md +0 -49
  229. package/api/doc/picoflow.solidderivation.get.md +0 -13
  230. package/api/doc/picoflow.solidderivation.md +0 -94
  231. package/api/doc/picoflow.solidgetter.md +0 -13
  232. package/api/doc/picoflow.solidobservable.get.md +0 -13
  233. package/api/doc/picoflow.solidobservable.md +0 -57
  234. package/api/doc/picoflow.solidresource._constructor_.md +0 -49
  235. package/api/doc/picoflow.solidresource.get.md +0 -13
  236. package/api/doc/picoflow.solidresource.latest.md +0 -13
  237. package/api/doc/picoflow.solidresource.md +0 -157
  238. package/api/doc/picoflow.solidresource.refetch.md +0 -13
  239. package/api/doc/picoflow.solidresource.state.md +0 -13
  240. package/api/doc/picoflow.solidstate._constructor_.md +0 -49
  241. package/api/doc/picoflow.solidstate.get.md +0 -13
  242. package/api/doc/picoflow.solidstate.md +0 -115
  243. package/api/doc/picoflow.solidstate.set.md +0 -13
  244. package/api/doc/picoflow.state.md +0 -55
  245. package/api/doc/picoflow.stream.md +0 -55
  246. package/api/doc/picoflow.streamasync.md +0 -55
  247. package/api/picoflow.public.api.md +0 -244
  248. package/api-extractor.json +0 -61
@@ -1,11 +1,47 @@
1
1
  import { FlowObservable } from './observable';
2
2
  /**
3
- * Represents a reactive and immutable constant value computed lazily upon first access.
3
+ * Represents a reactive and immutable constant value that can be computed lazily upon first access.
4
4
  *
5
- * @remarks This class extends FlowObservable and supports initializing the constant using either a direct value
6
- * or a lazy initializer function. Once computed, the value is cached for all subsequent accesses.
5
+ * @remarks
6
+ * FlowConstant extends FlowObservable to provide an immutable reactive value. Unlike {@link FlowState},
7
+ * which is mutable via the `set()` method, a constant's value never changes after initialization.
7
8
  *
8
- * @typeparam T - The type of the constant value.
9
+ * **Initialization Patterns:**
10
+ * - **Direct value**: Pass a value directly; it's stored immediately.
11
+ * - **Lazy initialization**: Pass a function; it's called only when the value is first accessed
12
+ * via `get()` or `pick()`.
13
+ *
14
+ * **Lazy Evaluation Benefits:**
15
+ * Lazy initialization is useful when:
16
+ * - The computation is expensive and may not be needed immediately
17
+ * - The value depends on resources that aren't available at construction time
18
+ * - You want to defer computation until the value is actually needed
19
+ *
20
+ * **Caching:**
21
+ * Once computed (either immediately or lazily), the value is cached permanently. All subsequent
22
+ * accesses return the cached value without re-computation.
23
+ *
24
+ * **Use Cases:**
25
+ * - Configuration values that don't change
26
+ * - Expensive computations that should only run once
27
+ * - Initialization values for other reactive primitives
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * // Direct value - initialized immediately
32
+ * const $config = constant({ apiUrl: 'https://api.example.com' });
33
+ *
34
+ * // Lazy initialization - computed on first access
35
+ * const $expensiveValue = constant(() => {
36
+ * console.log('Computing...');
37
+ * return performExpensiveCalculation();
38
+ * });
39
+ *
40
+ * $expensiveValue.pick(); // Logs: "Computing..."
41
+ * $expensiveValue.pick(); // No log - returns cached value
42
+ * ```
43
+ *
44
+ * @typeParam T - The type of the constant value.
9
45
  *
10
46
  * @public
11
47
  */
@@ -13,20 +49,12 @@ export declare class FlowConstant<T> extends FlowObservable<T> {
13
49
  /**
14
50
  * Creates a new FlowConstant instance.
15
51
  *
16
- * @param value - Either a direct value of type T or a function returning a value of type T for lazy initialization.
17
- * @public
18
- */
19
- constructor(value: T | (() => T));
20
- /**
21
- * Retrieves the constant value, computing it lazily if needed.
22
- *
23
- * Accessing this method will initialize the value if it has not been computed already.
24
- * Throws an error if the instance has been disposed or if lazy initialization fails.
52
+ * @param value - Either a direct value of type T or a function returning a value of type T.
53
+ * If a function is provided, it will be invoked lazily on the first value access.
54
+ * If a direct value is provided, it is stored immediately.
25
55
  *
26
- * @returns The cached constant value.
27
- * @throws Error if the constant is disposed or cannot be initialized.
28
56
  * @public
29
57
  */
30
- get(): T;
58
+ constructor(value: T | (() => T));
31
59
  }
32
60
  //# sourceMappingURL=constant.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../../../src/basic/constant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C;;;;;;;;;GASG;AACH,qBAAa,YAAY,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;IAClD;;;;;OAKG;gBACS,KAAK,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAKhC;;;;;;;;;OASG;IACH,GAAG,IAAI,CAAC;CA6BX"}
1
+ {"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../../../src/basic/constant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,qBAAa,YAAY,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;IACrD;;;;;;;;OAQG;gBACS,KAAK,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;CAsChC"}
@@ -1,40 +1,89 @@
1
- import { FlowGetter, FlowObservable } from './observable';
2
- import { FlowWatcher } from './signal';
1
+ import { FlowObservable } from './observable';
2
+ import { TrackingContext } from './trackingContext';
3
3
  /**
4
4
  * Represents a reactive derivation whose value is computed based on other reactive signals.
5
+ *
5
6
  * @remarks
6
- * It tracks dependencies automatically and recomputes its value when any dependency changes.
7
- * Use FlowDerivation to create derived values in a reactive manner. It lazily initializes the computed value,
8
- * ensuring that computations only occur when necessary.
9
- * @typeparam T - The type of the computed value.
7
+ * FlowDerivation creates a computed value that automatically tracks its dependencies and
8
+ * recomputes when any dependency changes. The computation is lazy: it doesn't execute until
9
+ * the value is first accessed (via `get()` or `pick()`), and subsequent accesses return the
10
+ * cached value until a dependency changes.
11
+ *
12
+ * **Lazy Initialization:**
13
+ * The compute function doesn't run immediately upon creation. It runs only when:
14
+ * - The value is first read via `get()` or `pick()`
15
+ * - The derivation is watched via `watch()`
16
+ *
17
+ * **Dirty Checking and Recomputation:**
18
+ * When a tracked dependency changes, the derivation is marked as "dirty" but doesn't recompute
19
+ * immediately. Recomputation happens lazily on the next value access. This prevents unnecessary
20
+ * computations when multiple dependencies change in quick succession.
21
+ *
22
+ * **Dynamic Dependencies:**
23
+ * Dependencies are tracked dynamically during each computation. If the compute function
24
+ * conditionally tracks different observables, the dependency graph updates automatically.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const $firstName = state('John');
29
+ * const $lastName = state('Doe');
30
+ *
31
+ * const $fullName = derivation((t) => {
32
+ * return `${$firstName.get(t)} ${$lastName.get(t)}`;
33
+ * });
34
+ *
35
+ * // Compute function hasn't run yet (lazy)
36
+ * const name = $fullName.pick(); // Now it computes
37
+ * ```
38
+ *
39
+ * @typeParam T - The type of the computed value.
10
40
  * @public
11
41
  */
12
42
  export declare class FlowDerivation<T> extends FlowObservable<T> {
13
43
  /**
14
44
  * Creates a new FlowDerivation.
15
- * @param compute - A function that computes the derived value. It is provided with two parameters:
16
- * a getter and a watcher that respect dependency tracking.
45
+ *
46
+ * @param compute - A function that computes the derived value using a tracking context.
47
+ * The function receives a TrackingContext and should use it to access dependencies via
48
+ * `.get(t)`. The function is not executed immediately; it runs lazily on first access.
49
+ *
17
50
  * @public
18
51
  */
19
- constructor(compute: (get: FlowGetter, watch: FlowWatcher) => T);
52
+ constructor(compute: (t: TrackingContext) => T);
53
+ private _initialized;
54
+ private _dirty;
55
+ private _compute;
56
+ private _trackedContext;
57
+ private _initLazy;
20
58
  /**
21
- * Gets the current derived value.
22
- * @returns The current computed value.
59
+ * Watches the derivation, registering it as a dependency in the given context.
60
+ *
61
+ * @param context - The tracking context in which to register this derivation.
62
+ *
23
63
  * @remarks
24
- * This method lazily initializes and updates the derivation if it is marked as dirty. It throws an error
25
- * if the derivation has been disposed.
64
+ * This method overrides the base `watch()` to handle a special case: when a derivation
65
+ * is watched without having its value read (e.g., `$derivation.watch(t)` instead of
66
+ * `$derivation.get(t)`), the derivation still needs to compute its value to establish
67
+ * its own dependencies. Otherwise, the derivation would be tracked but wouldn't track
68
+ * its own dependencies, breaking the reactive chain.
69
+ *
70
+ * This override ensures that:
71
+ * 1. The derivation is registered as a dependency in the provided context
72
+ * 2. The derivation computes its value (if not already computed)
73
+ * 3. The derivation tracks its own dependencies during computation
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * const $derived = derivation((t) => $state.get(t) * 2);
78
+ *
79
+ * effect((t) => {
80
+ * $derived.watch(t); // Derivation computes even without reading value
81
+ * doSomething(); // Effect re-runs when $derived's dependencies change
82
+ * });
83
+ * ```
84
+ *
26
85
  * @public
27
86
  */
28
- get(): T;
29
- private _initialized;
30
- private _dirty;
31
- private _trackedGet;
32
- private _trackedWatch;
33
- private _untrackedGet;
34
- private _untrackedWatch;
35
- private _trackedCompute;
36
- private _untrackedCompute;
37
- private _initEager;
38
- private _initLazy;
87
+ watch(context: TrackingContext): void;
39
88
  }
40
89
  //# sourceMappingURL=derivation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"derivation.d.ts","sourceRoot":"","sources":["../../../src/basic/derivation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C;;;;;;;;GAQG;AACH,qBAAa,cAAc,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;IACpD;;;;;OAKG;gBACS,OAAO,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,KAAK,CAAC;IAK/D;;;;;;;OAOG;IACI,GAAG,IAAI,CAAC;IASf,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,MAAM,CAAS;IAEvB,OAAO,CAAC,WAAW,CAAyD;IAC5E,OAAO,CAAC,aAAa,CAAoD;IACzE,OAAO,CAAC,aAAa,CAAgD;IACrE,OAAO,CAAC,eAAe,CAA4C;IACnE,OAAO,CAAC,eAAe,CAAW;IAClC,OAAO,CAAC,iBAAiB,CAAW;IAEpC,OAAO,CAAC,UAAU;IASlB,OAAO,CAAC,SAAS;CA0CpB"}
1
+ {"version":3,"file":"derivation.d.ts","sourceRoot":"","sources":["../../../src/basic/derivation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,qBAAa,cAAc,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;IACvD;;;;;;;;OAQG;gBACS,OAAO,EAAE,CAAC,CAAC,EAAE,eAAe,KAAK,CAAC;IAmB9C,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAA4B;IAC5C,OAAO,CAAC,eAAe,CAAkB;IAEzC,OAAO,CAAC,SAAS;IAiCjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACa,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;CAQrD"}
@@ -1,22 +1,81 @@
1
1
  /**
2
- * Represents an object with a disposable lifecycle.
2
+ * Represents an object with a disposable lifecycle that manages resources requiring cleanup.
3
+ *
3
4
  * @remarks
4
- * Objects implementing this interface require explicit resource disposal.
5
+ * FlowDisposable is the interface for PicoFlow primitives that hold resources needing
6
+ * explicit cleanup. Implementing this interface ensures that objects can properly release
7
+ * resources such as subscriptions, event listeners, and dependent effects.
8
+ *
9
+ * **Disposal Behavior:**
10
+ * All PicoFlow reactive primitives (signals, states, effects, derivations, etc.) implement
11
+ * this interface. When disposed:
12
+ * - The primitive becomes unusable and throws errors on further access
13
+ * - All subscriptions and dependencies are cleaned up
14
+ * - Memory is freed for garbage collection
15
+ *
16
+ * **Options:**
17
+ * The optional `options` parameter controls disposal behavior:
18
+ * - `{ self: true }`: Dispose only this object, leaving dependent effects/listeners active
19
+ * - `{ self: false }` or omitted: Dispose this object AND all dependent effects/listeners (cascade)
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const $state = state(0);
24
+ * const fx = effect((t) => console.log($state.get(t)));
25
+ *
26
+ * // Cascade disposal - disposes $state and all its effects
27
+ * $state.dispose();
28
+ *
29
+ * // Self-only disposal - disposes $state but leaves effects intact
30
+ * $state.dispose({ self: true });
31
+ * ```
32
+ *
5
33
  * @public
6
34
  */
7
35
  export interface FlowDisposable {
8
36
  /**
9
37
  * Disposes resources held by this object.
10
- * @param options - Options to specify disposal behavior.
38
+ *
39
+ * @param options - Optional configuration for disposal behavior.
40
+ * @param options.self - When true, disposes only this object without cascading to dependents.
41
+ * When false or omitted, disposes this object and all its dependent effects and listeners.
42
+ *
43
+ * @throws Error if the object has already been disposed (behavior may vary by implementation).
11
44
  */
12
45
  dispose(options?: {
13
46
  self: boolean;
14
47
  }): void;
15
48
  }
16
49
  /**
17
- * Checks whether an object implements the FlowDisposable interface.
18
- * @param obj - The object to test.
19
- * @returns True if the object has a dispose method, otherwise false.
50
+ * Type guard that checks whether an object implements the FlowDisposable interface.
51
+ *
52
+ * @param obj - The object to test for disposability.
53
+ * @returns True if the object has a `dispose` method and is therefore disposable, false otherwise.
54
+ *
55
+ * @remarks
56
+ * This utility function is useful for safely checking if an object needs disposal before
57
+ * attempting cleanup operations. It performs a runtime check for the presence of a `dispose`
58
+ * method, making it safe to use with unknown types.
59
+ *
60
+ * **Common Use Cases:**
61
+ * - Conditionally disposing items in collections (arrays, maps)
62
+ * - Generic cleanup functions that handle both disposable and non-disposable objects
63
+ * - Defensive programming when working with mixed types
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * function cleanupArray<T>(items: T[]) {
68
+ * items.forEach(item => {
69
+ * if (isDisposable(item)) {
70
+ * item.dispose();
71
+ * }
72
+ * });
73
+ * }
74
+ *
75
+ * const mixed = [state(1), "string", signal(), 42];
76
+ * cleanupArray(mixed); // Only disposes the state and signal
77
+ * ```
78
+ *
20
79
  * @public
21
80
  */
22
81
  export declare function isDisposable(obj: unknown): obj is FlowDisposable;
@@ -1 +1 @@
1
- {"version":3,"file":"disposable.d.ts","sourceRoot":"","sources":["../../../src/basic/disposable.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC3B;;;OAGG;IACH,OAAO,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;CAC9C;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,cAAc,CAMhE"}
1
+ {"version":3,"file":"disposable.d.ts","sourceRoot":"","sources":["../../../src/basic/disposable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,WAAW,cAAc;IAC9B;;;;;;;;OAQG;IACH,OAAO,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;CAC3C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,cAAc,CAMhE"}
@@ -1,13 +1,28 @@
1
- import { FlowGetter } from './observable';
2
- import { FlowWatcher } from './signal';
1
+ import { TrackingContext } from './trackingContext';
3
2
  /**
4
3
  * Represents a reactive effect that executes side-effect functions based
5
4
  * on its tracked dependencies.
6
5
  *
7
6
  * @remarks
8
- * The FlowEffect executes an apply function that performs side effects,
9
- * running initially in a tracked mode to register dependencies and then in
10
- * an untracked mode to re-execute the effect on updates.
7
+ * FlowEffect executes an apply function that performs side effects. The effect always runs
8
+ * with a tracking context, allowing you to explicitly control which observables and signals
9
+ * become dependencies using `.get(t)` for tracked reads or `.pick()` for untracked reads.
10
+ *
11
+ * When any tracked dependency changes, the effect automatically re-executes. The effect
12
+ * runs immediately upon creation and whenever its dependencies trigger updates.
13
+ *
14
+ * Unlike the old API, effects in the new TrackingContext-based system always execute with
15
+ * a tracking context available. You control reactivity by choosing which observables to track
16
+ * within the effect body.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const fx = effect((t) => {
21
+ * const reactive = $stateA.get(t); // Tracked - effect re-runs when $stateA changes
22
+ * const snapshot = $stateB.pick(); // Not tracked - changes don't trigger re-runs
23
+ * console.log(reactive, snapshot);
24
+ * });
25
+ * ```
11
26
  *
12
27
  * @public
13
28
  */
@@ -15,16 +30,17 @@ export declare class FlowEffect {
15
30
  /**
16
31
  * Creates a new FlowEffect.
17
32
  *
18
- * @param apply - A side-effect function that receives a getter and a watcher to
33
+ * @param apply - A side-effect function that receives a tracking context to
19
34
  * access and register dependencies on reactive observables and signals.
20
35
  *
21
36
  * @remarks
22
- * The provided function is executed immediately in a tracked mode to collect dependencies.
23
- * On subsequent executions, it runs in an untracked mode.
37
+ * The provided function is executed immediately upon construction with a tracking context.
38
+ * Use the context parameter to call `.get(t)` on observables you want to track, or `.pick()`
39
+ * on observables you want to read without creating dependencies.
24
40
  *
25
41
  * @public
26
42
  */
27
- constructor(apply: (get: FlowGetter, watch: FlowWatcher) => void);
43
+ constructor(apply: (t: TrackingContext) => void);
28
44
  /**
29
45
  * Disposes the effect, unregistering all its tracked dependencies.
30
46
  *
@@ -44,13 +60,8 @@ export declare class FlowEffect {
44
60
  */
45
61
  get disposed(): boolean;
46
62
  private _disposed;
47
- private _initialized;
48
63
  private _dependencies;
49
- private _trackedGet;
50
- private _trackedWatch;
51
- private _untrackedGet;
52
- private _untrackedWatch;
53
- private _trackedExec;
54
- private _untrackedExec;
64
+ private _trackedContext;
65
+ private _apply;
55
66
  }
56
67
  //# sourceMappingURL=effect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"effect.d.ts","sourceRoot":"","sources":["../../../src/basic/effect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAc,WAAW,EAAE,MAAM,UAAU,CAAC;AAExD;;;;;;;;;;GAUG;AACH,qBAAa,UAAU;IACnB;;;;;;;;;;;OAWG;gBACS,KAAK,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,KAAK,IAAI;IAOhE;;;;;;;;OAQG;IACI,OAAO,IAAI,IAAI;IAQtB;;;;;;OAMG;IACH,IAAW,QAAQ,IAAI,OAAO,CAE7B;IAID,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,aAAa,CAAyB;IAE9C,OAAO,CAAC,WAAW,CAAyD;IAC5E,OAAO,CAAC,aAAa,CAAoD;IACzE,OAAO,CAAC,aAAa,CAAgD;IACrE,OAAO,CAAC,eAAe,CAA4C;IACnE,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,cAAc,CAAa;CAsBtC"}
1
+ {"version":3,"file":"effect.d.ts","sourceRoot":"","sources":["../../../src/basic/effect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,UAAU;IACtB;;;;;;;;;;;;OAYG;gBACS,KAAK,EAAE,CAAC,CAAC,EAAE,eAAe,KAAK,IAAI;IAM/C;;;;;;;;OAQG;IACI,OAAO,IAAI,IAAI;IAQtB;;;;;;OAMG;IACH,IAAW,QAAQ,IAAI,OAAO,CAE7B;IAID,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,aAAa,CAAyB;IAC9C,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,MAAM,CAA+B;CAoB7C"}
@@ -1,11 +1,10 @@
1
- export { FlowSignal } from './signal';
2
- export { FlowState } from './state';
3
- export { FlowObservable } from './observable';
4
- export { FlowDerivation } from './derivation';
5
- export { FlowEffect } from './effect';
6
1
  export { FlowConstant } from './constant';
7
- export { isDisposable } from './disposable';
8
- export type { FlowGetter } from './observable';
9
- export type { FlowWatcher } from './signal';
2
+ export { FlowDerivation } from './derivation';
10
3
  export type { FlowDisposable } from './disposable';
4
+ export { isDisposable } from './disposable';
5
+ export { FlowEffect } from './effect';
6
+ export { FlowObservable } from './observable';
7
+ export { FlowSignal } from './signal';
8
+ export { FlowState } from './state';
9
+ export { TrackingContext } from './trackingContext';
11
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/basic/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/basic/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
@@ -1,28 +1,77 @@
1
1
  import { FlowSignal } from './signal';
2
- /**
3
- * A function that retrieves the current value from a FlowObservable.
4
- * @typeparam T - The type of the value held by the observable.
5
- * @param observable - The FlowObservable instance to retrieve the value from.
6
- * @returns The current value of the observable.
7
- * @public
8
- */
9
- export type FlowGetter = <T>(observable: FlowObservable<T>) => T;
2
+ import { TrackingContext } from './trackingContext';
10
3
  /**
11
4
  * Represents a reactive observable that holds and tracks a value.
12
5
  *
6
+ * @remarks
7
+ * FlowObservable is the base class for all reactive values in PicoFlow. It provides two ways
8
+ * to access the current value:
9
+ *
10
+ * 1. **Tracked access** via `get(context)`: Registers the observable as a dependency in the
11
+ * tracking context, so changes trigger re-execution of the effect or derivation.
12
+ *
13
+ * 2. **Untracked access** via `pick()` or `get(null)`: Reads the current value without registering
14
+ * a dependency, useful for reading values within effects that shouldn't trigger re-runs.
13
15
  *
14
- * @remarks Subclasses must implement the {@link FlowObservable.get} method to return the current value.
15
- * @typeparam T - The type of the value held by the observable.
16
+ * Subclasses must implement the {@link FlowObservable._getRaw} method to provide the actual value.
17
+ *
18
+ * @typeParam T - The type of the value held by the observable.
16
19
  * @public
17
20
  */
18
21
  export declare abstract class FlowObservable<T> extends FlowSignal {
19
22
  /**
20
- * Retrieves the current value stored in the observable.
21
- * Subclasses must override this method to provide the current value.
23
+ * Gets the current value with optional dependency tracking.
24
+ *
25
+ * @param context - The tracking context for reactive tracking, or null for untracked access.
26
+ * When a context is provided, this observable is registered as a dependency. When null,
27
+ * the value is read without any tracking.
28
+ *
29
+ * @returns The current value of type T.
30
+ *
31
+ * @remarks
32
+ * Use `get(t)` within effects and derivations to create reactive dependencies.
33
+ * Use `get(null)` when you need to read a value without tracking (though `pick()` is more idiomatic).
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * effect((t) => {
38
+ * const tracked = $state.get(t); // Dependency registered
39
+ * const untracked = $other.get(null); // No dependency
40
+ * });
41
+ * ```
42
+ *
43
+ * @public
44
+ */
45
+ get(context: TrackingContext | null): T;
46
+ /**
47
+ * Gets the current value without any dependency tracking.
48
+ *
22
49
  * @returns The current value of type T.
50
+ *
51
+ * @remarks
52
+ * This method is equivalent to calling `get(null)` but provides a more semantic and readable API.
53
+ * Use `pick()` when you want to read a snapshot of the current value without creating a reactive
54
+ * dependency. This is useful for:
55
+ * - Reading initial values
56
+ * - Accessing configuration that shouldn't trigger updates
57
+ * - Mixing tracked and untracked reads in the same effect
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * // Read a snapshot outside reactive context
62
+ * const currentValue = $state.pick();
63
+ *
64
+ * // Mix tracked and untracked reads
65
+ * effect((t) => {
66
+ * const tracked = $reactive.get(t); // Triggers re-runs
67
+ * const snapshot = $config.pick(); // Doesn't trigger re-runs
68
+ * processData(tracked, snapshot);
69
+ * });
70
+ * ```
71
+ *
23
72
  * @public
24
73
  */
25
- abstract get(): T;
74
+ pick(): T;
26
75
  /**
27
76
  * Subscribes a listener function to changes of the observable.
28
77
  * The listener is executed immediately with the current value and on subsequent updates.
@@ -1 +1 @@
1
- {"version":3,"file":"observable.d.ts","sourceRoot":"","sources":["../../../src/basic/observable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAEjE;;;;;;;GAOG;AACH,8BAAsB,cAAc,CAAC,CAAC,CAAE,SAAQ,UAAU;IACtD;;;;;OAKG;IACH,QAAQ,CAAC,GAAG,IAAI,CAAC;IAWjB;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI;CAMtD"}
1
+ {"version":3,"file":"observable.d.ts","sourceRoot":"","sources":["../../../src/basic/observable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD;;;;;;;;;;;;;;;;;GAiBG;AACH,8BAAsB,cAAc,CAAC,CAAC,CAAE,SAAQ,UAAU;IACzD;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,GAAG,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,GAAG,CAAC;IAOvC;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,IAAI,IAAI,CAAC;IAeT;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI;CAMnD"}
@@ -1,10 +1,5 @@
1
1
  import { FlowDisposable } from './disposable';
2
- /**
3
- * A function for watching a FlowSignal.
4
- * @param signal - The FlowSignal that is being observed.
5
- * @public
6
- */
7
- export type FlowWatcher = (signal: FlowSignal) => void;
2
+ import { TrackingContext } from './trackingContext';
8
3
  /**
9
4
  * Represents a reactive signal.
10
5
  *
@@ -20,6 +15,40 @@ export declare class FlowSignal implements FlowDisposable {
20
15
  * @public
21
16
  */
22
17
  trigger(): void;
18
+ /**
19
+ * Watches the signal, registering it as a dependency in the tracking context.
20
+ *
21
+ * @param context - The tracking context in which to register this signal as a dependency.
22
+ *
23
+ * @remarks
24
+ * Use `watch()` when you want to track a signal without reading its value (signals don't
25
+ * have values to read). This is useful for triggering effects based on signal events
26
+ * without needing associated data.
27
+ *
28
+ * When the signal is triggered via `trigger()`, any effects or derivations that have
29
+ * watched this signal will automatically re-execute.
30
+ *
31
+ * This method must be called within an effect or derivation context where a TrackingContext
32
+ * is available. For observables (which hold values), use `.get(t)` instead, which both
33
+ * reads the value and watches for changes.
34
+ *
35
+ * @throws Error if the signal has been disposed.
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const $signal = signal();
40
+ *
41
+ * effect((t) => {
42
+ * $signal.watch(t); // Track the signal
43
+ * console.log('Signal triggered!');
44
+ * });
45
+ *
46
+ * $signal.trigger(); // Logs: "Signal triggered!"
47
+ * ```
48
+ *
49
+ * @public
50
+ */
51
+ watch(context: TrackingContext): void;
23
52
  /**
24
53
  * Disposes the FlowSignal.
25
54
  * Cleans up all registered effects, listeners, and dependencies.
@@ -1 +1 @@
1
- {"version":3,"file":"signal.d.ts","sourceRoot":"","sources":["../../../src/basic/signal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGnD;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;AAEvD;;;;;;GAMG;AACH,qBAAa,UAAW,YAAW,cAAc;IAC7C;;;;;OAKG;IACI,OAAO,IAAI,IAAI;IAKtB;;;;;;OAMG;IACI,OAAO,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;IAqBjD;;;;OAIG;IACH,IAAW,QAAQ,IAAI,OAAO,CAE7B;CAoDJ"}
1
+ {"version":3,"file":"signal.d.ts","sourceRoot":"","sources":["../../../src/basic/signal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD;;;;;;GAMG;AACH,qBAAa,UAAW,YAAW,cAAc;IAChD;;;;;OAKG;IACI,OAAO,IAAI,IAAI;IAKtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACI,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IAK5C;;;;;;OAMG;IACI,OAAO,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;IAuBjD;;;;OAIG;IACH,IAAW,QAAQ,IAAI,OAAO,CAE7B;CA8CD"}
@@ -2,12 +2,33 @@ import { FlowConstant } from './constant';
2
2
  /**
3
3
  * Represents a reactive state that holds a mutable value.
4
4
  *
5
- * @typeparam T - The type of the state value.
5
+ * @typeParam T - The type of the state value.
6
6
  *
7
7
  * @remarks
8
- * FlowState extends FlowConstant, which provides the {@link FlowConstant.get} method to read
9
- * the current state. Use the {@link FlowState.set} method to update the state. When the state is updated,
10
- * subscribers are notified automatically. This class notifies subscribers only when the value changes.
8
+ * FlowState extends FlowConstant and inherits reactive value access methods from FlowObservable.
9
+ * You can read the state value using `get(context)` for tracked access or `pick()` for untracked access.
10
+ * Use the {@link FlowState.set} method to update the state value.
11
+ *
12
+ * When the state is updated with a new value that differs from the current value, all dependent
13
+ * effects and derivations are automatically notified and re-executed. If the new value is strictly
14
+ * equal to the current value, no notification occurs.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const $count = state(0);
19
+ *
20
+ * // Read with tracking
21
+ * effect((t) => {
22
+ * console.log($count.get(t)); // Effect re-runs when $count changes
23
+ * });
24
+ *
25
+ * // Read without tracking
26
+ * const snapshot = $count.pick();
27
+ *
28
+ * // Update the value
29
+ * $count.set(1);
30
+ * $count.set(current => current + 1);
31
+ * ```
11
32
  *
12
33
  * @public
13
34
  */
@@ -1 +1 @@
1
- {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/basic/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C;;;;;;;;;;;GAWG;AACH,qBAAa,SAAS,CAAC,CAAC,CAAE,SAAQ,YAAY,CAAC,CAAC,CAAC;IAC7C;;;;;;;;OAQG;IACH,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI;CAc5C"}
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/basic/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBAAa,SAAS,CAAC,CAAC,CAAE,SAAQ,YAAY,CAAC,CAAC,CAAC;IAChD;;;;;;;;OAQG;IACH,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI;CAczC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Represents a tracking context used to register dependencies during reactive computations.
3
+ *
4
+ * @remarks
5
+ * TrackingContext is the core mechanism that enables automatic dependency tracking in PicoFlow's
6
+ * reactive system. When you create an effect or derivation, PicoFlow automatically creates and
7
+ * manages a TrackingContext instance for you. This context is passed as a parameter (typically
8
+ * named `t`) to your computation functions.
9
+ *
10
+ * You use the tracking context to explicitly mark which observables should be tracked as dependencies:
11
+ * - Call `observable.get(t)` to read a value AND register it as a dependency
12
+ * - Call `observable.pick()` to read a value WITHOUT registering it as a dependency
13
+ * - Call `signal.watch(t)` to register a signal as a dependency without reading a value
14
+ *
15
+ * End-users typically don't instantiate TrackingContext directly; instead, they receive it as
16
+ * a parameter in effect and derivation callbacks.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // TrackingContext passed as parameter 't'
21
+ * effect((t) => {
22
+ * const value = $state.get(t); // Tracked dependency
23
+ * const snapshot = $other.pick(); // Not tracked
24
+ * console.log(value, snapshot);
25
+ * });
26
+ * ```
27
+ *
28
+ * @public
29
+ */
30
+ export declare class TrackingContext {
31
+ private _owner;
32
+ }
33
+ //# sourceMappingURL=trackingContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trackingContext.d.ts","sourceRoot":"","sources":["../../../src/basic/trackingContext.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,eAAe;IAEf,OAAO,CAAC,MAAM;CAS1B"}