@ersbeth/picoflow 1.1.1 → 2.0.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 (383) hide show
  1. package/.vscode/settings.json +3 -3
  2. package/CHANGELOG.md +43 -0
  3. package/README.md +2 -18
  4. package/biome.json +45 -35
  5. package/dist/picoflow.js +857 -1528
  6. package/dist/types/api/base/flowDisposable.d.ts +41 -0
  7. package/dist/types/api/base/flowDisposable.d.ts.map +1 -0
  8. package/dist/types/api/base/flowObservable.d.ts +27 -0
  9. package/dist/types/api/base/flowObservable.d.ts.map +1 -0
  10. package/dist/types/api/base/flowSubscribable.d.ts +79 -0
  11. package/dist/types/api/base/flowSubscribable.d.ts.map +1 -0
  12. package/dist/types/api/base/flowTracker.d.ts +8 -0
  13. package/dist/types/api/base/flowTracker.d.ts.map +1 -0
  14. package/dist/types/api/base/index.d.ts +5 -0
  15. package/dist/types/api/base/index.d.ts.map +1 -0
  16. package/dist/types/api/index.d.ts +3 -0
  17. package/dist/types/api/index.d.ts.map +1 -0
  18. package/dist/types/api/nodes/async/flowConstantAsync.d.ts +31 -0
  19. package/dist/types/api/nodes/async/flowConstantAsync.d.ts.map +1 -0
  20. package/dist/types/api/nodes/async/flowDerivationAsync.d.ts +37 -0
  21. package/dist/types/api/nodes/async/flowDerivationAsync.d.ts.map +1 -0
  22. package/dist/types/api/nodes/async/flowStateAsync.d.ts +41 -0
  23. package/dist/types/api/nodes/async/flowStateAsync.d.ts.map +1 -0
  24. package/dist/types/api/nodes/async/flowWritableDerivationAsync.d.ts +30 -0
  25. package/dist/types/api/nodes/async/flowWritableDerivationAsync.d.ts.map +1 -0
  26. package/dist/types/{flow → api}/nodes/async/index.d.ts +1 -2
  27. package/dist/types/api/nodes/async/index.d.ts.map +1 -0
  28. package/dist/types/api/nodes/collections/flowArray.d.ts +134 -0
  29. package/dist/types/api/nodes/collections/flowArray.d.ts.map +1 -0
  30. package/dist/types/api/nodes/collections/flowMap.d.ts +98 -0
  31. package/dist/types/api/nodes/collections/flowMap.d.ts.map +1 -0
  32. package/dist/types/api/nodes/collections/index.d.ts.map +1 -0
  33. package/dist/types/api/nodes/flowEffect.d.ts +28 -0
  34. package/dist/types/api/nodes/flowEffect.d.ts.map +1 -0
  35. package/dist/types/api/nodes/flowSignal.d.ts +25 -0
  36. package/dist/types/api/nodes/flowSignal.d.ts.map +1 -0
  37. package/dist/types/api/nodes/flowValue.d.ts +35 -0
  38. package/dist/types/api/nodes/flowValue.d.ts.map +1 -0
  39. package/dist/types/api/nodes/index.d.ts +8 -0
  40. package/dist/types/api/nodes/index.d.ts.map +1 -0
  41. package/dist/types/api/nodes/sync/flowConstant.d.ts +29 -0
  42. package/dist/types/api/nodes/sync/flowConstant.d.ts.map +1 -0
  43. package/dist/types/api/nodes/sync/flowDerivation.d.ts +36 -0
  44. package/dist/types/api/nodes/sync/flowDerivation.d.ts.map +1 -0
  45. package/dist/types/api/nodes/sync/flowState.d.ts +39 -0
  46. package/dist/types/api/nodes/sync/flowState.d.ts.map +1 -0
  47. package/dist/types/api/nodes/sync/flowWritableDerivation.d.ts +28 -0
  48. package/dist/types/api/nodes/sync/flowWritableDerivation.d.ts.map +1 -0
  49. package/dist/types/{flow → api}/nodes/sync/index.d.ts +1 -2
  50. package/dist/types/api/nodes/sync/index.d.ts.map +1 -0
  51. package/dist/types/api/nodes/utils.d.ts +22 -0
  52. package/dist/types/api/nodes/utils.d.ts.map +1 -0
  53. package/dist/types/base/disposable.d.ts +11 -0
  54. package/dist/types/base/disposable.d.ts.map +1 -0
  55. package/dist/types/base/executionStack.d.ts +14 -0
  56. package/dist/types/base/executionStack.d.ts.map +1 -0
  57. package/dist/types/base/index.d.ts +6 -0
  58. package/dist/types/base/index.d.ts.map +1 -0
  59. package/dist/types/base/node.d.ts +27 -0
  60. package/dist/types/base/node.d.ts.map +1 -0
  61. package/dist/types/base/observable.d.ts +37 -0
  62. package/dist/types/base/observable.d.ts.map +1 -0
  63. package/dist/types/base/observer.d.ts +25 -0
  64. package/dist/types/base/observer.d.ts.map +1 -0
  65. package/dist/types/converters/index.d.ts +2 -0
  66. package/dist/types/converters/index.d.ts.map +1 -0
  67. package/dist/types/converters/solid.d.ts +46 -0
  68. package/dist/types/converters/solid.d.ts.map +1 -0
  69. package/dist/types/index.d.ts +2 -63
  70. package/dist/types/index.d.ts.map +1 -1
  71. package/dist/types/nodes/arrayNode.d.ts +2 -0
  72. package/dist/types/nodes/arrayNode.d.ts.map +1 -0
  73. package/dist/types/nodes/effectNode.d.ts +2 -0
  74. package/dist/types/nodes/effectNode.d.ts.map +1 -0
  75. package/dist/types/nodes/index.d.ts +9 -0
  76. package/dist/types/nodes/index.d.ts.map +1 -0
  77. package/dist/types/nodes/mapNode.d.ts +2 -0
  78. package/dist/types/nodes/mapNode.d.ts.map +1 -0
  79. package/dist/types/nodes/signalNode.d.ts +2 -0
  80. package/dist/types/nodes/signalNode.d.ts.map +1 -0
  81. package/dist/types/nodes/valueAsyncNode.d.ts +2 -0
  82. package/dist/types/nodes/valueAsyncNode.d.ts.map +1 -0
  83. package/dist/types/nodes/valueNode.d.ts +2 -0
  84. package/dist/types/nodes/valueNode.d.ts.map +1 -0
  85. package/dist/types/nodes/valueSyncNode.d.ts +2 -0
  86. package/dist/types/nodes/valueSyncNode.d.ts.map +1 -0
  87. package/dist/types/schedulers/asyncResolver.d.ts +2 -0
  88. package/dist/types/schedulers/asyncResolver.d.ts.map +1 -0
  89. package/dist/types/schedulers/asyncScheduler.d.ts +2 -0
  90. package/dist/types/schedulers/asyncScheduler.d.ts.map +1 -0
  91. package/dist/types/schedulers/index.d.ts +5 -0
  92. package/dist/types/schedulers/index.d.ts.map +1 -0
  93. package/dist/types/schedulers/pendingError.d.ts +2 -0
  94. package/dist/types/schedulers/pendingError.d.ts.map +1 -0
  95. package/dist/types/schedulers/scheduler.d.ts +2 -0
  96. package/dist/types/schedulers/scheduler.d.ts.map +1 -0
  97. package/dist/types/schedulers/syncResolver.d.ts +2 -0
  98. package/dist/types/schedulers/syncResolver.d.ts.map +1 -0
  99. package/dist/types/schedulers/syncScheduler.d.ts +2 -0
  100. package/dist/types/schedulers/syncScheduler.d.ts.map +1 -0
  101. package/docs/.vitepress/config.mts +128 -93
  102. package/docs/api/functions/array.md +14 -37
  103. package/docs/api/functions/constant.md +13 -25
  104. package/docs/api/functions/constantAsync.md +69 -0
  105. package/docs/api/functions/derivation.md +14 -33
  106. package/docs/api/functions/derivationAsync.md +34 -0
  107. package/docs/api/functions/from.md +62 -153
  108. package/docs/api/functions/isDisposable.md +8 -30
  109. package/docs/api/functions/map.md +15 -36
  110. package/docs/api/functions/signal.md +8 -23
  111. package/docs/api/functions/state.md +43 -23
  112. package/docs/api/functions/stateAsync.md +69 -0
  113. package/docs/api/functions/subscribe.md +40 -0
  114. package/docs/api/functions/writableDerivation.md +33 -0
  115. package/docs/api/functions/writableDerivationAsync.md +34 -0
  116. package/docs/api/index.md +45 -102
  117. package/docs/api/interfaces/FlowArray.md +439 -0
  118. package/docs/api/interfaces/FlowConstant.md +220 -0
  119. package/docs/api/interfaces/FlowConstantAsync.md +221 -0
  120. package/docs/api/interfaces/FlowDerivation.md +241 -0
  121. package/docs/api/interfaces/FlowDerivationAsync.md +242 -0
  122. package/docs/api/interfaces/FlowDisposable.md +32 -38
  123. package/docs/api/interfaces/FlowEffect.md +64 -0
  124. package/docs/api/interfaces/FlowMap.md +374 -0
  125. package/docs/api/interfaces/FlowObservable.md +155 -0
  126. package/docs/api/interfaces/FlowSignal.md +156 -0
  127. package/docs/api/interfaces/FlowState.md +269 -0
  128. package/docs/api/interfaces/FlowStateAsync.md +268 -0
  129. package/docs/api/interfaces/FlowSubscribable.md +55 -0
  130. package/docs/api/interfaces/FlowTracker.md +61 -0
  131. package/docs/api/interfaces/FlowValue.md +222 -0
  132. package/docs/api/interfaces/FlowWritableDerivation.md +292 -0
  133. package/docs/api/interfaces/FlowWritableDerivationAsync.md +293 -0
  134. package/docs/api/type-aliases/DerivationFunction.md +28 -0
  135. package/docs/api/type-aliases/DerivationFunctionAsync.md +28 -0
  136. package/docs/api/type-aliases/FlowArrayAction.md +19 -8
  137. package/docs/api/type-aliases/FlowDataTracker.md +33 -0
  138. package/docs/api/type-aliases/FlowMapAction.md +48 -0
  139. package/docs/api/type-aliases/FlowOnDataListener.md +33 -0
  140. package/docs/api/type-aliases/FlowOnErrorListener.md +27 -0
  141. package/docs/api/type-aliases/FlowOnPendingListener.md +21 -0
  142. package/docs/api/type-aliases/FlowReadonly.md +22 -0
  143. package/docs/api/type-aliases/InitFunction.md +21 -0
  144. package/docs/api/type-aliases/InitFunctionAsync.md +21 -0
  145. package/docs/api/type-aliases/NotPromise.md +6 -3
  146. package/docs/api/type-aliases/UpdateFunction.md +27 -0
  147. package/docs/api/type-aliases/UpdateFunctionAsync.md +27 -0
  148. package/docs/api/typedoc-sidebar.json +1 -81
  149. package/docs/examples/examples.md +0 -2
  150. package/docs/guide/advanced/architecture.md +1234 -0
  151. package/docs/guide/advanced/migration-v2.md +204 -0
  152. package/docs/guide/advanced/solidjs.md +2 -88
  153. package/docs/guide/introduction/concepts.md +4 -3
  154. package/docs/guide/introduction/conventions.md +2 -33
  155. package/docs/guide/introduction/getting-started.md +28 -23
  156. package/docs/guide/introduction/lifecycle.md +16 -19
  157. package/docs/guide/primitives/array.md +102 -216
  158. package/docs/guide/primitives/constant.md +39 -212
  159. package/docs/guide/primitives/derivations.md +55 -122
  160. package/docs/guide/primitives/effects.md +155 -241
  161. package/docs/guide/primitives/map.md +64 -186
  162. package/docs/guide/primitives/overview.md +45 -128
  163. package/docs/guide/primitives/signal.md +51 -88
  164. package/docs/guide/primitives/state.md +34 -130
  165. package/package.json +56 -60
  166. package/src/api/base/flowDisposable.ts +44 -0
  167. package/src/api/base/flowObservable.ts +28 -0
  168. package/src/api/base/flowSubscribable.ts +87 -0
  169. package/src/api/base/flowTracker.ts +7 -0
  170. package/src/api/base/index.ts +4 -0
  171. package/src/{flow → api}/index.ts +0 -1
  172. package/src/api/nodes/async/flowConstantAsync.ts +36 -0
  173. package/src/api/nodes/async/flowDerivationAsync.ts +42 -0
  174. package/src/api/nodes/async/flowStateAsync.ts +47 -0
  175. package/src/api/nodes/async/flowWritableDerivationAsync.ts +33 -0
  176. package/src/{flow → api}/nodes/async/index.ts +1 -2
  177. package/src/api/nodes/collections/flowArray.ts +155 -0
  178. package/src/api/nodes/collections/flowMap.ts +115 -0
  179. package/src/api/nodes/flowEffect.ts +42 -0
  180. package/src/api/nodes/flowSignal.ts +28 -0
  181. package/src/api/nodes/flowValue.ts +36 -0
  182. package/src/api/nodes/index.ts +7 -0
  183. package/src/api/nodes/sync/flowConstant.ts +33 -0
  184. package/src/api/nodes/sync/flowDerivation.ts +41 -0
  185. package/src/api/nodes/sync/flowState.ts +45 -0
  186. package/src/api/nodes/sync/flowWritableDerivation.ts +31 -0
  187. package/src/{flow → api}/nodes/sync/index.ts +1 -2
  188. package/src/api/nodes/utils.ts +22 -0
  189. package/src/base/disposable.ts +18 -0
  190. package/src/base/executionStack.ts +42 -0
  191. package/src/base/index.ts +5 -0
  192. package/src/base/node.ts +98 -0
  193. package/src/base/observable.ts +87 -0
  194. package/src/base/observer.ts +51 -0
  195. package/src/converters/index.ts +1 -0
  196. package/src/converters/solid.ts +109 -0
  197. package/src/index.ts +2 -64
  198. package/src/nodes/arrayNode.ts +172 -0
  199. package/src/nodes/effectNode.ts +59 -0
  200. package/src/nodes/index.ts +8 -0
  201. package/src/nodes/mapNode.ts +127 -0
  202. package/src/nodes/signalNode.ts +21 -0
  203. package/src/nodes/valueAsyncNode.ts +88 -0
  204. package/src/nodes/valueNode.ts +144 -0
  205. package/src/nodes/valueSyncNode.ts +128 -0
  206. package/src/schedulers/asyncResolver.ts +78 -0
  207. package/src/schedulers/asyncScheduler.ts +66 -0
  208. package/src/schedulers/index.ts +4 -0
  209. package/src/schedulers/pendingError.ts +13 -0
  210. package/src/schedulers/scheduler.ts +9 -0
  211. package/src/schedulers/syncResolver.ts +69 -0
  212. package/src/schedulers/syncScheduler.ts +55 -0
  213. package/test/base/pendingError.test.ts +67 -0
  214. package/test/converters/solid.derivation.browser.test.tsx +69 -0
  215. package/test/converters/solid.node.test.ts +654 -0
  216. package/test/converters/solid.state.browser.test.tsx +1592 -0
  217. package/test/reactivity/flowSignal.test.ts +226 -0
  218. package/test/reactivity/nodes/async/asyncScheduler/asyncResolver.test.ts +593 -0
  219. package/test/reactivity/nodes/async/asyncScheduler/asyncScheduler.test.ts +317 -0
  220. package/test/reactivity/nodes/async/flowConstantAsync.test.ts +652 -0
  221. package/test/reactivity/nodes/async/flowDerivation.test.ts +898 -0
  222. package/test/reactivity/nodes/async/flowDerivationAsync.test.ts +1716 -0
  223. package/test/reactivity/nodes/async/flowStateAsync.test.ts +708 -0
  224. package/test/reactivity/nodes/async/flowWritableDerivationAsync.test.ts +614 -0
  225. package/test/reactivity/nodes/collections/flowArray.asyncStates.test.ts +1289 -0
  226. package/test/reactivity/nodes/collections/flowArray.scalars.test.ts +961 -0
  227. package/test/reactivity/nodes/collections/flowArray.states.test.ts +1035 -0
  228. package/test/reactivity/nodes/collections/flowMap.asyncStates.test.ts +960 -0
  229. package/test/reactivity/nodes/collections/flowMap.scalars.test.ts +775 -0
  230. package/test/reactivity/nodes/collections/flowMap.states.test.ts +958 -0
  231. package/test/reactivity/nodes/sync/flowConstant.test.ts +377 -0
  232. package/test/reactivity/nodes/sync/flowDerivation.test.ts +896 -0
  233. package/test/reactivity/nodes/sync/flowState.test.ts +341 -0
  234. package/test/reactivity/nodes/sync/flowWritableDerivation.test.ts +603 -0
  235. package/test/vitest.d.ts +10 -0
  236. package/tsconfig.json +31 -20
  237. package/typedoc.json +35 -35
  238. package/vite.config.ts +25 -23
  239. package/vitest.browser.config.ts +21 -0
  240. package/vitest.config.ts +12 -12
  241. package/.cursor/plans/unifier-flowresource-avec-flowderivation-c9506e24.plan.md +0 -372
  242. package/.cursor/plans/update-js-e795d61b.plan.md +0 -567
  243. package/dist/types/flow/base/flowDisposable.d.ts +0 -67
  244. package/dist/types/flow/base/flowDisposable.d.ts.map +0 -1
  245. package/dist/types/flow/base/flowEffect.d.ts +0 -127
  246. package/dist/types/flow/base/flowEffect.d.ts.map +0 -1
  247. package/dist/types/flow/base/flowGraph.d.ts +0 -97
  248. package/dist/types/flow/base/flowGraph.d.ts.map +0 -1
  249. package/dist/types/flow/base/flowSignal.d.ts +0 -134
  250. package/dist/types/flow/base/flowSignal.d.ts.map +0 -1
  251. package/dist/types/flow/base/flowTracker.d.ts +0 -15
  252. package/dist/types/flow/base/flowTracker.d.ts.map +0 -1
  253. package/dist/types/flow/base/index.d.ts +0 -7
  254. package/dist/types/flow/base/index.d.ts.map +0 -1
  255. package/dist/types/flow/base/utils.d.ts +0 -20
  256. package/dist/types/flow/base/utils.d.ts.map +0 -1
  257. package/dist/types/flow/collections/flowArray.d.ts +0 -148
  258. package/dist/types/flow/collections/flowArray.d.ts.map +0 -1
  259. package/dist/types/flow/collections/flowMap.d.ts +0 -224
  260. package/dist/types/flow/collections/flowMap.d.ts.map +0 -1
  261. package/dist/types/flow/collections/index.d.ts.map +0 -1
  262. package/dist/types/flow/index.d.ts +0 -4
  263. package/dist/types/flow/index.d.ts.map +0 -1
  264. package/dist/types/flow/nodes/async/flowConstantAsync.d.ts +0 -137
  265. package/dist/types/flow/nodes/async/flowConstantAsync.d.ts.map +0 -1
  266. package/dist/types/flow/nodes/async/flowDerivationAsync.d.ts +0 -137
  267. package/dist/types/flow/nodes/async/flowDerivationAsync.d.ts.map +0 -1
  268. package/dist/types/flow/nodes/async/flowNodeAsync.d.ts +0 -343
  269. package/dist/types/flow/nodes/async/flowNodeAsync.d.ts.map +0 -1
  270. package/dist/types/flow/nodes/async/flowReadonlyAsync.d.ts +0 -81
  271. package/dist/types/flow/nodes/async/flowReadonlyAsync.d.ts.map +0 -1
  272. package/dist/types/flow/nodes/async/flowStateAsync.d.ts +0 -111
  273. package/dist/types/flow/nodes/async/flowStateAsync.d.ts.map +0 -1
  274. package/dist/types/flow/nodes/async/index.d.ts.map +0 -1
  275. package/dist/types/flow/nodes/index.d.ts +0 -3
  276. package/dist/types/flow/nodes/index.d.ts.map +0 -1
  277. package/dist/types/flow/nodes/sync/flowConstant.d.ts +0 -108
  278. package/dist/types/flow/nodes/sync/flowConstant.d.ts.map +0 -1
  279. package/dist/types/flow/nodes/sync/flowDerivation.d.ts +0 -100
  280. package/dist/types/flow/nodes/sync/flowDerivation.d.ts.map +0 -1
  281. package/dist/types/flow/nodes/sync/flowNode.d.ts +0 -314
  282. package/dist/types/flow/nodes/sync/flowNode.d.ts.map +0 -1
  283. package/dist/types/flow/nodes/sync/flowReadonly.d.ts +0 -57
  284. package/dist/types/flow/nodes/sync/flowReadonly.d.ts.map +0 -1
  285. package/dist/types/flow/nodes/sync/flowState.d.ts +0 -96
  286. package/dist/types/flow/nodes/sync/flowState.d.ts.map +0 -1
  287. package/dist/types/flow/nodes/sync/index.d.ts.map +0 -1
  288. package/dist/types/solid/converters.d.ts +0 -53
  289. package/dist/types/solid/converters.d.ts.map +0 -1
  290. package/dist/types/solid/index.d.ts +0 -3
  291. package/dist/types/solid/index.d.ts.map +0 -1
  292. package/dist/types/solid/primitives.d.ts +0 -181
  293. package/dist/types/solid/primitives.d.ts.map +0 -1
  294. package/docs/api/classes/FlowArray.md +0 -489
  295. package/docs/api/classes/FlowConstant.md +0 -350
  296. package/docs/api/classes/FlowDerivation.md +0 -334
  297. package/docs/api/classes/FlowEffect.md +0 -100
  298. package/docs/api/classes/FlowMap.md +0 -512
  299. package/docs/api/classes/FlowObservable.md +0 -306
  300. package/docs/api/classes/FlowResource.md +0 -380
  301. package/docs/api/classes/FlowResourceAsync.md +0 -362
  302. package/docs/api/classes/FlowSignal.md +0 -160
  303. package/docs/api/classes/FlowState.md +0 -368
  304. package/docs/api/classes/FlowStream.md +0 -367
  305. package/docs/api/classes/FlowStreamAsync.md +0 -364
  306. package/docs/api/classes/SolidDerivation.md +0 -75
  307. package/docs/api/classes/SolidResource.md +0 -91
  308. package/docs/api/classes/SolidState.md +0 -71
  309. package/docs/api/classes/TrackingContext.md +0 -33
  310. package/docs/api/functions/effect.md +0 -49
  311. package/docs/api/functions/resource.md +0 -52
  312. package/docs/api/functions/resourceAsync.md +0 -50
  313. package/docs/api/functions/stream.md +0 -53
  314. package/docs/api/functions/streamAsync.md +0 -50
  315. package/docs/api/interfaces/SolidObservable.md +0 -19
  316. package/docs/api/type-aliases/FlowStreamDisposer.md +0 -15
  317. package/docs/api/type-aliases/FlowStreamSetter.md +0 -27
  318. package/docs/api/type-aliases/FlowStreamUpdater.md +0 -32
  319. package/docs/api/type-aliases/SolidGetter.md +0 -17
  320. package/docs/guide/primitives/resources.md +0 -858
  321. package/docs/guide/primitives/streams.md +0 -931
  322. package/src/flow/base/flowDisposable.ts +0 -71
  323. package/src/flow/base/flowEffect.ts +0 -171
  324. package/src/flow/base/flowGraph.ts +0 -288
  325. package/src/flow/base/flowSignal.ts +0 -207
  326. package/src/flow/base/flowTracker.ts +0 -17
  327. package/src/flow/base/index.ts +0 -6
  328. package/src/flow/base/utils.ts +0 -19
  329. package/src/flow/collections/flowArray.ts +0 -409
  330. package/src/flow/collections/flowMap.ts +0 -398
  331. package/src/flow/nodes/async/flowConstantAsync.ts +0 -142
  332. package/src/flow/nodes/async/flowDerivationAsync.ts +0 -143
  333. package/src/flow/nodes/async/flowNodeAsync.ts +0 -474
  334. package/src/flow/nodes/async/flowReadonlyAsync.ts +0 -81
  335. package/src/flow/nodes/async/flowStateAsync.ts +0 -116
  336. package/src/flow/nodes/await/advanced/index.ts +0 -5
  337. package/src/flow/nodes/await/advanced/resource.ts +0 -134
  338. package/src/flow/nodes/await/advanced/resourceAsync.ts +0 -109
  339. package/src/flow/nodes/await/advanced/stream.ts +0 -188
  340. package/src/flow/nodes/await/advanced/streamAsync.ts +0 -176
  341. package/src/flow/nodes/await/flowConstantAwait.ts +0 -154
  342. package/src/flow/nodes/await/flowDerivationAwait.ts +0 -154
  343. package/src/flow/nodes/await/flowNodeAwait.ts +0 -508
  344. package/src/flow/nodes/await/flowReadonlyAwait.ts +0 -89
  345. package/src/flow/nodes/await/flowStateAwait.ts +0 -130
  346. package/src/flow/nodes/await/index.ts +0 -5
  347. package/src/flow/nodes/index.ts +0 -3
  348. package/src/flow/nodes/sync/flowConstant.ts +0 -111
  349. package/src/flow/nodes/sync/flowDerivation.ts +0 -105
  350. package/src/flow/nodes/sync/flowNode.ts +0 -439
  351. package/src/flow/nodes/sync/flowReadonly.ts +0 -57
  352. package/src/flow/nodes/sync/flowState.ts +0 -101
  353. package/src/solid/converters.ts +0 -139
  354. package/src/solid/index.ts +0 -2
  355. package/src/solid/primitives.ts +0 -215
  356. package/test/base/flowEffect.test.ts +0 -108
  357. package/test/base/flowGraph.test.ts +0 -485
  358. package/test/base/flowSignal.test.ts +0 -372
  359. package/test/collections/flowArray.asyncStates.test.ts +0 -1553
  360. package/test/collections/flowArray.scalars.test.ts +0 -1129
  361. package/test/collections/flowArray.states.test.ts +0 -1365
  362. package/test/collections/flowMap.asyncStates.test.ts +0 -1105
  363. package/test/collections/flowMap.scalars.test.ts +0 -877
  364. package/test/collections/flowMap.states.test.ts +0 -1097
  365. package/test/nodes/async/flowConstantAsync.test.ts +0 -860
  366. package/test/nodes/async/flowDerivationAsync.test.ts +0 -1517
  367. package/test/nodes/async/flowStateAsync.test.ts +0 -1387
  368. package/test/nodes/await/advanced/resource.test.ts +0 -129
  369. package/test/nodes/await/advanced/resourceAsync.test.ts +0 -108
  370. package/test/nodes/await/advanced/stream.test.ts +0 -198
  371. package/test/nodes/await/advanced/streamAsync.test.ts +0 -196
  372. package/test/nodes/await/flowConstantAwait.test.ts +0 -643
  373. package/test/nodes/await/flowDerivationAwait.test.ts +0 -1583
  374. package/test/nodes/await/flowStateAwait.test.ts +0 -999
  375. package/test/nodes/mixed/derivation.test.ts +0 -1527
  376. package/test/nodes/sync/flowConstant.test.ts +0 -620
  377. package/test/nodes/sync/flowDerivation.test.ts +0 -1373
  378. package/test/nodes/sync/flowState.test.ts +0 -945
  379. package/test/solid/converters.test.ts +0 -721
  380. package/test/solid/primitives.test.ts +0 -1031
  381. /package/dist/types/{flow → api/nodes}/collections/index.d.ts +0 -0
  382. /package/docs/guide/advanced/{upgrading.md → migration-v1.md} +0 -0
  383. /package/src/{flow → api/nodes}/collections/index.ts +0 -0
@@ -0,0 +1,958 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+ import { type FlowState, map, state, subscribe } from "~";
3
+
4
+ describe("FlowMap", () => {
5
+ describe("unit", () => {
6
+ describe("initialization", () => {
7
+ it("should initialize with provided Record of FlowState values", async () => {
8
+ const $map = map({
9
+ key1: state(1),
10
+ key2: state(2),
11
+ key3: state(3),
12
+ });
13
+
14
+ const values = await Promise.all(
15
+ Array.from((await $map.pick()).entries()).map(([_, value]) => value.pick()),
16
+ );
17
+
18
+ expect(values).toEqual([1, 2, 3]);
19
+ });
20
+
21
+ it("should initialize with provided Map of FlowState values", async () => {
22
+ const $value1 = state(1);
23
+ const $value2 = state(2);
24
+ const initialMap = new Map([
25
+ ["key1", $value1],
26
+ ["key2", $value2],
27
+ ]);
28
+ const $map = map(initialMap);
29
+
30
+ expect(Array.from((await $map.pick()).entries())).toEqual([
31
+ ["key1", $value1],
32
+ ["key2", $value2],
33
+ ]);
34
+ });
35
+
36
+ it("should initialize with empty map when no value provided", async () => {
37
+ const $map = map<string, FlowState<number>>();
38
+
39
+ expect(Array.from((await $map.pick()).entries())).toEqual([]);
40
+ expect((await $map.pick()).size).toBe(0);
41
+ });
42
+
43
+ it("should initialize $lastAction with set action on creation", async () => {
44
+ const $value1 = state(1);
45
+ const $value2 = state(2);
46
+ const $map = map({
47
+ key1: $value1,
48
+ key2: $value2,
49
+ });
50
+ const action = await $map.$lastAction.pick();
51
+ expect(action.type).toBe("set");
52
+ if (action.type === "set") {
53
+ expect(action.setMap.size).toBe(2);
54
+ expect(action.setMap.get("key1")).toBe($value1);
55
+ expect(action.setMap.get("key2")).toBe($value2);
56
+ }
57
+ });
58
+
59
+ it("should initialize $lastAction with empty map when no value provided", async () => {
60
+ const $map = map<string, FlowState<number>>();
61
+ const action = await $map.$lastAction.pick();
62
+ expect(action.type).toBe("set");
63
+ if (action.type === "set") {
64
+ expect(action.setMap.size).toBe(0);
65
+ }
66
+ });
67
+ });
68
+
69
+ describe("disposal", () => {
70
+ it("should have disposed property set to false initially and true after disposal", () => {
71
+ const $map = map({
72
+ key1: state(1),
73
+ key2: state(2),
74
+ });
75
+ expect($map.disposed).toBe(false);
76
+ $map.dispose();
77
+ expect($map.disposed).toBe(true);
78
+ });
79
+
80
+ it("should throw error when disposed twice", () => {
81
+ const $map = map({
82
+ key1: state(1),
83
+ key2: state(2),
84
+ });
85
+ $map.dispose();
86
+ expect(() => $map.dispose()).toThrow("[PicoFlow] Primitive is disposed");
87
+ });
88
+
89
+ it("should throw when pick is called after disposal", async () => {
90
+ const $map = map<string, FlowState<number>>({
91
+ key1: state(1),
92
+ key2: state(2),
93
+ key3: state(3),
94
+ });
95
+ $map.dispose();
96
+ await expect($map.pick()).rejects.toThrow("[PicoFlow] Primitive is disposed");
97
+ });
98
+
99
+ it("should throw when set is called after disposal", () => {
100
+ const $map = map<string, FlowState<number>>({
101
+ key1: state(1),
102
+ });
103
+ $map.dispose();
104
+ expect(() => $map.set(new Map([["key2", state(2)]]))).toThrow("[PicoFlow] Primitive is disposed");
105
+ });
106
+
107
+ it("should throw when add is called after disposal", () => {
108
+ const $map = map<string, FlowState<number>>();
109
+ $map.dispose();
110
+ expect(() => $map.add("key1", state(2))).toThrow("[PicoFlow] Primitive is disposed");
111
+ });
112
+
113
+ it("should throw when update is called after disposal", () => {
114
+ const $map = map<string, FlowState<number>>();
115
+ $map.add("key1", state(1));
116
+ $map.dispose();
117
+ expect(() => $map.update("key1", state(2))).toThrow("[PicoFlow] Primitive is disposed");
118
+ });
119
+
120
+ it("should throw when delete is called after disposal", () => {
121
+ const $map = map<string, FlowState<number>>({
122
+ key1: state(1),
123
+ key2: state(2),
124
+ key3: state(3),
125
+ });
126
+ $map.dispose();
127
+ expect(() => $map.delete("key1")).toThrow("[PicoFlow] Primitive is disposed");
128
+ });
129
+
130
+ it("should throw when clear is called after disposal", () => {
131
+ const $map = map<string, FlowState<number>>({
132
+ key1: state(1),
133
+ key2: state(2),
134
+ });
135
+ $map.dispose();
136
+ expect(() => $map.clear()).toThrow("[PicoFlow] Primitive is disposed");
137
+ });
138
+
139
+ it("should dispose values when FlowMap is disposed", () => {
140
+ const $map = map<string, FlowState<number>>();
141
+ const $value1 = state(1);
142
+ const $value2 = state(2);
143
+ const $value3 = state(3);
144
+
145
+ $map.add("key1", $value1);
146
+ $map.add("key2", $value2);
147
+ $map.add("key3", $value3);
148
+
149
+ expect($value1.disposed).toBe(false);
150
+ expect($value2.disposed).toBe(false);
151
+ expect($value3.disposed).toBe(false);
152
+
153
+ $map.dispose();
154
+
155
+ expect($value1.disposed).toBe(true);
156
+ expect($value2.disposed).toBe(true);
157
+ expect($value3.disposed).toBe(true);
158
+ });
159
+
160
+ it("should dispose values with provided options when FlowMap is disposed", () => {
161
+ const $map = map<string, FlowState<number>>();
162
+ const $value1 = state(1);
163
+ const $value2 = state(2);
164
+
165
+ $map.add("key1", $value1);
166
+ $map.add("key2", $value2);
167
+
168
+ const onData = vi.fn();
169
+ const $effect = subscribe((t) => $value1.get(t), onData);
170
+
171
+ expect($effect.disposed).toBe(false);
172
+
173
+ $map.dispose();
174
+
175
+ expect($value1.disposed).toBe(true);
176
+ expect($value2.disposed).toBe(true);
177
+ expect($effect.disposed).toBe(false);
178
+
179
+ $effect.dispose();
180
+ });
181
+
182
+ it("should handle non-disposable values gracefully", async () => {
183
+ const $map = map<string, FlowState<number>>();
184
+ $map.add("key1", state(1));
185
+ $map.add("key2", state(2));
186
+ $map.add("key3", state(3));
187
+
188
+ expect((await $map.pick()).size).toBe(3);
189
+
190
+ expect(() => $map.dispose()).not.toThrow();
191
+ });
192
+ });
193
+
194
+ describe("set", () => {
195
+ it("should replace entire map when set is called", async () => {
196
+ const $map = map<string, FlowState<number>>({
197
+ key1: state(1),
198
+ key2: state(2),
199
+ });
200
+ const $newValue1 = state(3);
201
+ const $newValue2 = state(4);
202
+ const newMap = new Map([
203
+ ["key3", $newValue1],
204
+ ["key4", $newValue2],
205
+ ]);
206
+
207
+ $map.set(newMap);
208
+ expect(Array.from((await $map.pick()).entries())).toEqual([
209
+ ["key3", $newValue1],
210
+ ["key4", $newValue2],
211
+ ]);
212
+ });
213
+
214
+ it("should update $lastAction with set action when set is called", async () => {
215
+ const $map = map<string, FlowState<number>>({
216
+ key1: state(1),
217
+ key2: state(2),
218
+ });
219
+ const $newValue1 = state(3);
220
+ const $newValue2 = state(4);
221
+ const newMap = new Map([
222
+ ["key3", $newValue1],
223
+ ["key4", $newValue2],
224
+ ]);
225
+
226
+ $map.set(newMap);
227
+ const action = await $map.$lastAction.pick();
228
+ expect(action.type).toBe("set");
229
+ if (action.type === "set") {
230
+ expect(action.setMap).toBe(newMap);
231
+ expect(action.clearedMap).toBeInstanceOf(Map);
232
+ }
233
+ });
234
+ });
235
+
236
+ describe("add", () => {
237
+ it("should add key-value pair to map", async () => {
238
+ const $map = map<string, FlowState<number>>();
239
+
240
+ $map.add("key1", state(1));
241
+ expect(await (await $map.pick()).get("key1")?.pick()).toBe(1);
242
+ expect((await $map.pick()).size).toBe(1);
243
+ });
244
+
245
+ it("should add multiple keys successively", async () => {
246
+ const $map = map<string, FlowState<number>>();
247
+
248
+ $map.add("key1", state(1));
249
+ $map.add("key2", state(2));
250
+ $map.add("key3", state(3));
251
+
252
+ expect((await $map.pick()).size).toBe(3);
253
+ expect(await (await $map.pick()).get("key1")?.pick()).toBe(1);
254
+ expect(await (await $map.pick()).get("key2")?.pick()).toBe(2);
255
+ expect(await (await $map.pick()).get("key3")?.pick()).toBe(3);
256
+ });
257
+
258
+ it("should throw when key already exists", () => {
259
+ const $map = map<string, FlowState<number>>();
260
+ $map.add("key1", state(1));
261
+ expect(() => $map.add("key1", state(2))).toThrow("[PicoFlow] Key already exists");
262
+ });
263
+
264
+ it("should update $lastAction with add action when add is called", async () => {
265
+ const $map = map<string, FlowState<number>>();
266
+ const $value = state(1);
267
+ $map.add("key1", $value);
268
+ const action = await $map.$lastAction.pick();
269
+ expect(action).toEqual({
270
+ type: "add",
271
+ key: "key1",
272
+ addedValue: $value,
273
+ });
274
+ });
275
+
276
+ it("should have FlowState value in $lastAction when add is called", async () => {
277
+ const $map = map<string, FlowState<number>>();
278
+ const $value = state(100);
279
+ $map.add("key1", $value);
280
+ const action = await $map.$lastAction.pick();
281
+ expect(action.type).toBe("add");
282
+ if (action.type === "add") {
283
+ expect(action.addedValue).toBe($value);
284
+ expect(await action.addedValue.pick()).toBe(100);
285
+ }
286
+ });
287
+
288
+ it("should trigger reactivity when add is called", async () => {
289
+ const $map = map<string, FlowState<number>>();
290
+ const onData = vi.fn();
291
+ subscribe((t) => $map.get(t), onData);
292
+
293
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
294
+
295
+ $map.add("key1", state(1));
296
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
297
+ });
298
+ });
299
+
300
+ describe("update", () => {
301
+ it("should update existing key-value pair", async () => {
302
+ const $map = map<string, FlowState<number>>();
303
+ $map.add("key1", state(1));
304
+
305
+ const $newValue = state(2);
306
+ $map.update("key1", $newValue);
307
+ expect(await (await $map.pick()).get("key1")?.pick()).toBe(2);
308
+ });
309
+
310
+ it("should update multiple keys successively", async () => {
311
+ const $map = map<string, FlowState<number>>();
312
+ $map.add("key1", state(1));
313
+ $map.add("key2", state(2));
314
+
315
+ $map.update("key1", state(10));
316
+ $map.update("key2", state(20));
317
+
318
+ expect(await (await $map.pick()).get("key1")?.pick()).toBe(10);
319
+ expect(await (await $map.pick()).get("key2")?.pick()).toBe(20);
320
+ });
321
+
322
+ it("should throw when key does not exist", () => {
323
+ const $map = map<string, FlowState<number>>();
324
+ expect(() => $map.update("key1", state(1))).toThrow("[PicoFlow] Key does not exist");
325
+ });
326
+
327
+ it("should update $lastAction with update action when update is called", async () => {
328
+ const $map = map<string, FlowState<number>>();
329
+ $map.add("key1", state(1));
330
+ const $newValue = state(2);
331
+ $map.update("key1", $newValue);
332
+ const action = await $map.$lastAction.pick();
333
+ expect(action).toEqual({
334
+ type: "update",
335
+ key: "key1",
336
+ setValue: $newValue,
337
+ clearedValue: expect.any(Object),
338
+ });
339
+ });
340
+
341
+ it("should have FlowState value in $lastAction when update is called", async () => {
342
+ const $map = map<string, FlowState<number>>();
343
+ $map.add("key1", state(1));
344
+ const $newValue = state(200);
345
+ $map.update("key1", $newValue);
346
+ const action = await $map.$lastAction.pick();
347
+ expect(action.type).toBe("update");
348
+ if (action.type === "update") {
349
+ expect(action.setValue).toBe($newValue);
350
+ expect(await action.setValue.pick()).toBe(200);
351
+ }
352
+ });
353
+
354
+ it("should trigger reactivity when update is called", async () => {
355
+ const $map = map<string, FlowState<number>>();
356
+ $map.add("key1", state(1));
357
+ const onData = vi.fn();
358
+ subscribe((t) => $map.get(t), onData);
359
+
360
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
361
+
362
+ $map.update("key1", state(2));
363
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
364
+ });
365
+ });
366
+
367
+ describe("delete", () => {
368
+ it("should delete key from map", async () => {
369
+ const $map = map<string, FlowState<number>>();
370
+ $map.add("key1", state(1));
371
+ $map.add("key2", state(2));
372
+
373
+ $map.delete("key1");
374
+ expect(await (await $map.pick()).get("key1")?.pick()).toBe(undefined);
375
+ expect(await (await $map.pick()).get("key2")?.pick()).toBe(2);
376
+ expect((await $map.pick()).size).toBe(1);
377
+ });
378
+
379
+ it("should delete multiple keys successively", async () => {
380
+ const $map = map<string, FlowState<number>>();
381
+ $map.add("key1", state(1));
382
+ $map.add("key2", state(2));
383
+ $map.add("key3", state(3));
384
+
385
+ $map.delete("key1");
386
+ $map.delete("key2");
387
+
388
+ expect((await $map.pick()).size).toBe(1);
389
+ expect(await (await $map.pick()).get("key3")?.pick()).toBe(3);
390
+ });
391
+
392
+ it("should throw when key does not exist", () => {
393
+ const $map = map<string, FlowState<number>>();
394
+ expect(() => $map.delete("key1")).toThrow("[PicoFlow] Key does not exist");
395
+ });
396
+
397
+ it("should update $lastAction with delete action when delete is called", async () => {
398
+ const $map = map<string, FlowState<number>>();
399
+ const $value = state(1);
400
+ $map.add("key1", $value);
401
+ $map.delete("key1");
402
+ const action = await $map.$lastAction.pick();
403
+ expect(action.type).toBe("delete");
404
+ if (action.type === "delete") {
405
+ expect(action.key).toBe("key1");
406
+ expect(action.removedValue).toBe($value);
407
+ }
408
+ });
409
+
410
+ it("should trigger reactivity when delete is called", async () => {
411
+ const $map = map<string, FlowState<number>>();
412
+ $map.add("key1", state(1));
413
+ const onData = vi.fn();
414
+ subscribe((t) => $map.get(t), onData);
415
+
416
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
417
+
418
+ $map.delete("key1");
419
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
420
+ });
421
+ });
422
+
423
+ describe("clear", () => {
424
+ it("should remove all entries from map", async () => {
425
+ const $map = map<string, FlowState<number>>({
426
+ key1: state(1),
427
+ key2: state(2),
428
+ key3: state(3),
429
+ });
430
+ expect((await $map.pick()).size).toBe(3);
431
+
432
+ $map.clear();
433
+ expect((await $map.pick()).size).toBe(0);
434
+ });
435
+
436
+ it("should update $lastAction with clear action when clear is called", async () => {
437
+ const $map = map<string, FlowState<number>>({
438
+ key1: state(1),
439
+ key2: state(2),
440
+ });
441
+ $map.clear();
442
+ const action = await $map.$lastAction.pick();
443
+ expect(action.type).toBe("clear");
444
+ if (action.type === "clear") {
445
+ expect(action.clearedMap).toBeInstanceOf(Map);
446
+ expect(action.clearedMap.size).toBe(2);
447
+ }
448
+ });
449
+ });
450
+
451
+ describe("$lastAction", () => {
452
+ describe("set action", () => {
453
+ it("should initialize $lastAction with set action on creation", async () => {
454
+ const $value1 = state(1);
455
+ const $value2 = state(2);
456
+ const $map = map({
457
+ key1: $value1,
458
+ key2: $value2,
459
+ });
460
+ const action = await $map.$lastAction.pick();
461
+ expect(action).toEqual({
462
+ type: "set",
463
+ setMap: expect.any(Map),
464
+ clearedMap: expect.any(Map),
465
+ });
466
+ if (action.type === "set") {
467
+ expect(action.setMap.get("key1")).toBe($value1);
468
+ expect(action.setMap.get("key2")).toBe($value2);
469
+ }
470
+ });
471
+
472
+ it("should update $lastAction with set action when set is called", async () => {
473
+ const $map = map<string, FlowState<number>>({
474
+ key1: state(1),
475
+ });
476
+ const $newValue = state(2);
477
+ const newMap = new Map([["key2", $newValue]]);
478
+ $map.set(newMap);
479
+ const action = await $map.$lastAction.pick();
480
+ expect(action).toEqual({
481
+ type: "set",
482
+ setMap: newMap,
483
+ clearedMap: expect.any(Map),
484
+ });
485
+ });
486
+
487
+ it("should have correct structure for set action (type + setMap + clearedMap with FlowState)", async () => {
488
+ const $value = state(1);
489
+ const $map = map({ key1: $value });
490
+ const action = await $map.$lastAction.pick();
491
+ expect(action).toHaveProperty("type", "set");
492
+ if (action.type === "set") {
493
+ expect(action).toHaveProperty("setMap");
494
+ expect(action).toHaveProperty("clearedMap");
495
+ expect(action.setMap).toBeInstanceOf(Map);
496
+ expect(action.clearedMap).toBeInstanceOf(Map);
497
+ expect(action.setMap.get("key1")).toBe($value);
498
+ }
499
+ });
500
+ });
501
+
502
+ describe("add action", () => {
503
+ it("should update $lastAction with add action when add is called", async () => {
504
+ const $map = map<string, FlowState<number>>();
505
+ const $value = state(1);
506
+ $map.add("key1", $value);
507
+ const action = await $map.$lastAction.pick();
508
+ expect(action).toEqual({
509
+ type: "add",
510
+ key: "key1",
511
+ addedValue: $value,
512
+ });
513
+ });
514
+
515
+ it("should have correct structure for add action (type + key + FlowState addedValue)", async () => {
516
+ const $map = map<string, FlowState<number>>();
517
+ const $value = state(100);
518
+ $map.add("key1", $value);
519
+ const action = await $map.$lastAction.pick();
520
+ expect(action).toHaveProperty("type", "add");
521
+ if (action.type === "add") {
522
+ expect(action).toHaveProperty("key");
523
+ expect(action).toHaveProperty("addedValue");
524
+ expect(action.key).toBe("key1");
525
+ expect(action.addedValue).toBe($value);
526
+ expect(await action.addedValue.pick()).toBe(100);
527
+ }
528
+ });
529
+ });
530
+
531
+ describe("update action", () => {
532
+ it("should update $lastAction with update action when update is called", async () => {
533
+ const $map = map<string, FlowState<number>>();
534
+ $map.add("key1", state(1));
535
+ const $newValue = state(2);
536
+ $map.update("key1", $newValue);
537
+ const action = await $map.$lastAction.pick();
538
+ expect(action).toEqual({
539
+ type: "update",
540
+ key: "key1",
541
+ setValue: $newValue,
542
+ clearedValue: expect.any(Object),
543
+ });
544
+ });
545
+
546
+ it("should have correct structure for update action (type + key + FlowState setValue + clearedValue)", async () => {
547
+ const $map = map<string, FlowState<number>>();
548
+ $map.add("key1", state(1));
549
+ const $newValue = state(200);
550
+ $map.update("key1", $newValue);
551
+ const action = await $map.$lastAction.pick();
552
+ expect(action).toHaveProperty("type", "update");
553
+ if (action.type === "update") {
554
+ expect(action).toHaveProperty("key");
555
+ expect(action).toHaveProperty("setValue");
556
+ expect(action).toHaveProperty("clearedValue");
557
+ expect(action.key).toBe("key1");
558
+ expect(action.setValue).toBe($newValue);
559
+ expect(await action.setValue.pick()).toBe(200);
560
+ }
561
+ });
562
+ });
563
+
564
+ describe("delete action", () => {
565
+ it("should update $lastAction with delete action when delete is called", async () => {
566
+ const $map = map<string, FlowState<number>>();
567
+ const $value = state(1);
568
+ $map.add("key1", $value);
569
+ $map.delete("key1");
570
+ const action = await $map.$lastAction.pick();
571
+ expect(action).toEqual({
572
+ type: "delete",
573
+ key: "key1",
574
+ removedValue: $value,
575
+ });
576
+ });
577
+
578
+ it("should have correct structure for delete action (type + key + FlowState removedValue)", async () => {
579
+ const $map = map<string, FlowState<number>>();
580
+ const $value = state(300);
581
+ $map.add("key1", $value);
582
+ $map.delete("key1");
583
+ const action = await $map.$lastAction.pick();
584
+ expect(action).toHaveProperty("type", "delete");
585
+ if (action.type === "delete") {
586
+ expect(action).toHaveProperty("key");
587
+ expect(action).toHaveProperty("removedValue");
588
+ expect(action.key).toBe("key1");
589
+ expect(action.removedValue).toBe($value);
590
+ }
591
+ });
592
+ });
593
+
594
+ describe("clear action", () => {
595
+ it("should update $lastAction with clear action when clear is called", async () => {
596
+ const $map = map<string, FlowState<number>>({
597
+ key1: state(1),
598
+ key2: state(2),
599
+ });
600
+ $map.clear();
601
+ const action = await $map.$lastAction.pick();
602
+ expect(action.type).toBe("clear");
603
+ if (action.type === "clear") {
604
+ expect(action.clearedMap).toBeInstanceOf(Map);
605
+ expect(action.clearedMap.size).toBe(2);
606
+ }
607
+ });
608
+
609
+ it("should have correct structure for clear action (type + clearedMap)", async () => {
610
+ const $map = map<string, FlowState<number>>({
611
+ key1: state(1),
612
+ });
613
+ $map.clear();
614
+ const action = await $map.$lastAction.pick();
615
+ expect(action).toHaveProperty("type", "clear");
616
+ if (action.type === "clear") {
617
+ expect(action).toHaveProperty("clearedMap");
618
+ expect(action.clearedMap).toBeInstanceOf(Map);
619
+ }
620
+ });
621
+ });
622
+ });
623
+
624
+ describe("edge cases", () => {
625
+ it("should handle multiple rapid operations", async () => {
626
+ const $map = map<string, FlowState<number>>();
627
+ $map.add("key1", state(1));
628
+ $map.add("key2", state(2));
629
+ $map.add("key3", state(3));
630
+ $map.update("key1", state(10));
631
+ $map.delete("key2");
632
+ $map.add("key4", state(4));
633
+ $map.clear();
634
+ $map.add("key5", state(5));
635
+
636
+ expect((await $map.pick()).size).toBe(1);
637
+ expect(await (await $map.pick()).get("key5")?.pick()).toBe(5);
638
+ });
639
+
640
+ it("should handle empty map operations", async () => {
641
+ const $map = map<string, FlowState<number>>();
642
+ expect((await $map.pick()).size).toBe(0);
643
+
644
+ $map.add("key1", state(1));
645
+ expect((await $map.pick()).size).toBe(1);
646
+
647
+ $map.delete("key1");
648
+ expect((await $map.pick()).size).toBe(0);
649
+ });
650
+
651
+ it("should handle map with single entry", async () => {
652
+ const $map = map<string, FlowState<number>>({
653
+ key1: state(1),
654
+ });
655
+ expect((await $map.pick()).size).toBe(1);
656
+
657
+ $map.update("key1", state(2));
658
+ expect(await (await $map.pick()).get("key1")?.pick()).toBe(2);
659
+
660
+ $map.delete("key1");
661
+ expect((await $map.pick()).size).toBe(0);
662
+ });
663
+
664
+ it("should handle map with many entries", async () => {
665
+ const $map = map<string, FlowState<number>>();
666
+ for (let i = 0; i < 100; i++) {
667
+ $map.add(`key${i}`, state(i));
668
+ }
669
+ expect((await $map.pick()).size).toBe(100);
670
+
671
+ for (let i = 0; i < 50; i++) {
672
+ $map.delete(`key${i}`);
673
+ }
674
+ expect((await $map.pick()).size).toBe(50);
675
+ });
676
+
677
+ it("should handle disposed values in map", async () => {
678
+ const $value = state(1);
679
+ const $map = map(new Map([["key1", $value]]));
680
+
681
+ $map.delete("key1");
682
+
683
+ // In flow2, values are NOT automatically disposed
684
+ expect($value.disposed).toBe(false);
685
+ expect((await $map.pick()).size).toBe(0);
686
+ });
687
+
688
+ it("should handle effects on FlowState values in map", async () => {
689
+ const $value = state(1);
690
+ const $map = map(new Map([["key1", $value]]));
691
+ const onData = vi.fn();
692
+
693
+ subscribe(
694
+ (t) => $map.get(t).get("key1")?.get(t),
695
+ (data) => {
696
+ if (data) {
697
+ onData(data);
698
+ }
699
+ },
700
+ );
701
+
702
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
703
+ expect(onData).toHaveBeenLastCalledWith(1);
704
+
705
+ $value.set(2);
706
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
707
+ expect(onData).toHaveBeenLastCalledWith(2);
708
+ });
709
+ });
710
+ });
711
+
712
+ describe("integration", () => {
713
+ describe("with effects", () => {
714
+ describe("reactivity", () => {
715
+ it("should call effect when initialized", async () => {
716
+ const $map = map<string, FlowState<number>>({
717
+ key1: state(1),
718
+ key2: state(2),
719
+ });
720
+ const onData = vi.fn();
721
+ subscribe((t) => $map.get(t), onData);
722
+
723
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
724
+ expect(onData).toHaveBeenLastCalledWith(
725
+ expect.objectContaining({
726
+ size: 2,
727
+ }),
728
+ );
729
+ });
730
+
731
+ it("should call effect when updated with set", async () => {
732
+ const $map = map<string, FlowState<number>>({
733
+ key1: state(1),
734
+ });
735
+ const onData = vi.fn();
736
+ subscribe((t) => $map.get(t), onData);
737
+
738
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
739
+
740
+ const $newValue = state(2);
741
+ $map.set(new Map([["key2", $newValue]]));
742
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
743
+ expect(onData).toHaveBeenLastCalledWith(
744
+ expect.objectContaining({
745
+ size: 1,
746
+ }),
747
+ );
748
+ });
749
+
750
+ it("should call effect when updated with add", async () => {
751
+ const $map = map<string, FlowState<number>>();
752
+ const onData = vi.fn();
753
+ subscribe((t) => $map.get(t), onData);
754
+
755
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
756
+ expect(onData).toHaveBeenLastCalledWith(new Map());
757
+
758
+ const $key1Value = state(1);
759
+ $map.add("key1", $key1Value);
760
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
761
+ expect(onData).toHaveBeenLastCalledWith(new Map([["key1", $key1Value]]));
762
+
763
+ const $key2Value = state(2);
764
+ $map.add("key2", $key2Value);
765
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
766
+ expect(onData).toHaveBeenLastCalledWith(
767
+ new Map([
768
+ ["key1", $key1Value],
769
+ ["key2", $key2Value],
770
+ ]),
771
+ );
772
+ });
773
+
774
+ it("should call effect when updated with update", async () => {
775
+ const $map = map<string, FlowState<number>>();
776
+ $map.add("key1", state(1));
777
+ const onData = vi.fn();
778
+ subscribe((t) => $map.get(t), onData);
779
+
780
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
781
+
782
+ const $newValue = state(2);
783
+ $map.update("key1", $newValue);
784
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
785
+ expect(onData).toHaveBeenLastCalledWith(new Map([["key1", $newValue]]));
786
+ });
787
+
788
+ it("should call effect when updated with delete", async () => {
789
+ const $map = map<string, FlowState<number>>();
790
+ $map.add("key1", state(1));
791
+ $map.add("key2", state(2));
792
+ const onData = vi.fn();
793
+ subscribe((t) => $map.get(t), onData);
794
+
795
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
796
+
797
+ $map.delete("key1");
798
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
799
+ const mapAfterDelete = onData.mock.calls[1][0];
800
+ expect(mapAfterDelete.size).toBe(1);
801
+ expect(mapAfterDelete.has("key2")).toBe(true);
802
+ });
803
+
804
+ it("should call effect when updated with clear", async () => {
805
+ const $map = map<string, FlowState<number>>({
806
+ key1: state(1),
807
+ key2: state(2),
808
+ });
809
+ const onData = vi.fn();
810
+ subscribe((t) => $map.get(t), onData);
811
+
812
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
813
+
814
+ $map.clear();
815
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
816
+ expect(onData).toHaveBeenLastCalledWith(new Map());
817
+ });
818
+
819
+ it("should call effect when FlowState values in map are updated", async () => {
820
+ const $value = state(1);
821
+ const $map = map(new Map([["key1", $value]]));
822
+ const onData = vi.fn();
823
+
824
+ subscribe(
825
+ (t) => $map.get(t).get("key1")?.get(t),
826
+ (data) => {
827
+ if (data) {
828
+ onData(data);
829
+ }
830
+ },
831
+ );
832
+
833
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
834
+ expect(onData).toHaveBeenLastCalledWith(1);
835
+
836
+ $value.set(2);
837
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
838
+ expect(onData).toHaveBeenLastCalledWith(2);
839
+ });
840
+ });
841
+
842
+ describe("$lastAction", () => {
843
+ it("should call effect when $lastAction is updated with set action", async () => {
844
+ const $map = map<string, FlowState<number>>({
845
+ key1: state(1),
846
+ });
847
+ const onData = vi.fn();
848
+ subscribe((t) => $map.$lastAction.get(t), onData);
849
+
850
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
851
+
852
+ const $newValue = state(2);
853
+ $map.set(new Map([["key2", $newValue]]));
854
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
855
+ expect(onData).toHaveBeenLastCalledWith({
856
+ type: "set",
857
+ setMap: expect.any(Map),
858
+ clearedMap: expect.any(Map),
859
+ });
860
+ });
861
+
862
+ it("should call effect when $lastAction is updated with add action", async () => {
863
+ const $map = map<string, FlowState<number>>();
864
+ const onData = vi.fn();
865
+ subscribe((t) => $map.$lastAction.get(t), onData);
866
+
867
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
868
+
869
+ const $value = state(1);
870
+ $map.add("key1", $value);
871
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
872
+ expect(onData).toHaveBeenLastCalledWith({
873
+ type: "add",
874
+ key: "key1",
875
+ addedValue: $value,
876
+ });
877
+ });
878
+
879
+ it("should call effect when $lastAction is updated with update action", async () => {
880
+ const $map = map<string, FlowState<number>>();
881
+ $map.add("key1", state(1));
882
+ const onData = vi.fn();
883
+ subscribe((t) => $map.$lastAction.get(t), onData);
884
+
885
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
886
+
887
+ const $newValue = state(2);
888
+ $map.update("key1", $newValue);
889
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
890
+ expect(onData).toHaveBeenLastCalledWith({
891
+ type: "update",
892
+ key: "key1",
893
+ setValue: $newValue,
894
+ clearedValue: expect.any(Object),
895
+ });
896
+ });
897
+
898
+ it("should call effect when $lastAction is updated with delete action", async () => {
899
+ const $map = map<string, FlowState<number>>();
900
+ const $value = state(1);
901
+ $map.add("key1", $value);
902
+ const onData = vi.fn();
903
+ subscribe((t) => $map.$lastAction.get(t), onData);
904
+
905
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
906
+
907
+ $map.delete("key1");
908
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
909
+ expect(onData).toHaveBeenLastCalledWith({
910
+ type: "delete",
911
+ key: "key1",
912
+ removedValue: $value,
913
+ });
914
+ });
915
+
916
+ it("should call effect when $lastAction is updated with clear action", async () => {
917
+ const $map = map<string, FlowState<number>>({
918
+ key1: state(1),
919
+ key2: state(2),
920
+ });
921
+ const onData = vi.fn();
922
+ subscribe((t) => $map.$lastAction.get(t), onData);
923
+
924
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
925
+
926
+ $map.clear();
927
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
928
+ expect(onData).toHaveBeenLastCalledWith({
929
+ type: "clear",
930
+ clearedMap: expect.any(Map),
931
+ });
932
+ });
933
+
934
+ it("should call effect when FlowState value in $lastAction is updated", async () => {
935
+ const $map = map<string, FlowState<number>>();
936
+ const $value = state(1);
937
+ $map.add("key1", $value);
938
+ const onData = vi.fn();
939
+
940
+ subscribe((t) => {
941
+ const action = $map.$lastAction.get(t);
942
+ if (action.type === "add") {
943
+ return action.addedValue.get(t);
944
+ }
945
+ return undefined;
946
+ }, onData);
947
+
948
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
949
+ expect(onData).toHaveBeenLastCalledWith(1);
950
+
951
+ $value.set(2);
952
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
953
+ expect(onData).toHaveBeenLastCalledWith(2);
954
+ });
955
+ });
956
+ });
957
+ });
958
+ });