@ersbeth/picoflow 1.0.1 → 1.1.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 (180) hide show
  1. package/.cursor/plans/unifier-flowresource-avec-flowderivation-c9506e24.plan.md +372 -0
  2. package/README.md +17 -1
  3. package/biome.json +4 -1
  4. package/dist/picoflow.js +1129 -661
  5. package/dist/types/flow/base/flowDisposable.d.ts +67 -0
  6. package/dist/types/flow/base/flowDisposable.d.ts.map +1 -0
  7. package/dist/types/flow/base/flowEffect.d.ts +127 -0
  8. package/dist/types/flow/base/flowEffect.d.ts.map +1 -0
  9. package/dist/types/flow/base/flowGraph.d.ts +97 -0
  10. package/dist/types/flow/base/flowGraph.d.ts.map +1 -0
  11. package/dist/types/flow/base/flowSignal.d.ts +134 -0
  12. package/dist/types/flow/base/flowSignal.d.ts.map +1 -0
  13. package/dist/types/flow/base/flowTracker.d.ts +15 -0
  14. package/dist/types/flow/base/flowTracker.d.ts.map +1 -0
  15. package/dist/types/flow/base/index.d.ts +7 -0
  16. package/dist/types/flow/base/index.d.ts.map +1 -0
  17. package/dist/types/flow/base/utils.d.ts +20 -0
  18. package/dist/types/flow/base/utils.d.ts.map +1 -0
  19. package/dist/types/{advanced/array.d.ts → flow/collections/flowArray.d.ts} +50 -12
  20. package/dist/types/flow/collections/flowArray.d.ts.map +1 -0
  21. package/dist/types/flow/collections/flowMap.d.ts +224 -0
  22. package/dist/types/flow/collections/flowMap.d.ts.map +1 -0
  23. package/dist/types/flow/collections/index.d.ts +3 -0
  24. package/dist/types/flow/collections/index.d.ts.map +1 -0
  25. package/dist/types/flow/index.d.ts +4 -0
  26. package/dist/types/flow/index.d.ts.map +1 -0
  27. package/dist/types/flow/nodes/async/flowConstantAsync.d.ts +137 -0
  28. package/dist/types/flow/nodes/async/flowConstantAsync.d.ts.map +1 -0
  29. package/dist/types/flow/nodes/async/flowDerivationAsync.d.ts +137 -0
  30. package/dist/types/flow/nodes/async/flowDerivationAsync.d.ts.map +1 -0
  31. package/dist/types/flow/nodes/async/flowNodeAsync.d.ts +343 -0
  32. package/dist/types/flow/nodes/async/flowNodeAsync.d.ts.map +1 -0
  33. package/dist/types/flow/nodes/async/flowReadonlyAsync.d.ts +81 -0
  34. package/dist/types/flow/nodes/async/flowReadonlyAsync.d.ts.map +1 -0
  35. package/dist/types/flow/nodes/async/flowStateAsync.d.ts +111 -0
  36. package/dist/types/flow/nodes/async/flowStateAsync.d.ts.map +1 -0
  37. package/dist/types/flow/nodes/async/index.d.ts +6 -0
  38. package/dist/types/flow/nodes/async/index.d.ts.map +1 -0
  39. package/dist/types/flow/nodes/index.d.ts +3 -0
  40. package/dist/types/flow/nodes/index.d.ts.map +1 -0
  41. package/dist/types/flow/nodes/sync/flowConstant.d.ts +108 -0
  42. package/dist/types/flow/nodes/sync/flowConstant.d.ts.map +1 -0
  43. package/dist/types/flow/nodes/sync/flowDerivation.d.ts +100 -0
  44. package/dist/types/flow/nodes/sync/flowDerivation.d.ts.map +1 -0
  45. package/dist/types/flow/nodes/sync/flowNode.d.ts +314 -0
  46. package/dist/types/flow/nodes/sync/flowNode.d.ts.map +1 -0
  47. package/dist/types/flow/nodes/sync/flowReadonly.d.ts +57 -0
  48. package/dist/types/flow/nodes/sync/flowReadonly.d.ts.map +1 -0
  49. package/dist/types/flow/nodes/sync/flowState.d.ts +96 -0
  50. package/dist/types/flow/nodes/sync/flowState.d.ts.map +1 -0
  51. package/dist/types/flow/nodes/sync/index.d.ts +6 -0
  52. package/dist/types/flow/nodes/sync/index.d.ts.map +1 -0
  53. package/dist/types/index.d.ts +1 -4
  54. package/dist/types/index.d.ts.map +1 -1
  55. package/dist/types/solid/converters.d.ts +34 -44
  56. package/dist/types/solid/converters.d.ts.map +1 -1
  57. package/dist/types/solid/primitives.d.ts +1 -0
  58. package/dist/types/solid/primitives.d.ts.map +1 -1
  59. package/docs/.vitepress/config.mts +1 -1
  60. package/docs/api/typedoc-sidebar.json +81 -1
  61. package/package.json +60 -58
  62. package/src/flow/base/flowDisposable.ts +71 -0
  63. package/src/flow/base/flowEffect.ts +171 -0
  64. package/src/flow/base/flowGraph.ts +288 -0
  65. package/src/flow/base/flowSignal.ts +207 -0
  66. package/src/flow/base/flowTracker.ts +17 -0
  67. package/src/flow/base/index.ts +6 -0
  68. package/src/flow/base/utils.ts +19 -0
  69. package/src/flow/collections/flowArray.ts +409 -0
  70. package/src/flow/collections/flowMap.ts +398 -0
  71. package/src/flow/collections/index.ts +2 -0
  72. package/src/flow/index.ts +3 -0
  73. package/src/flow/nodes/async/flowConstantAsync.ts +142 -0
  74. package/src/flow/nodes/async/flowDerivationAsync.ts +143 -0
  75. package/src/flow/nodes/async/flowNodeAsync.ts +474 -0
  76. package/src/flow/nodes/async/flowReadonlyAsync.ts +81 -0
  77. package/src/flow/nodes/async/flowStateAsync.ts +116 -0
  78. package/src/flow/nodes/async/index.ts +5 -0
  79. package/src/flow/nodes/await/advanced/index.ts +5 -0
  80. package/src/{advanced → flow/nodes/await/advanced}/resource.ts +37 -3
  81. package/src/{advanced → flow/nodes/await/advanced}/resourceAsync.ts +35 -3
  82. package/src/{advanced → flow/nodes/await/advanced}/stream.ts +40 -2
  83. package/src/{advanced → flow/nodes/await/advanced}/streamAsync.ts +38 -3
  84. package/src/flow/nodes/await/flowConstantAwait.ts +154 -0
  85. package/src/flow/nodes/await/flowDerivationAwait.ts +154 -0
  86. package/src/flow/nodes/await/flowNodeAwait.ts +508 -0
  87. package/src/flow/nodes/await/flowReadonlyAwait.ts +89 -0
  88. package/src/flow/nodes/await/flowStateAwait.ts +130 -0
  89. package/src/flow/nodes/await/index.ts +5 -0
  90. package/src/flow/nodes/index.ts +3 -0
  91. package/src/flow/nodes/sync/flowConstant.ts +111 -0
  92. package/src/flow/nodes/sync/flowDerivation.ts +105 -0
  93. package/src/flow/nodes/sync/flowNode.ts +439 -0
  94. package/src/flow/nodes/sync/flowReadonly.ts +57 -0
  95. package/src/flow/nodes/sync/flowState.ts +101 -0
  96. package/src/flow/nodes/sync/index.ts +5 -0
  97. package/src/index.ts +1 -47
  98. package/src/solid/converters.ts +59 -198
  99. package/src/solid/primitives.ts +4 -0
  100. package/test/base/flowEffect.test.ts +108 -0
  101. package/test/base/flowGraph.test.ts +485 -0
  102. package/test/base/flowSignal.test.ts +372 -0
  103. package/test/collections/flowArray.asyncStates.test.ts +1553 -0
  104. package/test/collections/flowArray.scalars.test.ts +1129 -0
  105. package/test/collections/flowArray.states.test.ts +1365 -0
  106. package/test/collections/flowMap.asyncStates.test.ts +1105 -0
  107. package/test/collections/flowMap.scalars.test.ts +877 -0
  108. package/test/collections/flowMap.states.test.ts +1097 -0
  109. package/test/nodes/async/flowConstantAsync.test.ts +860 -0
  110. package/test/nodes/async/flowDerivationAsync.test.ts +1517 -0
  111. package/test/nodes/async/flowStateAsync.test.ts +1387 -0
  112. package/test/{resource.test.ts → nodes/await/advanced/resource.test.ts} +21 -19
  113. package/test/{resourceAsync.test.ts → nodes/await/advanced/resourceAsync.test.ts} +3 -1
  114. package/test/{stream.test.ts → nodes/await/advanced/stream.test.ts} +30 -28
  115. package/test/{streamAsync.test.ts → nodes/await/advanced/streamAsync.test.ts} +16 -14
  116. package/test/nodes/await/flowConstantAwait.test.ts +643 -0
  117. package/test/nodes/await/flowDerivationAwait.test.ts +1583 -0
  118. package/test/nodes/await/flowStateAwait.test.ts +999 -0
  119. package/test/nodes/mixed/derivation.test.ts +1527 -0
  120. package/test/nodes/sync/flowConstant.test.ts +620 -0
  121. package/test/nodes/sync/flowDerivation.test.ts +1373 -0
  122. package/test/nodes/sync/flowState.test.ts +945 -0
  123. package/test/solid/converters.test.ts +721 -0
  124. package/test/solid/primitives.test.ts +1031 -0
  125. package/tsconfig.json +2 -1
  126. package/vitest.config.ts +7 -1
  127. package/IMPLEMENTATION_GUIDE.md +0 -1578
  128. package/dist/types/advanced/array.d.ts.map +0 -1
  129. package/dist/types/advanced/index.d.ts +0 -9
  130. package/dist/types/advanced/index.d.ts.map +0 -1
  131. package/dist/types/advanced/map.d.ts +0 -166
  132. package/dist/types/advanced/map.d.ts.map +0 -1
  133. package/dist/types/advanced/resource.d.ts +0 -78
  134. package/dist/types/advanced/resource.d.ts.map +0 -1
  135. package/dist/types/advanced/resourceAsync.d.ts +0 -56
  136. package/dist/types/advanced/resourceAsync.d.ts.map +0 -1
  137. package/dist/types/advanced/stream.d.ts +0 -117
  138. package/dist/types/advanced/stream.d.ts.map +0 -1
  139. package/dist/types/advanced/streamAsync.d.ts +0 -97
  140. package/dist/types/advanced/streamAsync.d.ts.map +0 -1
  141. package/dist/types/basic/constant.d.ts +0 -60
  142. package/dist/types/basic/constant.d.ts.map +0 -1
  143. package/dist/types/basic/derivation.d.ts +0 -89
  144. package/dist/types/basic/derivation.d.ts.map +0 -1
  145. package/dist/types/basic/disposable.d.ts +0 -82
  146. package/dist/types/basic/disposable.d.ts.map +0 -1
  147. package/dist/types/basic/effect.d.ts +0 -67
  148. package/dist/types/basic/effect.d.ts.map +0 -1
  149. package/dist/types/basic/index.d.ts +0 -10
  150. package/dist/types/basic/index.d.ts.map +0 -1
  151. package/dist/types/basic/observable.d.ts +0 -83
  152. package/dist/types/basic/observable.d.ts.map +0 -1
  153. package/dist/types/basic/signal.d.ts +0 -69
  154. package/dist/types/basic/signal.d.ts.map +0 -1
  155. package/dist/types/basic/state.d.ts +0 -47
  156. package/dist/types/basic/state.d.ts.map +0 -1
  157. package/dist/types/basic/trackingContext.d.ts +0 -33
  158. package/dist/types/basic/trackingContext.d.ts.map +0 -1
  159. package/dist/types/creators.d.ts +0 -340
  160. package/dist/types/creators.d.ts.map +0 -1
  161. package/src/advanced/array.ts +0 -222
  162. package/src/advanced/index.ts +0 -12
  163. package/src/advanced/map.ts +0 -193
  164. package/src/basic/constant.ts +0 -97
  165. package/src/basic/derivation.ts +0 -147
  166. package/src/basic/disposable.ts +0 -86
  167. package/src/basic/effect.ts +0 -104
  168. package/src/basic/index.ts +0 -9
  169. package/src/basic/observable.ts +0 -109
  170. package/src/basic/signal.ts +0 -145
  171. package/src/basic/state.ts +0 -60
  172. package/src/basic/trackingContext.ts +0 -45
  173. package/src/creators.ts +0 -395
  174. package/test/array.test.ts +0 -600
  175. package/test/constant.test.ts +0 -44
  176. package/test/derivation.test.ts +0 -539
  177. package/test/effect.test.ts +0 -29
  178. package/test/map.test.ts +0 -240
  179. package/test/signal.test.ts +0 -72
  180. package/test/state.test.ts +0 -212
@@ -1 +0,0 @@
1
- {"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../../src/advanced/array.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,SAAS,EAAgB,MAAM,UAAU,CAAC;AAGxE;;;GAGG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IAC1B;IACA,IAAI,EAAE,KAAK,CAAC;IACZ,KAAK,EAAE,CAAC,EAAE,CAAC;CACV,GACD;IACA,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,CAAC,CAAC;CACP,GACD;IACA,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,CAAC,CAAC;CACP,GACD;IACA,IAAI,EAAE,KAAK,CAAC;CACX,GACD;IACA,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,CAAC,CAAC;CACP,GACD;IACA,IAAI,EAAE,OAAO,CAAC;CACb,GACD;IACA,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,CAAC,EAAE,CAAC;CACV,GACD;IACA,IAAI,EAAE,OAAO,CAAC;CACb,CAAC;AAEL;;;GAGG;AACH,qBAAa,SAAS,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,EAAE,CAAC;IACpD;;;OAGG;IACH,WAAW,EAAE,SAAS,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;IAE3C;;;;OAIG;gBACS,KAAK,GAAE,CAAC,EAAO;IAS3B;;;;OAIG;IACH,IAAI,MAAM,IAAI,MAAM,CAGnB;IAWD;;;;OAIG;IACH,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI;IAUrB;;;;;OAKG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,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 +0,0 @@
1
- export type { FlowArrayAction } from './array';
2
- export { FlowArray } from './array';
3
- export { FlowMap } from './map';
4
- export { FlowResource } from './resource';
5
- export { FlowResourceAsync } from './resourceAsync';
6
- export type { FlowStreamDisposer, FlowStreamSetter, FlowStreamUpdater, } from './stream';
7
- export { FlowStream } from './stream';
8
- export { FlowStreamAsync } from './streamAsync';
9
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
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,166 +0,0 @@
1
- import { FlowState } from '../basic/';
2
- /**
3
- * Represents a reactive map that extends {@link FlowState} for tracking key-value pairs.
4
- *
5
- * @remarks
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:
8
- *
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
13
- *
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
18
- *
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.
71
- *
72
- * @public
73
- */
74
- export declare class FlowMap<K, V> extends FlowState<Map<K, V>> {
75
- /**
76
- * A reactive state that holds the most recent key and value that were added.
77
- *
78
- * @remarks
79
- * When a key is added via {@link FlowMap.add}, this state is updated with
80
- * the corresponding key and value.
81
- *
82
- * @public
83
- */
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>;
101
- /**
102
- * A reactive state that holds the most recent key and value that were deleted.
103
- *
104
- * @remarks
105
- * When a key is deleted via {@link FlowMap.delete}, this state is updated with
106
- * the corresponding key and its last known value.
107
- *
108
- * @public
109
- */
110
- $lastDeleted: FlowState<{
111
- key: K;
112
- value: V;
113
- } | null>;
114
- /**
115
- * Adds a new key-value pair to the map.
116
- *
117
- * @param key - The key to add.
118
- * @param value - The value to associate with the key.
119
- * @throws If the FlowMap instance is disposed.
120
- * @throws If the key already exists in the map.
121
- *
122
- * @remarks
123
- * Adds a new entry to the internal map, emits the key-value pair via {@link FlowMap.$lastAdded},
124
- * and notifies all subscribers of the change.
125
- *
126
- * @public
127
- */
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;
144
- /**
145
- * Deletes the value at the specified key from the underlying map.
146
- *
147
- * @param key - The key to delete.
148
- * @throws If the FlowMap instance is disposed.
149
- *
150
- * @remarks
151
- * Removes the key from the internal map, emits the deleted key and its value via {@link FlowMap.$lastDeleted},
152
- * and notifies all subscribers of the change.
153
- *
154
- * @public
155
- */
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;
165
- }
166
- //# sourceMappingURL=map.d.ts.map
@@ -1 +0,0 @@
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,78 +0,0 @@
1
- import { FlowObservable } from '../basic';
2
- /**
3
- * Represents a reactive resource that asynchronously fetches its value and returns `T | undefined`.
4
- *
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).
52
- *
53
- * @public
54
- */
55
- export declare class FlowResource<T> extends FlowObservable<T | undefined> {
56
- /**
57
- * Creates a new FlowResource.
58
- *
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.
62
- *
63
- * @public
64
- */
65
- constructor(fetch: () => Promise<T>);
66
- /**
67
- * Asynchronously fetches a new value for the resource.
68
- * @remarks
69
- * Executes the internal fetch function. If the fetched value differs from the current one,
70
- * updates the resource's value and notifies subscribers.
71
- * @returns A Promise that resolves when the fetch operation is complete.
72
- * @throws Error if the resource is disposed.
73
- * @public
74
- */
75
- fetch(): Promise<void>;
76
- private _fetch;
77
- }
78
- //# sourceMappingURL=resource.d.ts.map
@@ -1 +0,0 @@
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,56 +0,0 @@
1
- import { FlowObservable } from '../basic/';
2
- /**
3
- * Represents a reactive resource that asynchronously fetches its value and always returns a Promise.
4
- *
5
- * @remarks
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.
9
- *
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).
34
- *
35
- * @public
36
- */
37
- export declare class FlowResourceAsync<T> extends FlowObservable<Promise<T>> {
38
- /**
39
- * Creates a new FlowResource.
40
- * @param fetch - An asynchronous function that retrieves the resource's value.
41
- * @public
42
- */
43
- constructor(fetch: () => Promise<T>);
44
- /**
45
- * Asynchronously fetches a new value for the resource.
46
- * @remarks
47
- * Executes the internal fetch function. If the fetched value differs from the current one,
48
- * updates the resource's value and notifies subscribers.
49
- * @returns A Promise that resolves when the fetch operation is complete.
50
- * @throws Error if the resource is disposed.
51
- * @public
52
- */
53
- fetch(): Promise<void>;
54
- private _fetch;
55
- }
56
- //# sourceMappingURL=resourceAsync.d.ts.map
@@ -1 +0,0 @@
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,117 +0,0 @@
1
- import { FlowObservable } from '../basic/';
2
- /**
3
- * A function type that sets a new value for the reactive stream.
4
- * @typeParam T - The type of the value.
5
- * @public
6
- */
7
- export type FlowStreamSetter<T> = (value: T) => void;
8
- /**
9
- * A function type that disposes of a resource.
10
- * @public
11
- */
12
- export type FlowStreamDisposer = () => void;
13
- /**
14
- * A function type that updates a stream and returns a disposer for cleanup.
15
- * @remarks
16
- * The updater receives a setter function to update the stream's value.
17
- * It should return a disposer function to release any resources or subscriptions.
18
- * @typeParam T - The type of the stream value.
19
- * @public
20
- */
21
- export type FlowStreamUpdater<T> = (set: FlowStreamSetter<T>) => FlowStreamDisposer;
22
- /**
23
- * Represents a reactive stream that updates its value based on an external updater function.
24
- *
25
- * @remarks
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
- *
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.
89
- * @public
90
- */
91
- export declare class FlowStream<T> extends FlowObservable<T | undefined> {
92
- /**
93
- * Creates a new FlowStream.
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
- *
103
- * @public
104
- */
105
- constructor(updater: FlowStreamUpdater<T>);
106
- /**
107
- * Disposes the stream, releasing all resources.
108
- * @remarks
109
- * In addition to disposing the underlying observable, this method calls the disposer
110
- * returned by the updater.
111
- * @public
112
- */
113
- dispose(): void;
114
- private _disposer;
115
- private _set;
116
- }
117
- //# sourceMappingURL=stream.d.ts.map
@@ -1 +0,0 @@
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,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC;AAE5C;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,CAClC,GAAG,EAAE,gBAAgB,CAAC,CAAC,CAAC,KACpB,kBAAkB,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,qBAAa,UAAU,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,GAAG,SAAS,CAAC;IAC/D;;;;;;;;;;;;OAYG;gBACS,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAgBzC;;;;;;OAMG;IACa,OAAO,IAAI,IAAI;IAO/B,OAAO,CAAC,SAAS,CAAqB;IAEtC,OAAO,CAAC,IAAI;CAOZ"}
@@ -1,97 +0,0 @@
1
- import { FlowObservable } from '../basic';
2
- import { FlowStreamUpdater } from './stream';
3
- /**
4
- * Represents an asynchronous reactive stream that always returns a Promise and updates based on an updater function.
5
- *
6
- * @remarks
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
- *
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).
66
- * @public
67
- */
68
- export declare class FlowStreamAsync<T> extends FlowObservable<Promise<T>> {
69
- /**
70
- * Creates a new asynchronous FlowStream.
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
- *
81
- * @public
82
- */
83
- constructor(updater: FlowStreamUpdater<T>);
84
- /**
85
- * Disposes the stream, releasing all resources.
86
- * @remarks In addition to disposing the underlying observable, this method calls the disposer
87
- * returned by the updater.
88
- * @public
89
- */
90
- dispose(): void;
91
- private _initialized;
92
- private _awaitedValue?;
93
- private _resolve;
94
- private _disposer;
95
- private _set;
96
- }
97
- //# sourceMappingURL=streamAsync.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,60 +0,0 @@
1
- import { FlowObservable } from './observable';
2
- /**
3
- * Represents a reactive and immutable constant value that can be computed lazily upon first access.
4
- *
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.
8
- *
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.
45
- *
46
- * @public
47
- */
48
- export declare class FlowConstant<T> extends FlowObservable<T> {
49
- /**
50
- * Creates a new FlowConstant instance.
51
- *
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.
55
- *
56
- * @public
57
- */
58
- constructor(value: T | (() => T));
59
- }
60
- //# sourceMappingURL=constant.d.ts.map
@@ -1 +0,0 @@
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"}