@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
@@ -50,12 +50,6 @@ export declare class FlowArray<T> extends FlowObservable<T[]> {
50
50
  * @public
51
51
  */
52
52
  get length(): number;
53
- /**
54
- * Returns a copy of the internal array.
55
- * @returns A copy of the array.
56
- * @public
57
- */
58
- get(): T[];
59
53
  /**
60
54
  * Replaces the entire array with new items.
61
55
  * @param items - The new array of items.
@@ -1 +1 @@
1
- {"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../../src/advanced/array.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAI1D;;;GAGG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IACvB;IACI,IAAI,EAAE,KAAK,CAAC;IACZ,KAAK,EAAE,CAAC,EAAE,CAAC;CACd,GACD;IACI,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,CAAC,CAAC;CACX,GACD;IACI,IAAI,EAA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E,IAAI,EAAE,CAAC,GAAG,IAAI;IAUrC;;;;OAIG;IACH,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI;IAOnB;;;OAGG;IACH,GAAG,IAAI,IAAI;IAUX;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI;IAOtB;;;OAGG;IACH,KAAK,IAAI,IAAI;IAUb;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,CAAC,EAAE,GAAG,IAAI;IAelE;;;OAGG;IACH,KAAK,IAAI,IAAI;IAWb;;;;OAIG;IACM,OAAO,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;CAWnD"}
@@ -1,9 +1,9 @@
1
+ export type { FlowArrayAction } from './array';
2
+ export { FlowArray } from './array';
1
3
  export { FlowMap } from './map';
2
- export { FlowStream } from './stream';
3
- export { FlowStreamAsync } from './streamAsync';
4
4
  export { FlowResource } from './resource';
5
5
  export { FlowResourceAsync } from './resourceAsync';
6
- export type { FlowStreamUpdater, FlowStreamDisposer, FlowStreamSetter, } from './stream';
7
- export { FlowArray } from './array';
8
- export type { FlowArrayAction } from './array';
6
+ export type { FlowStreamDisposer, FlowStreamSetter, FlowStreamUpdater, } from './stream';
7
+ export { FlowStream } from './stream';
8
+ export { FlowStreamAsync } from './streamAsync';
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/advanced/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,YAAY,EACR,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,GACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/advanced/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,YAAY,EACX,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,GACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
@@ -1,36 +1,103 @@
1
1
  import { FlowState } from '../basic/';
2
2
  /**
3
- * Represents a reactive map of states extending {@link FlowState} for a Map of key/value pairs.
3
+ * Represents a reactive map that extends {@link FlowState} for tracking key-value pairs.
4
4
  *
5
5
  * @remarks
6
- * FlowMap wraps a native Map and provides reactive signals for fine-grained tracking
7
- * of updates to the map. In addition to the reactive capabilities inherited from FlowState,
8
- * it exposes two reactive signals:
6
+ * FlowMap wraps a native JavaScript Map and provides reactive tracking at multiple granularity levels.
7
+ * Unlike plain reactive state, FlowMap offers fine-grained reactivity that lets you track:
9
8
  *
10
- * $lastSet: Holds the most recent key-value pair that was set.
11
- * $lastDeleted: Holds the most recent key-value pair that was deleted.
9
+ * 1. **Whole map changes**: Via `get(t)` or `pick()` on the FlowMap itself
10
+ * 2. **Last add operation**: Via the `$lastAdded` signal, track which key-value pair was most recently added
11
+ * 3. **Last update operation**: Via the `$lastUpdated` signal, track which key-value pair was most recently updated
12
+ * 4. **Last delete operation**: Via the `$lastDeleted` signal, track which key-value pair was most recently removed
12
13
  *
13
- * Use {@link FlowMap.setAt} to add or update a key-value pair and {@link FlowMap.delete} to remove a key.
14
+ * **Reactive Signals:**
15
+ * - **$lastAdded**: A FlowState containing `{ key?: K, value?: V }` updated on each `add()` call
16
+ * - **$lastUpdated**: A FlowState containing `{ key?: K, value?: V }` updated on each `update()` call
17
+ * - **$lastDeleted**: A FlowState containing `{ key?: K, value?: V }` updated on each `delete()` call
14
18
  *
15
- * @typeparam K - The type of the map keys.
16
- * @typeparam V - The type of the map values.
19
+ * These signals enable fine-grained reactivity patterns where effects can respond to specific
20
+ * map operations without re-processing the entire map.
21
+ *
22
+ * **Use Cases:**
23
+ * - Entity stores where you want to track additions/removals separately
24
+ * - Cache implementations with granular invalidation
25
+ * - Collections where operations on individual keys matter
26
+ * - UI state where you want to animate specific additions or removals
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const $users = map<string, User>();
31
+ *
32
+ * // Track the whole map
33
+ * effect((t) => {
34
+ * const users = $users.get(t);
35
+ * console.log(`Total users: ${users.size}`);
36
+ * });
37
+ *
38
+ * // Track only additions
39
+ * effect((t) => {
40
+ * const { key, value } = $users.$lastAdded.get(t);
41
+ * if (key && value) {
42
+ * console.log(`User ${key} was added:`, value);
43
+ * }
44
+ * });
45
+ *
46
+ * // Track only updates
47
+ * effect((t) => {
48
+ * const { key, value } = $users.$lastUpdated.get(t);
49
+ * if (key && value) {
50
+ * console.log(`User ${key} was updated:`, value);
51
+ * }
52
+ * });
53
+ *
54
+ * // Track only deletions
55
+ * effect((t) => {
56
+ * const { key, value } = $users.$lastDeleted.get(t);
57
+ * if (key && value) {
58
+ * console.log(`User ${key} was deleted:`, value);
59
+ * }
60
+ * });
61
+ *
62
+ * // Modify the map
63
+ * $users.add('user1', { name: 'John', age: 30 });
64
+ * $users.add('user2', { name: 'Jane', age: 25 });
65
+ * $users.update('user1', { name: 'John', age: 31 });
66
+ * $users.delete('user1');
67
+ * ```
68
+ *
69
+ * @typeParam K - The type of the map keys.
70
+ * @typeParam V - The type of the map values.
17
71
  *
18
72
  * @public
19
73
  */
20
74
  export declare class FlowMap<K, V> extends FlowState<Map<K, V>> {
21
75
  /**
22
- * A reactive state that holds the most recent key and value that were set.
76
+ * A reactive state that holds the most recent key and value that were added.
23
77
  *
24
78
  * @remarks
25
- * When a key is set via {@link FlowMap.setAt}, this state is updated with
79
+ * When a key is added via {@link FlowMap.add}, this state is updated with
26
80
  * the corresponding key and value.
27
81
  *
28
82
  * @public
29
83
  */
30
- $lastSet: FlowState<{
31
- key?: K;
32
- value?: V;
33
- }>;
84
+ $lastAdded: FlowState<{
85
+ key: K;
86
+ value: V;
87
+ } | null>;
88
+ /**
89
+ * A reactive state that holds the most recent key and value that were updated.
90
+ *
91
+ * @remarks
92
+ * When a key is updated via {@link FlowMap.update}, this state is updated with
93
+ * the corresponding key and value.
94
+ *
95
+ * @public
96
+ */
97
+ $lastUpdated: FlowState<{
98
+ key: K;
99
+ value: V;
100
+ } | null>;
34
101
  /**
35
102
  * A reactive state that holds the most recent key and value that were deleted.
36
103
  *
@@ -41,23 +108,39 @@ export declare class FlowMap<K, V> extends FlowState<Map<K, V>> {
41
108
  * @public
42
109
  */
43
110
  $lastDeleted: FlowState<{
44
- key?: K;
45
- value?: V;
46
- }>;
111
+ key: K;
112
+ value: V;
113
+ } | null>;
47
114
  /**
48
- * Sets a value at the specified key in the underlying map.
115
+ * Adds a new key-value pair to the map.
49
116
  *
50
- * @param key - The key at which to set the value.
51
- * @param value - The value to set.
117
+ * @param key - The key to add.
118
+ * @param value - The value to associate with the key.
52
119
  * @throws If the FlowMap instance is disposed.
120
+ * @throws If the key already exists in the map.
53
121
  *
54
122
  * @remarks
55
- * Updates the internal map, emits the key-value pair via {@link FlowMap.$lastSet},
123
+ * Adds a new entry to the internal map, emits the key-value pair via {@link FlowMap.$lastAdded},
56
124
  * and notifies all subscribers of the change.
57
125
  *
58
126
  * @public
59
127
  */
60
- setAt(key: K, value: V): void;
128
+ add(key: K, value: V): void;
129
+ /**
130
+ * Updates an existing key-value pair in the map.
131
+ *
132
+ * @param key - The key to update.
133
+ * @param value - The new value to associate with the key.
134
+ * @throws If the FlowMap instance is disposed.
135
+ * @throws If the key does not exist in the map.
136
+ *
137
+ * @remarks
138
+ * Updates an existing entry in the internal map, emits the key-value pair via {@link FlowMap.$lastUpdated},
139
+ * and notifies all subscribers of the change.
140
+ *
141
+ * @public
142
+ */
143
+ update(key: K, value: V): void;
61
144
  /**
62
145
  * Deletes the value at the specified key from the underlying map.
63
146
  *
@@ -71,5 +154,13 @@ export declare class FlowMap<K, V> extends FlowState<Map<K, V>> {
71
154
  * @public
72
155
  */
73
156
  delete(key: K): void;
157
+ /**
158
+ * Disposes the FlowMap and its values.
159
+ * @param options - Disposal options.
160
+ * @public
161
+ */
162
+ dispose(options?: {
163
+ self: boolean;
164
+ }): void;
74
165
  }
75
166
  //# sourceMappingURL=map.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../../src/advanced/map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,OAAO,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACnD;;;;;;;;OAQG;IACI,QAAQ,EAAE,SAAS,CAAC;QAAE,GAAG,CAAC,EAAE,CAAC,CAAC;QAAC,KAAK,CAAC,EAAE,CAAC,CAAA;KAAE,CAAC,CAAqB;IAEvE;;;;;;;;OAQG;IACI,YAAY,EAAE,SAAS,CAAC;QAAE,GAAG,CAAC,EAAE,CAAC,CAAC;QAAC,KAAK,CAAC,EAAE,CAAC,CAAA;KAAE,CAAC,CAAqB;IAE3E;;;;;;;;;;;;OAYG;IACI,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAOpC;;;;;;;;;;;OAWG;IACI,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI;CAO9B"}
1
+ {"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../../src/advanced/map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAgB,MAAM,WAAW,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuEG;AACH,qBAAa,OAAO,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACtD;;;;;;;;OAQG;IACI,UAAU;aAAwB,CAAC;eAAS,CAAC;cAAiB;IAErE;;;;;;;;OAQG;IACI,YAAY;aAAwB,CAAC;eAAS,CAAC;cAAiB;IAEvE;;;;;;;;OAQG;IACI,YAAY;aAAwB,CAAC;eAAS,CAAC;cAAiB;IAEvE;;;;;;;;;;;;;OAaG;IACI,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAUlC;;;;;;;;;;;;;OAaG;IACI,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAUrC;;;;;;;;;;;OAWG;IACI,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI;IAS3B;;;;OAIG;IACM,OAAO,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;CAUnD"}
@@ -1,29 +1,68 @@
1
1
  import { FlowObservable } from '../basic';
2
2
  /**
3
- * Represents a reactive resource that asynchronously fetches its value.
3
+ * Represents a reactive resource that asynchronously fetches its value and returns `T | undefined`.
4
4
  *
5
- * @remarks A FlowResource extends FlowObservable and encapsulates an asynchronous fetch function.
6
- * It is used to retrieve and update its value asynchronously. When the fetch is executed,
7
- * if the new value differs from the current value, the resource is updated and its subscribers
8
- * are notified.
5
+ * @remarks
6
+ * FlowResource extends FlowObservable to manage asynchronous data fetching with reactive updates.
7
+ * Unlike {@link FlowResourceAsync} which always returns a Promise, FlowResource returns the resolved
8
+ * value directly (or `undefined` if not yet fetched), making it more convenient for synchronous access
9
+ * patterns in effects and derivations.
10
+ *
11
+ * **Key Characteristics:**
12
+ * - The value is `undefined` initially, before the first fetch
13
+ * - Call `fetch()` to trigger the asynchronous fetch operation
14
+ * - When fetched, the value is compared to the current value; only different values trigger updates
15
+ * - Reading via `get(t)` or `pick()` returns the current value (possibly `undefined`) without triggering a fetch
16
+ *
17
+ * **Fetch Behavior:**
18
+ * The fetch function is NOT called automatically on construction. You must explicitly call the
19
+ * `fetch()` method to retrieve the resource. This gives you control over when network requests
20
+ * or expensive async operations occur.
21
+ *
22
+ * **Use Cases:**
23
+ * - API data fetching where you want synchronous access to the cached value
24
+ * - Lazy-loaded data that shouldn't fetch on construction
25
+ * - Resources that need manual refresh control
26
+ * - Data that may or may not be available (hence `T | undefined`)
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const $user = resource(() => fetchUserFromAPI());
31
+ *
32
+ * // Initially undefined
33
+ * console.log($user.pick()); // undefined
34
+ *
35
+ * // Trigger the fetch
36
+ * await $user.fetch();
37
+ * console.log($user.pick()); // { id: 1, name: 'John' }
38
+ *
39
+ * // Use in an effect
40
+ * effect((t) => {
41
+ * const user = $user.get(t);
42
+ * if (user) {
43
+ * console.log(`Hello, ${user.name}`);
44
+ * }
45
+ * });
46
+ *
47
+ * // Refetch to update
48
+ * await $user.fetch();
49
+ * ```
50
+ *
51
+ * @typeParam T - The type of the resource value (not including the undefined case).
9
52
  *
10
53
  * @public
11
54
  */
12
55
  export declare class FlowResource<T> extends FlowObservable<T | undefined> {
13
56
  /**
14
57
  * Creates a new FlowResource.
58
+ *
15
59
  * @param fetch - An asynchronous function that retrieves the resource's value.
60
+ * This function is not invoked on construction; you must call the `fetch()` method
61
+ * to execute it.
16
62
  *
17
63
  * @public
18
64
  */
19
65
  constructor(fetch: () => Promise<T>);
20
- /**
21
- * Retrieves the current resource value.
22
- * @returns The current value, or undefined if the resource has not been fetched yet.
23
- * @throws Error if the resource is disposed.
24
- * @public
25
- */
26
- get(): T | undefined;
27
66
  /**
28
67
  * Asynchronously fetches a new value for the resource.
29
68
  * @remarks
@@ -1 +1 @@
1
- {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../../src/advanced/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C;;;;;;;;;GASG;AACH,qBAAa,YAAY,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,GAAG,SAAS,CAAC;IAC9D;;;;;OAKG;gBACS,KAAK,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC;IAKnC;;;;;OAKG;IACI,GAAG,IAAI,CAAC,GAAG,SAAS;IAK3B;;;;;;;;OAQG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAUnC,OAAO,CAAC,MAAM,CAAmB;CACpC"}
1
+ {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../../src/advanced/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,qBAAa,YAAY,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,GAAG,SAAS,CAAC;IACjE;;;;;;;;OAQG;gBACS,KAAK,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC;IAcnC;;;;;;;;OAQG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAUnC,OAAO,CAAC,MAAM,CAAmB;CACjC"}
@@ -1,14 +1,36 @@
1
1
  import { FlowObservable } from '../basic/';
2
2
  /**
3
- * Represents a reactive resource that asynchronously fetches its value.
3
+ * Represents a reactive resource that asynchronously fetches its value and always returns a Promise.
4
4
  *
5
5
  * @remarks
6
- * A FlowResource extends FlowObservable and encapsulates an asynchronous fetch function.
7
- * It is used to retrieve and update its value asynchronously. When the fetch is executed,
8
- * if the new value differs from the current value, the resource is updated and its subscribers
9
- * are notified.
6
+ * FlowResourceAsync extends FlowObservable and encapsulates an asynchronous fetch function.
7
+ * Unlike {@link FlowResource} which returns `T | undefined`, FlowResourceAsync always returns
8
+ * a `Promise<T>`, making it suitable for async/await patterns.
10
9
  *
11
- * @typeparam T - The type of the resource value.
10
+ * **Key Characteristics:**
11
+ * - The first call to `get()` or `pick()` creates and caches a Promise
12
+ * - Subsequent calls return the same Promise until `fetch()` is called
13
+ * - Calling `fetch()` creates a new Promise and notifies subscribers
14
+ * - The Promise resolves to the fetched value of type T
15
+ *
16
+ * **Lazy Promise Creation:**
17
+ * The fetch function doesn't execute until the resource's value is first accessed.
18
+ * This allows you to define resources without immediately triggering network requests.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const $user = resourceAsync(() => fetchUserFromAPI());
23
+ *
24
+ * effect(async (t) => {
25
+ * const user = await $user.get(t); // Tracked, effect re-runs on fetch()
26
+ * console.log(user.name);
27
+ * });
28
+ *
29
+ * // Trigger a refetch
30
+ * await $user.fetch();
31
+ * ```
32
+ *
33
+ * @typeParam T - The type of the resource value (not the Promise itself).
12
34
  *
13
35
  * @public
14
36
  */
@@ -19,13 +41,6 @@ export declare class FlowResourceAsync<T> extends FlowObservable<Promise<T>> {
19
41
  * @public
20
42
  */
21
43
  constructor(fetch: () => Promise<T>);
22
- /**
23
- * Retrieves the current resource value.
24
- * @returns The current value, or undefined if the resource has not been fetched yet.
25
- * @throws Error if the resource is disposed.
26
- * @public
27
- */
28
- get(): Promise<T>;
29
44
  /**
30
45
  * Asynchronously fetches a new value for the resource.
31
46
  * @remarks
@@ -1 +1 @@
1
- {"version":3,"file":"resourceAsync.d.ts","sourceRoot":"","sources":["../../../src/advanced/resourceAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C;;;;;;;;;;;;GAYG;AACH,qBAAa,iBAAiB,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAChE;;;;OAIG;gBACS,KAAK,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC;IAKnC;;;;;OAKG;IACI,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC;IAMxB;;;;;;;;OAQG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQnC,OAAO,CAAC,MAAM,CAAmB;CACpC"}
1
+ {"version":3,"file":"resourceAsync.d.ts","sourceRoot":"","sources":["../../../src/advanced/resourceAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,qBAAa,iBAAiB,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACnE;;;;OAIG;gBACS,KAAK,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC;IAenC;;;;;;;;OAQG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQnC,OAAO,CAAC,MAAM,CAAmB;CACjC"}
@@ -1,7 +1,7 @@
1
1
  import { FlowObservable } from '../basic/';
2
2
  /**
3
3
  * A function type that sets a new value for the reactive stream.
4
- * @typeparam T - The type of the value.
4
+ * @typeParam T - The type of the value.
5
5
  * @public
6
6
  */
7
7
  export type FlowStreamSetter<T> = (value: T) => void;
@@ -15,36 +15,94 @@ export type FlowStreamDisposer = () => void;
15
15
  * @remarks
16
16
  * The updater receives a setter function to update the stream's value.
17
17
  * It should return a disposer function to release any resources or subscriptions.
18
- * @typeparam T - The type of the stream value.
18
+ * @typeParam T - The type of the stream value.
19
19
  * @public
20
20
  */
21
21
  export type FlowStreamUpdater<T> = (set: FlowStreamSetter<T>) => FlowStreamDisposer;
22
22
  /**
23
- * Represents a reactive stream that updates its value based on an updater function.
23
+ * Represents a reactive stream that updates its value based on an external updater function.
24
24
  *
25
25
  * @remarks
26
- * FlowStream extends FlowObservable to encapsulate an update mechanism provided by an external updater function.
27
- * The updater is invoked during construction with a setter, and it returns a disposer to be called upon disposal.
28
- * Note: The stream's current value may be undefined until explicitly set.
26
+ * FlowStream extends FlowObservable to bridge external event sources with PicoFlow's reactive
27
+ * system. It's designed for integrating with event emitters, WebSocket connections, timers,
28
+ * or any push-based data source that sends updates over time.
29
29
  *
30
- * @typeparam T - The type of the stream's value.
30
+ * **How It Works:**
31
+ * 1. You provide an updater function that receives a setter callback
32
+ * 2. The updater sets up subscriptions to external events and calls the setter with new values
33
+ * 3. When the setter is called, the stream notifies all dependent effects and derivations
34
+ * 4. The updater returns a disposer function for cleanup
35
+ *
36
+ * **Initial Value:**
37
+ * The stream's value is `undefined` until the first time the setter is called. This allows
38
+ * you to check if any data has been received yet.
39
+ *
40
+ * **Change Detection:**
41
+ * The stream only notifies subscribers when the new value differs from the current value
42
+ * (using strict equality `===`). This prevents unnecessary updates for duplicate values.
43
+ *
44
+ * **Resource Management:**
45
+ * The disposer function returned by your updater is automatically called when the stream
46
+ * is disposed. Use it to clean up subscriptions, close connections, or clear timers.
47
+ *
48
+ * **Use Cases:**
49
+ * - WebSocket message streams
50
+ * - DOM event listeners
51
+ * - setInterval/setTimeout timers
52
+ * - Server-sent events (SSE)
53
+ * - Observable subscriptions from other libraries
54
+ * - Any push-based data source
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * // WebSocket stream
59
+ * const $messages = stream<string>((set) => {
60
+ * const ws = new WebSocket('ws://example.com');
61
+ * ws.onmessage = (event) => set(event.data);
62
+ * return () => ws.close();
63
+ * });
64
+ *
65
+ * // Timer stream
66
+ * const $tick = stream<number>((set) => {
67
+ * let count = 0;
68
+ * const id = setInterval(() => set(count++), 1000);
69
+ * return () => clearInterval(id);
70
+ * });
71
+ *
72
+ * // DOM event stream
73
+ * const $clicks = stream<MouseEvent>((set) => {
74
+ * const handler = (e: MouseEvent) => set(e);
75
+ * document.addEventListener('click', handler);
76
+ * return () => document.removeEventListener('click', handler);
77
+ * });
78
+ *
79
+ * // Use in an effect
80
+ * effect((t) => {
81
+ * const message = $messages.get(t);
82
+ * if (message) {
83
+ * console.log('Received:', message);
84
+ * }
85
+ * });
86
+ * ```
87
+ *
88
+ * @typeParam T - The type of the values emitted by the stream.
31
89
  * @public
32
90
  */
33
91
  export declare class FlowStream<T> extends FlowObservable<T | undefined> {
34
92
  /**
35
93
  * Creates a new FlowStream.
36
- * @param updater - A function that receives a setter to update the stream's value.
37
- * It should return a disposer function that will be called upon disposal.
94
+ *
95
+ * @param updater - A function that receives a setter callback and returns a disposer.
96
+ * The setter should be called whenever new data is available. The disposer will be
97
+ * invoked when the stream is disposed to clean up resources.
98
+ *
99
+ * @remarks
100
+ * The updater is invoked immediately during construction. Make sure to return a proper
101
+ * cleanup function to avoid resource leaks.
102
+ *
38
103
  * @public
39
104
  */
40
105
  constructor(updater: FlowStreamUpdater<T>);
41
- /**
42
- * Retrieves the current value of the stream.
43
- * @returns The current value, or undefined if no value has been set yet.
44
- * @throws Error if the stream is disposed.
45
- * @public
46
- */
47
- get(): T | undefined;
48
106
  /**
49
107
  * Disposes the stream, releasing all resources.
50
108
  * @remarks
@@ -1 +1 @@
1
- {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../src/advanced/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AAErD;;;GAGG;AACH,MAAM,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IAEtC,OAAO,CAAC,IAAI;CAOZ"}
@@ -1,32 +1,86 @@
1
1
  import { FlowObservable } from '../basic';
2
2
  import { FlowStreamUpdater } from './stream';
3
3
  /**
4
- * Represents an asynchronous reactive stream that updates its value based on an updater function.
4
+ * Represents an asynchronous reactive stream that always returns a Promise and updates based on an updater function.
5
5
  *
6
6
  * @remarks
7
- * A FlowStreamAsync extends FlowObservable and encapsulates a mechanism for asynchronously updating its value.
8
- * The updater is invoked during construction with a setter, and its returned disposer is called upon disposal.
9
- * Note: The stream's current value may be undefined until it is set.
7
+ * FlowStreamAsync extends FlowObservable to bridge external async event sources with PicoFlow's
8
+ * reactive system. Unlike {@link FlowStream} which returns `T | undefined`, FlowStreamAsync always
9
+ * returns a `Promise<T>`, making it suitable for use with async/await patterns.
10
10
  *
11
- * @typeparam T - The type of the stream's value.
11
+ * **How It Works:**
12
+ * 1. On construction, creates an initial Promise that resolves when the first value arrives
13
+ * 2. Your updater function receives a setter callback and sets up event subscriptions
14
+ * 3. When the setter is called with a value, the Promise resolves (first call) or a new Promise is created (subsequent calls)
15
+ * 4. The updater returns a disposer function for cleanup
16
+ *
17
+ * **Promise Behavior:**
18
+ * - **First call to setter**: Resolves the initial Promise created at construction
19
+ * - **Subsequent calls**: Creates a new `Promise.resolve(value)` for immediate resolution
20
+ * - **Reading the value**: Always returns a Promise, either pending (initial) or resolved
21
+ *
22
+ * **Change Detection:**
23
+ * After the first value is set, the stream only notifies subscribers when the new value
24
+ * differs from the previous value (using strict equality `===`). This prevents unnecessary
25
+ * updates for duplicate values.
26
+ *
27
+ * **Resource Management:**
28
+ * The disposer function returned by your updater is automatically called when the stream
29
+ * is disposed. Use it to clean up subscriptions, close connections, or clear timers.
30
+ *
31
+ * **Use Cases:**
32
+ * - Async WebSocket message streams
33
+ * - Server-sent events that you want to await
34
+ * - Async event handlers
35
+ * - Integration with async iterators
36
+ * - Any push-based async data source
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * // Async WebSocket stream
41
+ * const $messages = streamAsync<string>((set) => {
42
+ * const ws = new WebSocket('ws://example.com');
43
+ * ws.onmessage = (event) => set(event.data);
44
+ * return () => ws.close();
45
+ * });
46
+ *
47
+ * // Use with async/await
48
+ * effect(async (t) => {
49
+ * const message = await $messages.get(t);
50
+ * console.log('Received:', message);
51
+ * });
52
+ *
53
+ * // Wait for the first message
54
+ * const firstMessage = await $messages.pick();
55
+ * console.log('First message:', firstMessage);
56
+ *
57
+ * // Async timer stream
58
+ * const $asyncTick = streamAsync<number>((set) => {
59
+ * let count = 0;
60
+ * const id = setInterval(() => set(count++), 1000);
61
+ * return () => clearInterval(id);
62
+ * });
63
+ * ```
64
+ *
65
+ * @typeParam T - The type of the values emitted by the stream (not the Promise itself).
12
66
  * @public
13
67
  */
14
68
  export declare class FlowStreamAsync<T> extends FlowObservable<Promise<T>> {
15
69
  /**
16
70
  * Creates a new asynchronous FlowStream.
17
- * @param updater - A function that receives a setter to update the stream's value.
18
- * It should return a disposer function that will be called upon disposal.
19
- * @remarks The updater function can invoke the setter asynchronously to update the stream.
71
+ *
72
+ * @param updater - A function that receives a setter callback and returns a disposer.
73
+ * The setter should be called whenever new data is available (can be called asynchronously).
74
+ * The disposer will be invoked when the stream is disposed to clean up resources.
75
+ *
76
+ * @remarks
77
+ * The updater is invoked immediately during construction. An initial Promise is created
78
+ * that will resolve when the setter is first called. Make sure to return a proper cleanup
79
+ * function to avoid resource leaks.
80
+ *
20
81
  * @public
21
82
  */
22
83
  constructor(updater: FlowStreamUpdater<T>);
23
- /**
24
- * Retrieves the current value of the stream as a Promise.
25
- * @returns A Promise that resolves to the current value.
26
- * @throws Error if the stream is disposed.
27
- * @public
28
- */
29
- get(): Promise<T>;
30
84
  /**
31
85
  * Disposes the stream, releasing all resources.
32
86
  * @remarks In addition to disposing the underlying observable, this method calls the disposer
@@ -1 +1 @@
1
- {"version":3,"file":"streamAsync.d.ts","sourceRoot":"","sources":["../../../src/advanced/streamAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EAAsB,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAEtE;;;;;;;;;;GAUG;AACH,qBAAa,eAAe,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC9D;;;;;;OAMG;gBACS,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAWzC;;;;;OAKG;IACI,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC;IAKxB;;;;;OAKG;IACa,OAAO,IAAI,IAAI;IAO/B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,aAAa,CAAC,CAAI;IAE1B,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,SAAS,CAAqB;IAEtC,OAAO,CAAC,IAAI;CAkBf"}
1
+ {"version":3,"file":"streamAsync.d.ts","sourceRoot":"","sources":["../../../src/advanced/streamAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EAAsB,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEG;AACH,qBAAa,eAAe,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACjE;;;;;;;;;;;;;OAaG;gBACS,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAoBzC;;;;;OAKG;IACa,OAAO,IAAI,IAAI;IAO/B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,aAAa,CAAC,CAAI;IAE1B,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,SAAS,CAAqB;IAEtC,OAAO,CAAC,IAAI;CAkBZ"}