@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
@@ -1,1097 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
2
- import { effect, FlowGraph, type FlowState, map, state } from "#package";
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]) =>
16
- value.pick(),
17
- ),
18
- );
19
-
20
- expect(values).toEqual([1, 2, 3]);
21
- });
22
-
23
- it("should initialize with provided Map of FlowState values", async () => {
24
- const $value1 = state(1);
25
- const $value2 = state(2);
26
- const initialMap = new Map([
27
- ["key1", $value1],
28
- ["key2", $value2],
29
- ]);
30
- const $map = map(initialMap);
31
-
32
- expect(Array.from((await $map.pick()).entries())).toEqual([
33
- ["key1", $value1],
34
- ["key2", $value2],
35
- ]);
36
- });
37
-
38
- it("should initialize with empty map when no value provided", async () => {
39
- const $map = map<string, FlowState<number>>();
40
-
41
- expect(Array.from((await $map.pick()).entries())).toEqual([]);
42
- expect((await $map.pick()).size).toBe(0);
43
- });
44
-
45
- it("should initialize $lastAction with set action on creation", async () => {
46
- const $value1 = state(1);
47
- const $value2 = state(2);
48
- const $map = map({
49
- key1: $value1,
50
- key2: $value2,
51
- });
52
- const action = await $map.$lastAction.pick();
53
- expect(action.type).toBe("set");
54
- if (action.type === "set") {
55
- expect(action.map.size).toBe(2);
56
- expect(action.map.get("key1")).toBe($value1);
57
- expect(action.map.get("key2")).toBe($value2);
58
- }
59
- });
60
-
61
- it("should initialize $lastAction with empty map when no value provided", async () => {
62
- const $map = map<string, FlowState<number>>();
63
- const action = await $map.$lastAction.pick();
64
- expect(action.type).toBe("set");
65
- if (action.type === "set") {
66
- expect(action.map.size).toBe(0);
67
- }
68
- });
69
- });
70
-
71
- describe("disposal", () => {
72
- it("should have disposed property set to false initially and true after disposal", () => {
73
- const $map = map({
74
- key1: state(1),
75
- key2: state(2),
76
- });
77
- expect($map.disposed).toBe(false);
78
- $map.dispose();
79
- expect($map.disposed).toBe(true);
80
- });
81
-
82
- it("should throw error when disposed twice", () => {
83
- const $map = map({
84
- key1: state(1),
85
- key2: state(2),
86
- });
87
- $map.dispose();
88
- expect(() => $map.dispose()).toThrow(
89
- "[PicoFlow] Primitive is disposed",
90
- );
91
- });
92
-
93
- it("should throw when pick is called after disposal", async () => {
94
- const $map = map<string, FlowState<number>>({
95
- key1: state(1),
96
- key2: state(2),
97
- key3: state(3),
98
- });
99
- $map.dispose();
100
- await expect($map.pick()).rejects.toThrow(
101
- "[PicoFlow] Primitive is disposed",
102
- );
103
- });
104
-
105
- it("should throw when set is called after disposal", async () => {
106
- const $map = map<string, FlowState<number>>({
107
- key1: state(1),
108
- });
109
- $map.dispose();
110
- await expect($map.set(new Map([["key2", state(2)]]))).rejects.toThrow(
111
- "[PicoFlow] Primitive is disposed",
112
- );
113
- });
114
-
115
- it("should throw when add is called after disposal", async () => {
116
- const $map = map<string, FlowState<number>>();
117
- $map.dispose();
118
- await expect($map.add("key1", state(2))).rejects.toThrow(
119
- "[PicoFlow] Primitive is disposed",
120
- );
121
- });
122
-
123
- it("should throw when update is called after disposal", async () => {
124
- const $map = map<string, FlowState<number>>();
125
- await $map.add("key1", state(1));
126
- $map.dispose();
127
- await expect($map.update("key1", state(2))).rejects.toThrow(
128
- "[PicoFlow] Primitive is disposed",
129
- );
130
- });
131
-
132
- it("should throw when delete is called after disposal", async () => {
133
- const $map = map<string, FlowState<number>>({
134
- key1: state(1),
135
- key2: state(2),
136
- key3: state(3),
137
- });
138
- $map.dispose();
139
- await expect($map.delete("key1")).rejects.toThrow(
140
- "[PicoFlow] Primitive is disposed",
141
- );
142
- });
143
-
144
- it("should throw when clear is called after disposal", async () => {
145
- const $map = map<string, FlowState<number>>({
146
- key1: state(1),
147
- key2: state(2),
148
- });
149
- $map.dispose();
150
- await expect($map.clear()).rejects.toThrow(
151
- "[PicoFlow] Primitive is disposed",
152
- );
153
- });
154
-
155
- it("should dispose values when FlowMap is disposed", () => {
156
- const $map = map<string, FlowState<number>>();
157
- const $value1 = state(1);
158
- const $value2 = state(2);
159
- const $value3 = state(3);
160
-
161
- $map.add("key1", $value1);
162
- $map.add("key2", $value2);
163
- $map.add("key3", $value3);
164
-
165
- expect($value1.disposed).toBe(false);
166
- expect($value2.disposed).toBe(false);
167
- expect($value3.disposed).toBe(false);
168
-
169
- $map.dispose();
170
-
171
- expect($value1.disposed).toBe(true);
172
- expect($value2.disposed).toBe(true);
173
- expect($value3.disposed).toBe(true);
174
- });
175
-
176
- it("should dispose values with provided options when FlowMap is disposed", () => {
177
- const $map = map<string, FlowState<number>>();
178
- const $value1 = state(1);
179
- const $value2 = state(2);
180
-
181
- $map.add("key1", $value1);
182
- $map.add("key2", $value2);
183
-
184
- const $effect = effect((t) => {
185
- $value1.get(t);
186
- });
187
-
188
- expect($effect.disposed).toBe(false);
189
-
190
- $map.dispose({ self: true });
191
-
192
- expect($value1.disposed).toBe(true);
193
- expect($value2.disposed).toBe(true);
194
- expect($effect.disposed).toBe(false);
195
-
196
- $effect.dispose();
197
- });
198
-
199
- it("should handle non-disposable values gracefully", async () => {
200
- const $map = map<string, FlowState<number>>();
201
- await $map.add("key1", state(1));
202
- await $map.add("key2", state(2));
203
- await $map.add("key3", state(3));
204
-
205
- expect((await $map.pick()).size).toBe(3);
206
-
207
- expect(() => $map.dispose()).not.toThrow();
208
- });
209
- });
210
-
211
- describe("set", () => {
212
- it("should replace entire map when set is called", async () => {
213
- const $map = map<string, FlowState<number>>({
214
- key1: state(1),
215
- key2: state(2),
216
- });
217
- const $newValue1 = state(3);
218
- const $newValue2 = state(4);
219
- const newMap = new Map([
220
- ["key3", $newValue1],
221
- ["key4", $newValue2],
222
- ]);
223
-
224
- await $map.set(newMap);
225
- expect(Array.from((await $map.pick()).entries())).toEqual([
226
- ["key3", $newValue1],
227
- ["key4", $newValue2],
228
- ]);
229
- });
230
-
231
- it("should dispose values when set replaces map", async () => {
232
- const $oldValue1 = state(1);
233
- const $oldValue2 = state(2);
234
- const $map = map(
235
- new Map([
236
- ["key1", $oldValue1],
237
- ["key2", $oldValue2],
238
- ]),
239
- );
240
-
241
- expect($oldValue1.disposed).toBe(false);
242
- expect($oldValue2.disposed).toBe(false);
243
-
244
- await $map.set(
245
- new Map([
246
- ["key3", state(3)],
247
- ["key4", state(4)],
248
- ]),
249
- );
250
-
251
- expect($oldValue1.disposed).toBe(true);
252
- expect($oldValue2.disposed).toBe(true);
253
- });
254
-
255
- it("should dispose values with self option when set replaces map", async () => {
256
- const $oldValue = state(1);
257
- const $map = map(new Map([["key1", $oldValue]]));
258
-
259
- const $effect = effect((t) => {
260
- $oldValue.get(t);
261
- });
262
-
263
- expect($effect.disposed).toBe(false);
264
-
265
- await $map.set(new Map([["key2", state(2)]]));
266
-
267
- expect($oldValue.disposed).toBe(true);
268
- expect($effect.disposed).toBe(false);
269
-
270
- $effect.dispose();
271
- });
272
-
273
- it("should update $lastAction with set action when set is called", async () => {
274
- const $map = map<string, FlowState<number>>({
275
- key1: state(1),
276
- key2: state(2),
277
- });
278
- const $newValue1 = state(3);
279
- const $newValue2 = state(4);
280
- const newMap = new Map([
281
- ["key3", $newValue1],
282
- ["key4", $newValue2],
283
- ]);
284
-
285
- await $map.set(newMap);
286
- const action = await $map.$lastAction.pick();
287
- expect(action).toEqual({
288
- type: "set",
289
- map: newMap,
290
- });
291
- });
292
- });
293
-
294
- describe("add", () => {
295
- it("should add key-value pair to map", async () => {
296
- const $map = map<string, FlowState<number>>();
297
-
298
- await $map.add("key1", state(1));
299
- expect(await (await $map.pick()).get("key1")?.pick()).toBe(1);
300
- expect((await $map.pick()).size).toBe(1);
301
- });
302
-
303
- it("should add multiple keys successively", async () => {
304
- const $map = map<string, FlowState<number>>();
305
-
306
- await $map.add("key1", state(1));
307
- await $map.add("key2", state(2));
308
- await $map.add("key3", state(3));
309
-
310
- expect((await $map.pick()).size).toBe(3);
311
- expect(await (await $map.pick()).get("key1")?.pick()).toBe(1);
312
- expect(await (await $map.pick()).get("key2")?.pick()).toBe(2);
313
- expect(await (await $map.pick()).get("key3")?.pick()).toBe(3);
314
- });
315
-
316
- it("should throw when key already exists", async () => {
317
- const $map = map<string, FlowState<number>>();
318
- await $map.add("key1", state(1));
319
- await expect($map.add("key1", state(2))).rejects.toThrow(
320
- "[PicoFlow] Key already exists",
321
- );
322
- });
323
-
324
- it("should update $lastAction with add action when add is called", async () => {
325
- const $map = map<string, FlowState<number>>();
326
- const $value = state(1);
327
- await $map.add("key1", $value);
328
- const action = await $map.$lastAction.pick();
329
- expect(action).toEqual({
330
- type: "add",
331
- key: "key1",
332
- value: $value,
333
- });
334
- });
335
-
336
- it("should have FlowState value in $lastAction when add is called", async () => {
337
- const $map = map<string, FlowState<number>>();
338
- const $value = state(100);
339
- await $map.add("key1", $value);
340
- const action = await $map.$lastAction.pick();
341
- expect(action.type).toBe("add");
342
- if (action.type === "add") {
343
- expect(action.value).toBe($value);
344
- expect(await action.value.pick()).toBe(100);
345
- }
346
- });
347
-
348
- it("should trigger reactivity when add is called", async () => {
349
- const $map = map<string, FlowState<number>>();
350
- const effectFn = vi.fn();
351
- effect((t) => effectFn($map.get(t)));
352
-
353
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
354
-
355
- await $map.add("key1", state(1));
356
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
357
- });
358
- });
359
-
360
- describe("update", () => {
361
- it("should update existing key-value pair", async () => {
362
- const $map = map<string, FlowState<number>>();
363
- await $map.add("key1", state(1));
364
-
365
- const $newValue = state(2);
366
- await $map.update("key1", $newValue);
367
- expect(await (await $map.pick()).get("key1")?.pick()).toBe(2);
368
- });
369
-
370
- it("should update multiple keys successively", async () => {
371
- const $map = map<string, FlowState<number>>();
372
- await $map.add("key1", state(1));
373
- await $map.add("key2", state(2));
374
-
375
- await $map.update("key1", state(10));
376
- await $map.update("key2", state(20));
377
-
378
- expect(await (await $map.pick()).get("key1")?.pick()).toBe(10);
379
- expect(await (await $map.pick()).get("key2")?.pick()).toBe(20);
380
- });
381
-
382
- it("should throw when key does not exist", async () => {
383
- const $map = map<string, FlowState<number>>();
384
- await expect($map.update("key1", state(1))).rejects.toThrow(
385
- "[PicoFlow] Key does not exist",
386
- );
387
- });
388
-
389
- it("should update $lastAction with update action when update is called", async () => {
390
- const $map = map<string, FlowState<number>>();
391
- await $map.add("key1", state(1));
392
- const $newValue = state(2);
393
- await $map.update("key1", $newValue);
394
- const action = await $map.$lastAction.pick();
395
- expect(action).toEqual({
396
- type: "update",
397
- key: "key1",
398
- value: $newValue,
399
- });
400
- });
401
-
402
- it("should have FlowState value in $lastAction when update is called", async () => {
403
- const $map = map<string, FlowState<number>>();
404
- await $map.add("key1", state(1));
405
- const $newValue = state(200);
406
- await $map.update("key1", $newValue);
407
- const action = await $map.$lastAction.pick();
408
- expect(action.type).toBe("update");
409
- if (action.type === "update") {
410
- expect(action.value).toBe($newValue);
411
- expect(await action.value.pick()).toBe(200);
412
- }
413
- });
414
-
415
- it("should dispose old value when update is called", async () => {
416
- const $map = map<string, FlowState<number>>();
417
- const $oldValue = state(1);
418
- await $map.add("key1", $oldValue);
419
-
420
- const $newValue = state(2);
421
- await $map.update("key1", $newValue);
422
-
423
- expect($oldValue.disposed).toBe(true);
424
- expect($newValue.disposed).toBe(false);
425
- });
426
-
427
- it("should trigger reactivity when update is called", async () => {
428
- const $map = map<string, FlowState<number>>();
429
- await $map.add("key1", state(1));
430
- const effectFn = vi.fn();
431
- effect((t) => effectFn($map.get(t)));
432
-
433
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
434
-
435
- await $map.update("key1", state(2));
436
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
437
- });
438
- });
439
-
440
- describe("delete", () => {
441
- it("should delete key from map", async () => {
442
- const $map = map<string, FlowState<number>>();
443
- await $map.add("key1", state(1));
444
- await $map.add("key2", state(2));
445
-
446
- await $map.delete("key1");
447
- expect(await (await $map.pick()).get("key1")?.pick()).toBe(undefined);
448
- expect(await (await $map.pick()).get("key2")?.pick()).toBe(2);
449
- expect((await $map.pick()).size).toBe(1);
450
- });
451
-
452
- it("should delete multiple keys successively", async () => {
453
- const $map = map<string, FlowState<number>>();
454
- await $map.add("key1", state(1));
455
- await $map.add("key2", state(2));
456
- await $map.add("key3", state(3));
457
-
458
- await $map.delete("key1");
459
- await $map.delete("key2");
460
-
461
- expect((await $map.pick()).size).toBe(1);
462
- expect(await (await $map.pick()).get("key3")?.pick()).toBe(3);
463
- });
464
-
465
- it("should throw when key does not exist", async () => {
466
- const $map = map<string, FlowState<number>>();
467
- await expect($map.delete("key1")).rejects.toThrow(
468
- "[PicoFlow] Key does not exist",
469
- );
470
- });
471
-
472
- it("should update $lastAction with delete action when delete is called", async () => {
473
- const $map = map<string, FlowState<number>>();
474
- const $value = state(1);
475
- await $map.add("key1", $value);
476
- await $map.delete("key1");
477
- const action = await $map.$lastAction.pick();
478
- expect(action.type).toBe("delete");
479
- if (action.type === "delete") {
480
- expect(action.key).toBe("key1");
481
- expect(action.value).toBe($value);
482
- }
483
- });
484
-
485
- it("should have disposed FlowState value in $lastAction when delete is called", async () => {
486
- const $map = map<string, FlowState<number>>();
487
- const $value = state(300);
488
- await $map.add("key1", $value);
489
- await $map.delete("key1");
490
- const action = await $map.$lastAction.pick();
491
- expect(action.type).toBe("delete");
492
- if (action.type === "delete") {
493
- expect(action.value).toBe($value);
494
- expect(action.value.disposed).toBe(true);
495
- }
496
- });
497
-
498
- it("should dispose value with self option when delete is called", async () => {
499
- const $value = state(1);
500
- const $map = map(new Map([["key1", $value]]));
501
-
502
- const $effect = effect((t) => {
503
- $value.get(t);
504
- });
505
-
506
- expect($effect.disposed).toBe(false);
507
-
508
- await $map.delete("key1");
509
-
510
- expect($value.disposed).toBe(true);
511
- expect($effect.disposed).toBe(false);
512
-
513
- $effect.dispose();
514
- });
515
-
516
- it("should trigger reactivity when delete is called", async () => {
517
- const $map = map<string, FlowState<number>>();
518
- await $map.add("key1", state(1));
519
- const effectFn = vi.fn();
520
- effect((t) => effectFn($map.get(t)));
521
-
522
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
523
-
524
- await $map.delete("key1");
525
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
526
- });
527
- });
528
-
529
- describe("clear", () => {
530
- it("should remove all entries from map", async () => {
531
- const $map = map<string, FlowState<number>>({
532
- key1: state(1),
533
- key2: state(2),
534
- key3: state(3),
535
- });
536
- expect((await $map.pick()).size).toBe(3);
537
-
538
- await $map.clear();
539
- expect((await $map.pick()).size).toBe(0);
540
- });
541
-
542
- it("should dispose all values when clear is called", async () => {
543
- const $value1 = state(1);
544
- const $value2 = state(2);
545
- const $value3 = state(3);
546
- const $map = map(
547
- new Map([
548
- ["key1", $value1],
549
- ["key2", $value2],
550
- ["key3", $value3],
551
- ]),
552
- );
553
-
554
- expect($value1.disposed).toBe(false);
555
- expect($value2.disposed).toBe(false);
556
- expect($value3.disposed).toBe(false);
557
-
558
- await $map.clear();
559
-
560
- expect($value1.disposed).toBe(true);
561
- expect($value2.disposed).toBe(true);
562
- expect($value3.disposed).toBe(true);
563
- });
564
-
565
- it("should dispose values with self option when clear is called", async () => {
566
- const $value = state(1);
567
- const $map = map(
568
- new Map([
569
- ["key1", $value],
570
- ["key2", state(2)],
571
- ]),
572
- );
573
-
574
- const $effect = effect((t) => {
575
- $value.get(t);
576
- });
577
-
578
- expect($effect.disposed).toBe(false);
579
-
580
- await $map.clear();
581
-
582
- expect($value.disposed).toBe(true);
583
- expect($effect.disposed).toBe(false);
584
-
585
- $effect.dispose();
586
- });
587
-
588
- it("should update $lastAction with clear action when clear is called", async () => {
589
- const $map = map<string, FlowState<number>>({
590
- key1: state(1),
591
- key2: state(2),
592
- });
593
- await $map.clear();
594
- const action = await $map.$lastAction.pick();
595
- expect(action).toEqual({ type: "clear" });
596
- });
597
- });
598
-
599
- describe("$lastAction", () => {
600
- describe("set action", () => {
601
- it("should initialize $lastAction with set action on creation", async () => {
602
- const $value1 = state(1);
603
- const $value2 = state(2);
604
- const $map = map({
605
- key1: $value1,
606
- key2: $value2,
607
- });
608
- const action = await $map.$lastAction.pick();
609
- expect(action).toEqual({
610
- type: "set",
611
- map: expect.any(Map),
612
- });
613
- if (action.type === "set") {
614
- expect(action.map.get("key1")).toBe($value1);
615
- expect(action.map.get("key2")).toBe($value2);
616
- }
617
- });
618
-
619
- it("should update $lastAction with set action when set is called", async () => {
620
- const $map = map<string, FlowState<number>>({
621
- key1: state(1),
622
- });
623
- const $newValue = state(2);
624
- const newMap = new Map([["key2", $newValue]]);
625
- await $map.set(newMap);
626
- const action = await $map.$lastAction.pick();
627
- expect(action).toEqual({
628
- type: "set",
629
- map: newMap,
630
- });
631
- });
632
-
633
- it("should have correct structure for set action (type + map with FlowState)", async () => {
634
- const $value = state(1);
635
- const $map = map({ key1: $value });
636
- const action = await $map.$lastAction.pick();
637
- expect(action).toHaveProperty("type", "set");
638
- if (action.type === "set") {
639
- expect(action).toHaveProperty("map");
640
- expect(action.map).toBeInstanceOf(Map);
641
- expect(action.map.get("key1")).toBe($value);
642
- }
643
- });
644
- });
645
-
646
- describe("add action", () => {
647
- it("should update $lastAction with add action when add is called", async () => {
648
- const $map = map<string, FlowState<number>>();
649
- const $value = state(1);
650
- await $map.add("key1", $value);
651
- const action = await $map.$lastAction.pick();
652
- expect(action).toEqual({
653
- type: "add",
654
- key: "key1",
655
- value: $value,
656
- });
657
- });
658
-
659
- it("should have correct structure for add action (type + key + FlowState value)", async () => {
660
- const $map = map<string, FlowState<number>>();
661
- const $value = state(100);
662
- await $map.add("key1", $value);
663
- const action = await $map.$lastAction.pick();
664
- expect(action).toHaveProperty("type", "add");
665
- if (action.type === "add") {
666
- expect(action).toHaveProperty("key");
667
- expect(action).toHaveProperty("value");
668
- expect(action.key).toBe("key1");
669
- expect(action.value).toBe($value);
670
- expect(await action.value.pick()).toBe(100);
671
- }
672
- });
673
- });
674
-
675
- describe("update action", () => {
676
- it("should update $lastAction with update action when update is called", async () => {
677
- const $map = map<string, FlowState<number>>();
678
- await $map.add("key1", state(1));
679
- const $newValue = state(2);
680
- await $map.update("key1", $newValue);
681
- const action = await $map.$lastAction.pick();
682
- expect(action).toEqual({
683
- type: "update",
684
- key: "key1",
685
- value: $newValue,
686
- });
687
- });
688
-
689
- it("should have correct structure for update action (type + key + FlowState value)", async () => {
690
- const $map = map<string, FlowState<number>>();
691
- await $map.add("key1", state(1));
692
- const $newValue = state(200);
693
- await $map.update("key1", $newValue);
694
- const action = await $map.$lastAction.pick();
695
- expect(action).toHaveProperty("type", "update");
696
- if (action.type === "update") {
697
- expect(action).toHaveProperty("key");
698
- expect(action).toHaveProperty("value");
699
- expect(action.key).toBe("key1");
700
- expect(action.value).toBe($newValue);
701
- expect(await action.value.pick()).toBe(200);
702
- }
703
- });
704
- });
705
-
706
- describe("delete action", () => {
707
- it("should update $lastAction with delete action when delete is called", async () => {
708
- const $map = map<string, FlowState<number>>();
709
- const $value = state(1);
710
- await $map.add("key1", $value);
711
- await $map.delete("key1");
712
- const action = await $map.$lastAction.pick();
713
- expect(action).toEqual({
714
- type: "delete",
715
- key: "key1",
716
- value: $value,
717
- });
718
- });
719
-
720
- it("should have correct structure for delete action (type + key + disposed FlowState value)", async () => {
721
- const $map = map<string, FlowState<number>>();
722
- const $value = state(300);
723
- await $map.add("key1", $value);
724
- await $map.delete("key1");
725
- const action = await $map.$lastAction.pick();
726
- expect(action).toHaveProperty("type", "delete");
727
- if (action.type === "delete") {
728
- expect(action).toHaveProperty("key");
729
- expect(action).toHaveProperty("value");
730
- expect(action.key).toBe("key1");
731
- expect(action.value).toBe($value);
732
- expect(action.value.disposed).toBe(true);
733
- }
734
- });
735
- });
736
-
737
- describe("clear action", () => {
738
- it("should update $lastAction with clear action when clear is called", async () => {
739
- const $map = map<string, FlowState<number>>({
740
- key1: state(1),
741
- key2: state(2),
742
- });
743
- await $map.clear();
744
- const action = await $map.$lastAction.pick();
745
- expect(action).toEqual({
746
- type: "clear",
747
- });
748
- });
749
-
750
- it("should have correct structure for clear action (type only)", async () => {
751
- const $map = map<string, FlowState<number>>({
752
- key1: state(1),
753
- });
754
- await $map.clear();
755
- const action = await $map.$lastAction.pick();
756
- expect(action).toHaveProperty("type", "clear");
757
- if (action.type === "clear") {
758
- expect(action).not.toHaveProperty("key");
759
- expect(action).not.toHaveProperty("value");
760
- expect(action).not.toHaveProperty("map");
761
- }
762
- });
763
- });
764
- });
765
-
766
- describe("edge cases", () => {
767
- it("should handle multiple rapid operations", async () => {
768
- const $map = map<string, FlowState<number>>();
769
- await $map.add("key1", state(1));
770
- await $map.add("key2", state(2));
771
- await $map.add("key3", state(3));
772
- await $map.update("key1", state(10));
773
- await $map.delete("key2");
774
- await $map.add("key4", state(4));
775
- await $map.clear();
776
- await $map.add("key5", state(5));
777
-
778
- expect((await $map.pick()).size).toBe(1);
779
- expect(await (await $map.pick()).get("key5")?.pick()).toBe(5);
780
- });
781
-
782
- it("should handle empty map operations", async () => {
783
- const $map = map<string, FlowState<number>>();
784
- expect((await $map.pick()).size).toBe(0);
785
-
786
- await $map.add("key1", state(1));
787
- expect((await $map.pick()).size).toBe(1);
788
-
789
- await $map.delete("key1");
790
- expect((await $map.pick()).size).toBe(0);
791
- });
792
-
793
- it("should handle map with single entry", async () => {
794
- const $map = map<string, FlowState<number>>({
795
- key1: state(1),
796
- });
797
- expect((await $map.pick()).size).toBe(1);
798
-
799
- await $map.update("key1", state(2));
800
- expect(await (await $map.pick()).get("key1")?.pick()).toBe(2);
801
-
802
- await $map.delete("key1");
803
- expect((await $map.pick()).size).toBe(0);
804
- });
805
-
806
- it("should handle map with many entries", async () => {
807
- const $map = map<string, FlowState<number>>();
808
- for (let i = 0; i < 100; i++) {
809
- await $map.add(`key${i}`, state(i));
810
- }
811
- expect((await $map.pick()).size).toBe(100);
812
-
813
- for (let i = 0; i < 50; i++) {
814
- await $map.delete(`key${i}`);
815
- }
816
- expect((await $map.pick()).size).toBe(50);
817
- });
818
-
819
- it("should handle disposed values in map", async () => {
820
- const $value = state(1);
821
- const $map = map(new Map([["key1", $value]]));
822
-
823
- await $map.delete("key1");
824
-
825
- expect($value.disposed).toBe(true);
826
- expect((await $map.pick()).size).toBe(0);
827
- });
828
-
829
- it("should handle effects on FlowState values in map", async () => {
830
- const $value = state(1);
831
- const $map = map(new Map([["key1", $value]]));
832
- const effectFn = vi.fn();
833
-
834
- effect((t) => {
835
- const mapValue = $map.get(t).get("key1");
836
- if (mapValue) {
837
- effectFn(mapValue.get(t));
838
- }
839
- });
840
-
841
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
842
- expect(effectFn).toHaveBeenLastCalledWith(1);
843
-
844
- await $value.set(2);
845
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
846
- expect(effectFn).toHaveBeenLastCalledWith(2);
847
- });
848
- });
849
- });
850
-
851
- describe("integration", () => {
852
- beforeEach(() => {
853
- FlowGraph.clear();
854
- });
855
-
856
- describe("with effects", () => {
857
- describe("reactivity", () => {
858
- it("should call effect when initialized", async () => {
859
- const $map = map<string, FlowState<number>>({
860
- key1: state(1),
861
- key2: state(2),
862
- });
863
- const effectFn = vi.fn();
864
- effect((t) => effectFn($map.get(t)));
865
-
866
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
867
- expect(effectFn).toHaveBeenLastCalledWith(
868
- expect.objectContaining({
869
- size: 2,
870
- }),
871
- );
872
- });
873
-
874
- it("should call effect when updated with set", async () => {
875
- const $map = map<string, FlowState<number>>({
876
- key1: state(1),
877
- });
878
- const effectFn = vi.fn();
879
- effect((t) => effectFn($map.get(t)));
880
-
881
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
882
-
883
- const $newValue = state(2);
884
- await $map.set(new Map([["key2", $newValue]]));
885
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
886
- expect(effectFn).toHaveBeenLastCalledWith(
887
- expect.objectContaining({
888
- size: 1,
889
- }),
890
- );
891
- });
892
-
893
- it("should call effect when updated with add", async () => {
894
- const $map = map<string, FlowState<number>>();
895
- const effectFn = vi.fn();
896
- effect((t) => effectFn($map.get(t)));
897
-
898
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
899
- expect(effectFn).toHaveBeenLastCalledWith(new Map());
900
-
901
- const $key1Value = state(1);
902
- await $map.add("key1", $key1Value);
903
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
904
- expect(effectFn).toHaveBeenLastCalledWith(
905
- new Map([["key1", $key1Value]]),
906
- );
907
-
908
- const $key2Value = state(2);
909
- await $map.add("key2", $key2Value);
910
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(3));
911
- expect(effectFn).toHaveBeenLastCalledWith(
912
- new Map([
913
- ["key1", $key1Value],
914
- ["key2", $key2Value],
915
- ]),
916
- );
917
- });
918
-
919
- it("should call effect when updated with update", async () => {
920
- const $map = map<string, FlowState<number>>();
921
- await $map.add("key1", state(1));
922
- const effectFn = vi.fn();
923
- effect((t) => effectFn($map.get(t)));
924
-
925
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
926
-
927
- const $newValue = state(2);
928
- await $map.update("key1", $newValue);
929
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
930
- expect(effectFn).toHaveBeenLastCalledWith(
931
- new Map([["key1", $newValue]]),
932
- );
933
- });
934
-
935
- it("should call effect when updated with delete", async () => {
936
- const $map = map<string, FlowState<number>>();
937
- await $map.add("key1", state(1));
938
- await $map.add("key2", state(2));
939
- const effectFn = vi.fn();
940
- effect((t) => effectFn($map.get(t)));
941
-
942
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
943
-
944
- await $map.delete("key1");
945
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
946
- const mapAfterDelete = effectFn.mock.calls[1][0];
947
- expect(mapAfterDelete.size).toBe(1);
948
- expect(mapAfterDelete.has("key2")).toBe(true);
949
- });
950
-
951
- it("should call effect when updated with clear", async () => {
952
- const $map = map<string, FlowState<number>>({
953
- key1: state(1),
954
- key2: state(2),
955
- });
956
- const effectFn = vi.fn();
957
- effect((t) => effectFn($map.get(t)));
958
-
959
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
960
-
961
- await $map.clear();
962
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
963
- expect(effectFn).toHaveBeenLastCalledWith(new Map());
964
- });
965
-
966
- it("should call effect when FlowState values in map are updated", async () => {
967
- const $value = state(1);
968
- const $map = map(new Map([["key1", $value]]));
969
- const effectFn = vi.fn();
970
-
971
- effect((t) => {
972
- const mapValue = $map.get(t).get("key1");
973
- if (mapValue) {
974
- effectFn(mapValue.get(t));
975
- }
976
- });
977
-
978
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
979
- expect(effectFn).toHaveBeenLastCalledWith(1);
980
-
981
- await $value.set(2);
982
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
983
- expect(effectFn).toHaveBeenLastCalledWith(2);
984
- });
985
- });
986
-
987
- describe("$lastAction", () => {
988
- it("should call effect when $lastAction is updated with set action", async () => {
989
- const $map = map<string, FlowState<number>>({
990
- key1: state(1),
991
- });
992
- const effectFn = vi.fn();
993
- effect((t) => effectFn($map.$lastAction.get(t)));
994
-
995
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
996
-
997
- const $newValue = state(2);
998
- await $map.set(new Map([["key2", $newValue]]));
999
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
1000
- expect(effectFn).toHaveBeenLastCalledWith({
1001
- type: "set",
1002
- map: expect.any(Map),
1003
- });
1004
- });
1005
-
1006
- it("should call effect when $lastAction is updated with add action", async () => {
1007
- const $map = map<string, FlowState<number>>();
1008
- const effectFn = vi.fn();
1009
- effect((t) => effectFn($map.$lastAction.get(t)));
1010
-
1011
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
1012
-
1013
- const $value = state(1);
1014
- await $map.add("key1", $value);
1015
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
1016
- expect(effectFn).toHaveBeenLastCalledWith({
1017
- type: "add",
1018
- key: "key1",
1019
- value: $value,
1020
- });
1021
- });
1022
-
1023
- it("should call effect when $lastAction is updated with update action", async () => {
1024
- const $map = map<string, FlowState<number>>();
1025
- await $map.add("key1", state(1));
1026
- const effectFn = vi.fn();
1027
- effect((t) => effectFn($map.$lastAction.get(t)));
1028
-
1029
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
1030
-
1031
- const $newValue = state(2);
1032
- await $map.update("key1", $newValue);
1033
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
1034
- expect(effectFn).toHaveBeenLastCalledWith({
1035
- type: "update",
1036
- key: "key1",
1037
- value: $newValue,
1038
- });
1039
- });
1040
-
1041
- it("should call effect when $lastAction is updated with delete action", async () => {
1042
- const $map = map<string, FlowState<number>>();
1043
- const $value = state(1);
1044
- await $map.add("key1", $value);
1045
- const effectFn = vi.fn();
1046
- effect((t) => effectFn($map.$lastAction.get(t)));
1047
-
1048
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
1049
-
1050
- await $map.delete("key1");
1051
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
1052
- expect(effectFn).toHaveBeenLastCalledWith({
1053
- type: "delete",
1054
- key: "key1",
1055
- value: $value,
1056
- });
1057
- });
1058
-
1059
- it("should call effect when $lastAction is updated with clear action", async () => {
1060
- const $map = map<string, FlowState<number>>({
1061
- key1: state(1),
1062
- key2: state(2),
1063
- });
1064
- const effectFn = vi.fn();
1065
- effect((t) => effectFn($map.$lastAction.get(t)));
1066
-
1067
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
1068
-
1069
- await $map.clear();
1070
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
1071
- expect(effectFn).toHaveBeenLastCalledWith({ type: "clear" });
1072
- });
1073
-
1074
- it("should call effect when FlowState value in $lastAction is updated", async () => {
1075
- const $map = map<string, FlowState<number>>();
1076
- const $value = state(1);
1077
- await $map.add("key1", $value);
1078
- const effectFn = vi.fn();
1079
-
1080
- effect((t) => {
1081
- const action = $map.$lastAction.get(t);
1082
- if (action.type === "add") {
1083
- effectFn(action.value.get(t));
1084
- }
1085
- });
1086
-
1087
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
1088
- expect(effectFn).toHaveBeenLastCalledWith(1);
1089
-
1090
- await $value.set(2);
1091
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
1092
- expect(effectFn).toHaveBeenLastCalledWith(2);
1093
- });
1094
- });
1095
- });
1096
- });
1097
- });