@ersbeth/picoflow 1.1.2 → 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 +856 -1530
  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 -57
  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 -148
  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,1365 +0,0 @@
1
- import { describe, expect, it, vi } from "vitest";
2
- import { array, effect, type FlowState, state } from "#package";
3
-
4
- describe("FlowArray", () => {
5
- describe("unit", () => {
6
- describe("initialization", () => {
7
- it("should initialize with provided FlowState values", async () => {
8
- const $array = array([state(1), state(2), state(3)]);
9
-
10
- expect(
11
- await Promise.all((await $array.pick()).map((state) => state.pick())),
12
- ).toEqual([1, 2, 3]);
13
- });
14
-
15
- it("should initialize with empty array when no value provided", async () => {
16
- const $array = array<FlowState<number>>();
17
-
18
- expect(await $array.pick()).toEqual([]);
19
- });
20
- });
21
-
22
- describe("disposal", () => {
23
- it("should have disposed property set to false initially and true after disposal", () => {
24
- const $array = array([state(1), state(2), state(3)]);
25
- expect($array.disposed).toBe(false);
26
- $array.dispose();
27
- expect($array.disposed).toBe(true);
28
- });
29
-
30
- it("should throw error when disposed twice", () => {
31
- const $array = array([state(1), state(2), state(3)]);
32
- $array.dispose();
33
- expect(() => $array.dispose()).toThrow(
34
- "[PicoFlow] Primitive is disposed",
35
- );
36
- });
37
-
38
- it("should throw when pick is called after disposal", async () => {
39
- const $array = array([state(1), state(2), state(3)]);
40
- $array.dispose();
41
- await expect($array.pick()).rejects.toThrow(
42
- "[PicoFlow] Primitive is disposed",
43
- );
44
- });
45
-
46
- it("should throw when set is called after disposal", async () => {
47
- const $array = array([state(1), state(2), state(3)]);
48
- $array.dispose();
49
- await expect($array.set([state(1)])).rejects.toThrow(
50
- "[PicoFlow] Primitive is disposed",
51
- );
52
- });
53
-
54
- it("should throw when setItem is called after disposal", async () => {
55
- const $array = array([state(1), state(2), state(3)]);
56
- $array.dispose();
57
- await expect($array.update(0, state(3))).rejects.toThrow(
58
- "[PicoFlow] Primitive is disposed",
59
- );
60
- });
61
-
62
- it("should throw when push is called after disposal", async () => {
63
- const $array = array([state(1), state(2), state(3)]);
64
- $array.dispose();
65
- await expect($array.push(state(3))).rejects.toThrow(
66
- "[PicoFlow] Primitive is disposed",
67
- );
68
- });
69
-
70
- it("should throw when pop is called after disposal", async () => {
71
- const $array = array([state(1), state(2), state(3)]);
72
- $array.dispose();
73
- await expect($array.pop()).rejects.toThrow(
74
- "[PicoFlow] Primitive is disposed",
75
- );
76
- });
77
-
78
- it("should throw when unshift is called after disposal", async () => {
79
- const $array = array([state(1), state(2), state(3)]);
80
- $array.dispose();
81
- await expect($array.unshift(state(3))).rejects.toThrow(
82
- "[PicoFlow] Primitive is disposed",
83
- );
84
- });
85
-
86
- it("should throw when shift is called after disposal", async () => {
87
- const $array = array([state(1), state(2), state(3)]);
88
- $array.dispose();
89
- await expect($array.shift()).rejects.toThrow(
90
- "[PicoFlow] Primitive is disposed",
91
- );
92
- });
93
-
94
- it("should throw when splice is called after disposal", async () => {
95
- const $array = array<FlowState<number>>([
96
- state(0),
97
- state(1),
98
- state(2),
99
- state(3),
100
- state(4),
101
- ]);
102
- $array.dispose();
103
- await expect($array.splice(1, 2)).rejects.toThrow(
104
- "[PicoFlow] Primitive is disposed",
105
- );
106
- });
107
-
108
- it("should throw when clear is called after disposal", async () => {
109
- const $array = array<FlowState<number>>([
110
- state(0),
111
- state(1),
112
- state(2),
113
- state(3),
114
- state(4),
115
- ]);
116
- $array.dispose();
117
- await expect($array.clear()).rejects.toThrow(
118
- "[PicoFlow] Primitive is disposed",
119
- );
120
- });
121
-
122
- it("should dispose items when FlowArray is disposed", () => {
123
- const $item1 = state(1);
124
- const $item2 = state(2);
125
- const $item3 = state(3);
126
- const $array = array([$item1, $item2, $item3]);
127
-
128
- expect($item1.disposed).toBe(false);
129
- expect($item2.disposed).toBe(false);
130
- expect($item3.disposed).toBe(false);
131
-
132
- $array.dispose();
133
-
134
- expect($item1.disposed).toBe(true);
135
- expect($item2.disposed).toBe(true);
136
- expect($item3.disposed).toBe(true);
137
- });
138
-
139
- it("should dispose items with provided options when FlowArray is disposed", () => {
140
- const $item1 = state(1);
141
- const $item2 = state(2);
142
- const $array = array([$item1, $item2]);
143
-
144
- const $effect = effect((t) => {
145
- $item1.get(t);
146
- });
147
-
148
- expect($effect.disposed).toBe(false);
149
-
150
- $array.dispose({ self: true });
151
-
152
- expect($item1.disposed).toBe(true);
153
- expect($item2.disposed).toBe(true);
154
- expect($effect.disposed).toBe(false);
155
- });
156
- });
157
-
158
- describe("length", () => {
159
- it("should return correct length", () => {
160
- const $array = array([state(1), state(2), state(3)]);
161
- expect($array.length).toBe(3);
162
- });
163
-
164
- it("should return zero for empty array", () => {
165
- const $array = array<FlowState<number>>([]);
166
- expect($array.length).toBe(0);
167
- });
168
-
169
- it("should throw when length is accessed after disposal", () => {
170
- const $array = array([state(1), state(2), state(3)]);
171
- $array.dispose();
172
- expect(() => $array.length).toThrow("[PicoFlow] Primitive is disposed");
173
- });
174
-
175
- it("should update length when array is modified", async () => {
176
- const $array = array<FlowState<number>>([]);
177
- expect($array.length).toBe(0);
178
-
179
- $array.push(state(1));
180
- expect($array.length).toBe(1);
181
-
182
- $array.push(state(2));
183
- expect($array.length).toBe(2);
184
-
185
- $array.pop();
186
- expect($array.length).toBe(1);
187
-
188
- $array.unshift(state(0));
189
- expect($array.length).toBe(2);
190
-
191
- $array.shift();
192
- expect($array.length).toBe(1);
193
-
194
- $array.clear();
195
- expect($array.length).toBe(0);
196
- });
197
- });
198
-
199
- describe("set", () => {
200
- it("should update array when set is called with FlowStates", async () => {
201
- const $array = array([state(0), state(1), state(2)]);
202
- expect(
203
- await Promise.all((await $array.pick()).map((state) => state.pick())),
204
- ).toEqual([0, 1, 2]);
205
-
206
- await $array.set([state(1), state(2), state(3)]);
207
- expect(
208
- await Promise.all((await $array.pick()).map((state) => state.pick())),
209
- ).toEqual([1, 2, 3]);
210
- });
211
-
212
- it("should dispose items when set replaces array", () => {
213
- const $oldItem1 = state(1);
214
- const $oldItem2 = state(2);
215
- const $array = array([$oldItem1, $oldItem2]);
216
-
217
- expect($oldItem1.disposed).toBe(false);
218
- expect($oldItem2.disposed).toBe(false);
219
-
220
- $array.set([state(3), state(4)]);
221
-
222
- expect($oldItem1.disposed).toBe(true);
223
- expect($oldItem2.disposed).toBe(true);
224
- });
225
-
226
- it("should dispose items with self option when set replaces array", async () => {
227
- const $oldItem = state(1);
228
- const $array = array([$oldItem]);
229
-
230
- const $effect = effect((t) => {
231
- $array.get(t)[0].get(t);
232
- });
233
-
234
- expect($effect.disposed).toBe(false);
235
- expect($oldItem.disposed).toBe(false);
236
-
237
- await $array.set([state(2)]);
238
-
239
- expect($oldItem.disposed).toBe(true);
240
- expect($effect.disposed).toBe(false);
241
- });
242
- });
243
-
244
- describe("update", () => {
245
- it("should update item at specific index", async () => {
246
- const $array = array([state(0), state(1), state(2)]);
247
- expect(
248
- await Promise.all((await $array.pick()).map((state) => state.pick())),
249
- ).toEqual([0, 1, 2]);
250
-
251
- $array.update(0, state(1));
252
- expect(
253
- await Promise.all((await $array.pick()).map((state) => state.pick())),
254
- ).toEqual([1, 1, 2]);
255
-
256
- $array.update(1, state(2));
257
- expect(
258
- await Promise.all((await $array.pick()).map((state) => state.pick())),
259
- ).toEqual([1, 2, 2]);
260
-
261
- $array.update(2, state(3));
262
- expect(
263
- await Promise.all((await $array.pick()).map((state) => state.pick())),
264
- ).toEqual([1, 2, 3]);
265
- });
266
-
267
- it("should throw when update is called with negative index", async () => {
268
- const $array = array([state(1), state(2), state(3)]);
269
- await expect($array.update(-1, state(0))).rejects.toThrow(
270
- "[PicoFlow] Index out of bounds",
271
- );
272
- });
273
-
274
- it("should throw when update is called with index >= length", async () => {
275
- const $array = array([state(1), state(2), state(3)]);
276
- await expect($array.update(3, state(0))).rejects.toThrow(
277
- "[PicoFlow] Index out of bounds",
278
- );
279
- await expect($array.update(10, state(0))).rejects.toThrow(
280
- "[PicoFlow] Index out of bounds",
281
- );
282
- });
283
-
284
- it("should handle boundary indices correctly", async () => {
285
- const $array = array([state(0), state(1), state(2)]);
286
- $array.update(0, state(10));
287
- expect(
288
- await Promise.all((await $array.pick()).map((state) => state.pick())),
289
- ).toEqual([10, 1, 2]);
290
-
291
- $array.update(2, state(20));
292
- expect(
293
- await Promise.all((await $array.pick()).map((state) => state.pick())),
294
- ).toEqual([10, 1, 20]);
295
- });
296
- });
297
-
298
- describe("push", () => {
299
- it("should append FlowState to end of array", async () => {
300
- const $array = array<FlowState<number>>([]);
301
- expect(await $array.pick()).toEqual([]);
302
-
303
- $array.push(state(0));
304
- expect(
305
- await Promise.all((await $array.pick()).map((state) => state.pick())),
306
- ).toEqual([0]);
307
-
308
- $array.push(state(1));
309
- expect(
310
- await Promise.all((await $array.pick()).map((state) => state.pick())),
311
- ).toEqual([0, 1]);
312
-
313
- $array.push(state(2));
314
- expect(
315
- await Promise.all((await $array.pick()).map((state) => state.pick())),
316
- ).toEqual([0, 1, 2]);
317
- });
318
-
319
- it("should handle operations on empty array", () => {
320
- const $array = array<FlowState<number>>([]);
321
- expect($array.length).toBe(0);
322
- $array.push(state(1));
323
- expect($array.length).toBe(1);
324
- });
325
- });
326
-
327
- describe("pop", () => {
328
- it("should remove last FlowState from array", async () => {
329
- const $array = array([state(0), state(1), state(2)]);
330
- expect(
331
- await Promise.all((await $array.pick()).map((state) => state.pick())),
332
- ).toEqual([0, 1, 2]);
333
-
334
- $array.pop();
335
- expect(
336
- await Promise.all((await $array.pick()).map((state) => state.pick())),
337
- ).toEqual([0, 1]);
338
-
339
- $array.pop();
340
- expect(
341
- await Promise.all((await $array.pick()).map((state) => state.pick())),
342
- ).toEqual([0]);
343
-
344
- $array.pop();
345
- expect(
346
- await Promise.all((await $array.pick()).map((state) => state.pick())),
347
- ).toEqual([]);
348
- });
349
-
350
- it("should dispose item when pop removes it", () => {
351
- const $item = state(1);
352
- const $array = array([$item]);
353
-
354
- expect($item.disposed).toBe(false);
355
-
356
- $array.pop();
357
-
358
- expect($item.disposed).toBe(true);
359
- });
360
-
361
- it("should dispose item with self option when pop removes it", async () => {
362
- const $item = state(1);
363
- const $array = array([$item]);
364
-
365
- const $effect = effect((t) => {
366
- const item = $array.get(t)[0];
367
- if (item) {
368
- item.get(t);
369
- }
370
- });
371
-
372
- expect($effect.disposed).toBe(false);
373
- expect($item.disposed).toBe(false);
374
-
375
- await $array.pop();
376
-
377
- expect($item.disposed).toBe(true);
378
- expect($effect.disposed).toBe(false);
379
- });
380
-
381
- it("should handle operations on empty array", () => {
382
- const $array = array<FlowState<number>>([]);
383
- expect($array.length).toBe(0);
384
- $array.pop();
385
- expect($array.length).toBe(0);
386
- });
387
- });
388
-
389
- describe("unshift", () => {
390
- it("should insert FlowState at beginning of array", async () => {
391
- const $array = array<FlowState<number>>([]);
392
- expect(await $array.pick()).toEqual([]);
393
-
394
- $array.unshift(state(0));
395
- expect(
396
- await Promise.all((await $array.pick()).map((state) => state.pick())),
397
- ).toEqual([0]);
398
-
399
- $array.unshift(state(1));
400
- expect(
401
- await Promise.all((await $array.pick()).map((state) => state.pick())),
402
- ).toEqual([1, 0]);
403
-
404
- $array.unshift(state(2));
405
- expect(
406
- await Promise.all((await $array.pick()).map((state) => state.pick())),
407
- ).toEqual([2, 1, 0]);
408
- });
409
- });
410
-
411
- describe("shift", () => {
412
- it("should remove first FlowState from array", async () => {
413
- const $array = array([state(0), state(1), state(2)]);
414
- expect(
415
- await Promise.all((await $array.pick()).map((state) => state.pick())),
416
- ).toEqual([0, 1, 2]);
417
-
418
- $array.shift();
419
- expect(
420
- await Promise.all((await $array.pick()).map((state) => state.pick())),
421
- ).toEqual([1, 2]);
422
-
423
- $array.shift();
424
- expect(
425
- await Promise.all((await $array.pick()).map((state) => state.pick())),
426
- ).toEqual([2]);
427
-
428
- $array.shift();
429
- expect(
430
- await Promise.all((await $array.pick()).map((state) => state.pick())),
431
- ).toEqual([]);
432
- });
433
-
434
- it("should dispose item when shift removes it", () => {
435
- const $item = state(1);
436
- const $array = array([$item, state(2)]);
437
-
438
- expect($item.disposed).toBe(false);
439
-
440
- $array.shift();
441
-
442
- expect($item.disposed).toBe(true);
443
- });
444
-
445
- it("should dispose item with self option when shift removes it", async () => {
446
- const $item = state(1);
447
- const $array = array([$item, state(2)]);
448
-
449
- const $effect = effect((t) => {
450
- $item.get(t);
451
- });
452
-
453
- expect($effect.disposed).toBe(false);
454
-
455
- await $array.shift();
456
-
457
- expect($item.disposed).toBe(true);
458
- expect($effect.disposed).toBe(false);
459
- });
460
-
461
- it("should handle operations on empty array", () => {
462
- const $array = array<FlowState<number>>([]);
463
- expect($array.length).toBe(0);
464
- $array.shift();
465
- expect($array.length).toBe(0);
466
- });
467
- });
468
-
469
- describe("splice", () => {
470
- it("should remove FlowStates from array", async () => {
471
- const $array = array<FlowState<number>>([
472
- state(0),
473
- state(1),
474
- state(2),
475
- state(3),
476
- state(4),
477
- ]);
478
- expect(
479
- await Promise.all((await $array.pick()).map((state) => state.pick())),
480
- ).toEqual([0, 1, 2, 3, 4]);
481
-
482
- $array.splice(1, 2);
483
- expect(
484
- await Promise.all((await $array.pick()).map((state) => state.pick())),
485
- ).toEqual([0, 3, 4]);
486
- });
487
-
488
- it("should insert FlowStates into array", async () => {
489
- const $array = array<FlowState<number>>([
490
- state(0),
491
- state(1),
492
- state(2),
493
- state(3),
494
- state(4),
495
- ]);
496
- $array.splice(1, 0, state(10), state(11));
497
- expect(
498
- await Promise.all((await $array.pick()).map((state) => state.pick())),
499
- ).toEqual([0, 10, 11, 1, 2, 3, 4]);
500
- });
501
-
502
- it("should replace FlowStates in array", async () => {
503
- const $array = array<FlowState<number>>([
504
- state(0),
505
- state(1),
506
- state(2),
507
- state(3),
508
- state(4),
509
- ]);
510
- $array.splice(1, 2, state(10), state(11));
511
- expect(
512
- await Promise.all((await $array.pick()).map((state) => state.pick())),
513
- ).toEqual([0, 10, 11, 3, 4]);
514
- });
515
-
516
- it("should dispose items when splice removes them", () => {
517
- const $item1 = state(1);
518
- const $item2 = state(2);
519
- const $array = array([state(0), $item1, $item2, state(3)]);
520
-
521
- expect($item1.disposed).toBe(false);
522
- expect($item2.disposed).toBe(false);
523
-
524
- $array.splice(1, 2);
525
-
526
- expect($item1.disposed).toBe(true);
527
- expect($item2.disposed).toBe(true);
528
- });
529
-
530
- it("should dispose items with self option when splice removes them", async () => {
531
- const $item = state(1);
532
- const $array = array([state(0), $item, state(2)]);
533
-
534
- const $effect = effect((t) => {
535
- $item.get(t);
536
- });
537
-
538
- expect($effect.disposed).toBe(false);
539
-
540
- await $array.splice(1, 1);
541
-
542
- expect($item.disposed).toBe(true);
543
- expect($effect.disposed).toBe(false);
544
- });
545
- });
546
-
547
- describe("clear", () => {
548
- it("should remove all FlowStates from array", async () => {
549
- const $array = array<FlowState<number>>([
550
- state(0),
551
- state(1),
552
- state(2),
553
- state(3),
554
- state(4),
555
- ]);
556
- expect(
557
- await Promise.all((await $array.pick()).map((state) => state.pick())),
558
- ).toEqual([0, 1, 2, 3, 4]);
559
-
560
- $array.clear();
561
- expect(
562
- await Promise.all((await $array.pick()).map((state) => state.pick())),
563
- ).toEqual([]);
564
- });
565
-
566
- it("should dispose all items when clear is called", () => {
567
- const $item1 = state(1);
568
- const $item2 = state(2);
569
- const $item3 = state(3);
570
- const $array = array([$item1, $item2, $item3]);
571
-
572
- expect($item1.disposed).toBe(false);
573
- expect($item2.disposed).toBe(false);
574
- expect($item3.disposed).toBe(false);
575
-
576
- $array.clear();
577
-
578
- expect($item1.disposed).toBe(true);
579
- expect($item2.disposed).toBe(true);
580
- expect($item3.disposed).toBe(true);
581
- });
582
-
583
- it("should dispose items with self option when clear is called", async () => {
584
- const $item = state(1);
585
- const $array = array([$item, state(2)]);
586
-
587
- const $effect = effect((t) => {
588
- $item.get(t);
589
- });
590
-
591
- expect($effect.disposed).toBe(false);
592
-
593
- await $array.clear();
594
-
595
- expect($item.disposed).toBe(true);
596
- expect($effect.disposed).toBe(false);
597
- });
598
- });
599
-
600
- describe("$lastAction", () => {
601
- describe("set action", () => {
602
- it("should initialize $lastAction with set action on creation", async () => {
603
- const $array = array([state(1), state(2), state(3)]);
604
- const action = await $array.$lastAction.pick();
605
- expect(action.type).toBe("set");
606
- if (action.type === "set") {
607
- expect(action.items).toHaveLength(3);
608
- expect(action.items[0]).toBeInstanceOf(Object);
609
- expect(action.items[1]).toBeInstanceOf(Object);
610
- expect(action.items[2]).toBeInstanceOf(Object);
611
- }
612
- });
613
-
614
- it("should update $lastAction with set action when set is called", async () => {
615
- const $array = array([state(0), state(1), state(2)]);
616
- await $array.set([state(1), state(2), state(3)]);
617
- const action = await $array.$lastAction.pick();
618
- expect(action.type).toBe("set");
619
- if (action.type === "set") {
620
- expect(action.items).toHaveLength(3);
621
- }
622
- });
623
-
624
- it("should have correct structure for set action (items array)", async () => {
625
- const $array = array([state(1), state(2), state(3)]);
626
- const action = await $array.$lastAction.pick();
627
- expect(action).toHaveProperty("type", "set");
628
- if (action.type === "set") {
629
- expect(action).toHaveProperty("items");
630
- expect(Array.isArray(action.items)).toBe(true);
631
- expect(action.items).toHaveLength(3);
632
- }
633
- });
634
- });
635
-
636
- describe("update action", () => {
637
- it("should update $lastAction with setItem action when setItem is called", async () => {
638
- const $array = array([state(0), state(1), state(2)]);
639
- const $newItem = state(10);
640
- $array.update(1, $newItem);
641
- const action = await $array.$lastAction.pick();
642
- expect(action.type).toBe("update");
643
- if (action.type === "update") {
644
- expect(action.index).toBe(1);
645
- expect(action.item).toBe($newItem);
646
- }
647
- });
648
-
649
- it("should have correct structure for update action (index and item)", async () => {
650
- const $array = array([state(1), state(2), state(3)]);
651
- const $newItem = state(10);
652
- $array.update(0, $newItem);
653
- const action = await $array.$lastAction.pick();
654
- expect(action).toHaveProperty("type", "update");
655
- if (action.type === "update") {
656
- expect(action).toHaveProperty("index");
657
- expect(action).toHaveProperty("item");
658
- expect(action.index).toBe(0);
659
- expect(action.item).toBe($newItem);
660
- }
661
- });
662
- });
663
-
664
- describe("push action", () => {
665
- it("should update $lastAction with push action when push is called", async () => {
666
- const $array = array<FlowState<number>>([]);
667
- const $newItem = state(42);
668
- $array.push($newItem);
669
- const action = await $array.$lastAction.pick();
670
- expect(action.type).toBe("push");
671
- if (action.type === "push") {
672
- expect(action.item).toBe($newItem);
673
- }
674
- });
675
-
676
- it("should have correct structure for push action (item)", async () => {
677
- const $array = array<FlowState<number>>([]);
678
- const $newItem = state(100);
679
- $array.push($newItem);
680
- const action = await $array.$lastAction.pick();
681
- expect(action).toHaveProperty("type", "push");
682
- if (action.type === "push") {
683
- expect(action).toHaveProperty("item");
684
- expect(action.item).toBe($newItem);
685
- }
686
- });
687
- });
688
-
689
- describe("pop action", () => {
690
- it("should update $lastAction with pop action when pop is called", async () => {
691
- const $array = array([state(1), state(2), state(3)]);
692
- $array.pop();
693
- const action = await $array.$lastAction.pick();
694
- expect(action).toEqual({
695
- type: "pop",
696
- });
697
- });
698
-
699
- it("should have correct structure for pop action (no additional fields)", async () => {
700
- const $array = array([state(1), state(2), state(3)]);
701
- $array.pop();
702
- const action = await $array.$lastAction.pick();
703
- expect(action).toHaveProperty("type", "pop");
704
- if (action.type === "pop") {
705
- expect(action).not.toHaveProperty("item");
706
- expect(action).not.toHaveProperty("index");
707
- expect(action).not.toHaveProperty("items");
708
- }
709
- });
710
- });
711
-
712
- describe("unshift action", () => {
713
- it("should update $lastAction with unshift action when unshift is called", async () => {
714
- const $array = array<FlowState<number>>([]);
715
- const $newItem = state(42);
716
- $array.unshift($newItem);
717
- const action = await $array.$lastAction.pick();
718
- expect(action.type).toBe("unshift");
719
- if (action.type === "unshift") {
720
- expect(action.item).toBe($newItem);
721
- }
722
- });
723
-
724
- it("should have correct structure for unshift action (item)", async () => {
725
- const $array = array<FlowState<number>>([]);
726
- const $newItem = state(200);
727
- $array.unshift($newItem);
728
- const action = await $array.$lastAction.pick();
729
- expect(action).toHaveProperty("type", "unshift");
730
- if (action.type === "unshift") {
731
- expect(action).toHaveProperty("item");
732
- expect(action.item).toBe($newItem);
733
- }
734
- });
735
- });
736
-
737
- describe("shift action", () => {
738
- it("should update $lastAction with shift action when shift is called", async () => {
739
- const $array = array([state(1), state(2), state(3)]);
740
- $array.shift();
741
- const action = await $array.$lastAction.pick();
742
- expect(action).toEqual({
743
- type: "shift",
744
- });
745
- });
746
-
747
- it("should have correct structure for shift action (no additional fields)", async () => {
748
- const $array = array([state(1), state(2), state(3)]);
749
- $array.shift();
750
- const action = await $array.$lastAction.pick();
751
- expect(action).toHaveProperty("type", "shift");
752
- if (action.type === "shift") {
753
- expect(action).not.toHaveProperty("item");
754
- expect(action).not.toHaveProperty("index");
755
- expect(action).not.toHaveProperty("items");
756
- }
757
- });
758
- });
759
-
760
- describe("splice action", () => {
761
- it("should update $lastAction with splice action when splice is called", async () => {
762
- const $array = array<FlowState<number>>([
763
- state(0),
764
- state(1),
765
- state(2),
766
- state(3),
767
- state(4),
768
- ]);
769
- const $newItem1 = state(10);
770
- const $newItem2 = state(11);
771
- $array.splice(1, 2, $newItem1, $newItem2);
772
- const action = await $array.$lastAction.pick();
773
- expect(action.type).toBe("splice");
774
- if (action.type === "splice") {
775
- expect(action.start).toBe(1);
776
- expect(action.deleteCount).toBe(2);
777
- expect(action.items).toHaveLength(2);
778
- expect(action.items[0]).toBe($newItem1);
779
- expect(action.items[1]).toBe($newItem2);
780
- }
781
- });
782
-
783
- it("should have correct structure for splice action (start, deleteCount, items)", async () => {
784
- const $array = array<FlowState<number>>([
785
- state(0),
786
- state(1),
787
- state(2),
788
- ]);
789
- const $newItem = state(100);
790
- $array.splice(1, 1, $newItem);
791
- const action = await $array.$lastAction.pick();
792
- expect(action).toHaveProperty("type", "splice");
793
- if (action.type === "splice") {
794
- expect(action).toHaveProperty("start");
795
- expect(action).toHaveProperty("deleteCount");
796
- expect(action).toHaveProperty("items");
797
- expect(action.start).toBe(1);
798
- expect(action.deleteCount).toBe(1);
799
- expect(Array.isArray(action.items)).toBe(true);
800
- expect(action.items).toHaveLength(1);
801
- expect(action.items[0]).toBe($newItem);
802
- }
803
- });
804
- });
805
-
806
- describe("clear action", () => {
807
- it("should update $lastAction with clear action when clear is called", async () => {
808
- const $array = array<FlowState<number>>([
809
- state(0),
810
- state(1),
811
- state(2),
812
- state(3),
813
- state(4),
814
- ]);
815
- $array.clear();
816
- const action = await $array.$lastAction.pick();
817
- expect(action).toEqual({
818
- type: "clear",
819
- });
820
- });
821
-
822
- it("should have correct structure for clear action (no additional fields)", async () => {
823
- const $array = array<FlowState<number>>([
824
- state(1),
825
- state(2),
826
- state(3),
827
- ]);
828
- $array.clear();
829
- const action = await $array.$lastAction.pick();
830
- expect(action).toHaveProperty("type", "clear");
831
- if (action.type === "clear") {
832
- expect(action).not.toHaveProperty("item");
833
- expect(action).not.toHaveProperty("index");
834
- expect(action).not.toHaveProperty("items");
835
- }
836
- });
837
- });
838
- });
839
-
840
- describe("edge cases", () => {
841
- it("should handle multiple rapid operations", async () => {
842
- const $array = array<FlowState<number>>([]);
843
- $array.push(state(1));
844
- $array.push(state(2));
845
- $array.push(state(3));
846
- $array.pop();
847
- $array.shift();
848
- $array.unshift(state(0));
849
- expect(
850
- await Promise.all((await $array.pick()).map((state) => state.pick())),
851
- ).toEqual([0, 2]);
852
- });
853
-
854
- it("should handle boundary indices correctly", async () => {
855
- const $array = array([state(0), state(1), state(2)]);
856
- $array.update(0, state(10));
857
- expect(
858
- await Promise.all((await $array.pick()).map((state) => state.pick())),
859
- ).toEqual([10, 1, 2]);
860
-
861
- $array.update(2, state(20));
862
- expect(
863
- await Promise.all((await $array.pick()).map((state) => state.pick())),
864
- ).toEqual([10, 1, 20]);
865
- });
866
- });
867
- });
868
-
869
- describe("integration", () => {
870
- describe("with effects", () => {
871
- describe("reactivity", () => {
872
- it("should call effect when initialized", async () => {
873
- const $array = array([state(1), state(2), state(3)]);
874
- const effectFn = vi.fn();
875
- effect(async (t) =>
876
- effectFn(
877
- await Promise.all(
878
- (await $array.get(t)).map((state) => state.get(t)),
879
- ),
880
- ),
881
- );
882
-
883
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
884
- expect(effectFn).toHaveBeenLastCalledWith([1, 2, 3]);
885
- });
886
-
887
- it("should call effect when updated with set", async () => {
888
- const $array = array<FlowState<number>>([
889
- state(0),
890
- state(1),
891
- state(2),
892
- ]);
893
- const effectFn = vi.fn();
894
- effect(async (t) =>
895
- effectFn(
896
- await Promise.all(
897
- (await $array.get(t)).map((state) => state.get(t)),
898
- ),
899
- ),
900
- );
901
-
902
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
903
- expect(effectFn).toHaveBeenLastCalledWith([0, 1, 2]);
904
-
905
- await $array.set([state(1), state(2), state(3)]);
906
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
907
- expect(effectFn).toHaveBeenLastCalledWith([1, 2, 3]);
908
- });
909
-
910
- it("should call effect when updated with push/pop", async () => {
911
- const $array = array<FlowState<number>>();
912
- const effectFn = vi.fn();
913
- effect(async (t) =>
914
- effectFn(
915
- await Promise.all(
916
- (await $array.get(t)).map((state) => state.get(t)),
917
- ),
918
- ),
919
- );
920
-
921
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
922
- expect(effectFn).toHaveBeenLastCalledWith([]);
923
-
924
- $array.push(state(0));
925
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
926
- expect(effectFn).toHaveBeenLastCalledWith([0]);
927
-
928
- $array.push(state(1));
929
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(3));
930
- expect(effectFn).toHaveBeenLastCalledWith([0, 1]);
931
-
932
- $array.push(state(2));
933
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(4));
934
- expect(effectFn).toHaveBeenLastCalledWith([0, 1, 2]);
935
-
936
- $array.pop();
937
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(5));
938
- expect(effectFn).toHaveBeenLastCalledWith([0, 1]);
939
-
940
- $array.pop();
941
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(6));
942
- expect(effectFn).toHaveBeenLastCalledWith([0]);
943
-
944
- $array.pop();
945
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(7));
946
- expect(effectFn).toHaveBeenLastCalledWith([]);
947
- });
948
-
949
- it("should call effect when updated with unshift/shift", async () => {
950
- const $array = array<FlowState<number>>();
951
- const effectFn = vi.fn();
952
- effect(async (t) =>
953
- effectFn(
954
- await Promise.all(
955
- (await $array.get(t)).map((state) => state.get(t)),
956
- ),
957
- ),
958
- );
959
-
960
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
961
- expect(effectFn).toHaveBeenLastCalledWith([]);
962
-
963
- $array.unshift(state(0));
964
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
965
- expect(effectFn).toHaveBeenLastCalledWith([0]);
966
-
967
- $array.unshift(state(1));
968
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(3));
969
- expect(effectFn).toHaveBeenLastCalledWith([1, 0]);
970
-
971
- $array.unshift(state(2));
972
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(4));
973
- expect(effectFn).toHaveBeenLastCalledWith([2, 1, 0]);
974
-
975
- $array.shift();
976
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(5));
977
- expect(effectFn).toHaveBeenLastCalledWith([1, 0]);
978
-
979
- $array.shift();
980
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(6));
981
- expect(effectFn).toHaveBeenLastCalledWith([0]);
982
-
983
- $array.shift();
984
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(7));
985
- expect(effectFn).toHaveBeenLastCalledWith([]);
986
- });
987
-
988
- it("should call effect when updated with splice", async () => {
989
- const $array = array<FlowState<number>>([
990
- state(0),
991
- state(1),
992
- state(2),
993
- state(3),
994
- state(4),
995
- ]);
996
- const effectFn = vi.fn();
997
- effect(async (t) =>
998
- effectFn($array.get(t).map((state) => state.get(t))),
999
- );
1000
-
1001
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
1002
- expect(effectFn).toHaveBeenLastCalledWith([0, 1, 2, 3, 4]);
1003
-
1004
- $array.splice(1, 2);
1005
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
1006
- expect(effectFn).toHaveBeenLastCalledWith([0, 3, 4]);
1007
-
1008
- $array.splice(1, 0, state(1), state(2));
1009
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(3));
1010
- expect(effectFn).toHaveBeenLastCalledWith([0, 1, 2, 3, 4]);
1011
- });
1012
-
1013
- it("should call effect when updated with clear", async () => {
1014
- const $array = array<FlowState<number>>([
1015
- state(0),
1016
- state(1),
1017
- state(2),
1018
- state(3),
1019
- state(4),
1020
- ]);
1021
- const effectFn = vi.fn();
1022
- effect(async (t) =>
1023
- effectFn($array.get(t).map((state) => state.get(t))),
1024
- );
1025
-
1026
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
1027
- expect(effectFn).toHaveBeenLastCalledWith([0, 1, 2, 3, 4]);
1028
-
1029
- $array.clear();
1030
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
1031
- expect(effectFn).toHaveBeenLastCalledWith([]);
1032
- });
1033
- });
1034
-
1035
- describe("item reactivity", () => {
1036
- it("should call effect when item is updated", async () => {
1037
- const $array = array<FlowState<number>>([
1038
- state(0),
1039
- state(1),
1040
- state(2),
1041
- ]);
1042
- const effectFn = vi.fn();
1043
- const effect0Fn = vi.fn();
1044
- const effect1Fn = vi.fn();
1045
- const effect2Fn = vi.fn();
1046
-
1047
- effect(async (t) =>
1048
- effectFn($array.get(t).map((state) => state.get(t))),
1049
- );
1050
- effect(async (t) => effect0Fn(await (await $array.get(t))[0].get(t)));
1051
- effect(async (t) => effect1Fn(await (await $array.get(t))[1].get(t)));
1052
- effect(async (t) => effect2Fn(await (await $array.get(t))[2].get(t)));
1053
-
1054
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
1055
- expect(effectFn).toHaveBeenLastCalledWith([0, 1, 2]);
1056
- await vi.waitFor(() => expect(effect0Fn).toHaveBeenCalledTimes(1));
1057
- expect(effect0Fn).toHaveBeenLastCalledWith(0);
1058
- await vi.waitFor(() => expect(effect1Fn).toHaveBeenCalledTimes(1));
1059
- expect(effect1Fn).toHaveBeenLastCalledWith(1);
1060
- await vi.waitFor(() => expect(effect2Fn).toHaveBeenCalledTimes(1));
1061
- expect(effect2Fn).toHaveBeenLastCalledWith(2);
1062
-
1063
- (await $array.pick())[0].set(1);
1064
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
1065
- expect(effectFn).toHaveBeenLastCalledWith([1, 1, 2]);
1066
- await vi.waitFor(() => expect(effect0Fn).toHaveBeenCalledTimes(2));
1067
- expect(effect0Fn).toHaveBeenLastCalledWith(1);
1068
- await vi.waitFor(() => expect(effect1Fn).toHaveBeenCalledTimes(1));
1069
- expect(effect1Fn).toHaveBeenLastCalledWith(1);
1070
- await vi.waitFor(() => expect(effect2Fn).toHaveBeenCalledTimes(1));
1071
- expect(effect2Fn).toHaveBeenLastCalledWith(2);
1072
-
1073
- (await $array.pick())[1].set(2);
1074
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(3));
1075
- expect(effectFn).toHaveBeenLastCalledWith([1, 2, 2]);
1076
- await vi.waitFor(() => expect(effect0Fn).toHaveBeenCalledTimes(2));
1077
- expect(effect0Fn).toHaveBeenLastCalledWith(1);
1078
- await vi.waitFor(() => expect(effect1Fn).toHaveBeenCalledTimes(2));
1079
- expect(effect1Fn).toHaveBeenLastCalledWith(2);
1080
- await vi.waitFor(() => expect(effect2Fn).toHaveBeenCalledTimes(1));
1081
- expect(effect2Fn).toHaveBeenLastCalledWith(2);
1082
-
1083
- (await $array.pick())[2].set(3);
1084
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(4));
1085
- expect(effectFn).toHaveBeenLastCalledWith([1, 2, 3]);
1086
- await vi.waitFor(() => expect(effect0Fn).toHaveBeenCalledTimes(2));
1087
- expect(effect0Fn).toHaveBeenLastCalledWith(1);
1088
- await vi.waitFor(() => expect(effect1Fn).toHaveBeenCalledTimes(2));
1089
- expect(effect1Fn).toHaveBeenLastCalledWith(2);
1090
- await vi.waitFor(() => expect(effect2Fn).toHaveBeenCalledTimes(2));
1091
- expect(effect2Fn).toHaveBeenLastCalledWith(3);
1092
- });
1093
-
1094
- it("should call effect when item is replaced", async () => {
1095
- const $array = array<FlowState<number>>([
1096
- state(0),
1097
- state(1),
1098
- state(2),
1099
- ]);
1100
- const effectFn = vi.fn();
1101
- const effect0Fn = vi.fn();
1102
-
1103
- effect(async (t) =>
1104
- effectFn($array.get(t).map((state) => state.get(t))),
1105
- );
1106
- effect(async (t) => effect0Fn($array.get(t)[0].get(t)));
1107
-
1108
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
1109
- expect(effectFn).toHaveBeenLastCalledWith([0, 1, 2]);
1110
- await vi.waitFor(() => expect(effect0Fn).toHaveBeenCalledTimes(1));
1111
- expect(effect0Fn).toHaveBeenLastCalledWith(0);
1112
-
1113
- $array.update(0, state(3));
1114
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
1115
- expect(effectFn).toHaveBeenLastCalledWith([3, 1, 2]);
1116
- await vi.waitFor(() => expect(effect0Fn).toHaveBeenCalledTimes(2));
1117
- expect(effect0Fn).toHaveBeenLastCalledWith(3);
1118
-
1119
- $array.shift();
1120
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(3));
1121
- expect(effectFn).toHaveBeenLastCalledWith([1, 2]);
1122
- await vi.waitFor(() => expect(effect0Fn).toHaveBeenCalledTimes(3));
1123
- expect(effect0Fn).toHaveBeenLastCalledWith(1);
1124
-
1125
- $array.unshift(state(4));
1126
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(4));
1127
- expect(effectFn).toHaveBeenLastCalledWith([4, 1, 2]);
1128
- await vi.waitFor(() => expect(effect0Fn).toHaveBeenCalledTimes(4));
1129
- expect(effect0Fn).toHaveBeenLastCalledWith(4);
1130
- });
1131
- });
1132
-
1133
- describe("lastAction reactivity", () => {
1134
- describe("set action", () => {
1135
- it("should call effect when $lastAction is updated with set action", async () => {
1136
- const $array = array([state(0), state(1), state(2)]);
1137
- const effectFn = vi.fn();
1138
- effect(async (t) => effectFn(await $array.$lastAction.get(t)));
1139
-
1140
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
1141
- expect(effectFn).toHaveBeenLastCalledWith(
1142
- expect.objectContaining({
1143
- type: "set",
1144
- }),
1145
- );
1146
-
1147
- await $array.set([state(1), state(2), state(3)]);
1148
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
1149
- expect(effectFn).toHaveBeenLastCalledWith(
1150
- expect.objectContaining({
1151
- type: "set",
1152
- }),
1153
- );
1154
- });
1155
- });
1156
-
1157
- describe("update action", () => {
1158
- it("should call effect when $lastAction is updated with setItem action", async () => {
1159
- const $array = array([state(0), state(1), state(2)]);
1160
- const effectFn = vi.fn();
1161
- effect(async (t) => effectFn($array.$lastAction.get(t)));
1162
-
1163
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
1164
-
1165
- const $newItem = state(10);
1166
- $array.update(1, $newItem);
1167
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
1168
- expect(effectFn).toHaveBeenLastCalledWith(
1169
- expect.objectContaining({
1170
- type: "update",
1171
- index: 1,
1172
- }),
1173
- );
1174
- });
1175
- });
1176
-
1177
- describe("push action", () => {
1178
- it("should call effect when $lastAction is updated with push action", async () => {
1179
- const $array = array<FlowState<number>>();
1180
- const effectFn = vi.fn();
1181
- effect(async (t) => effectFn(await $array.$lastAction.get(t)));
1182
-
1183
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
1184
- expect(effectFn).toHaveBeenLastCalledWith(
1185
- expect.objectContaining({
1186
- type: "set",
1187
- }),
1188
- );
1189
-
1190
- const $newItem = state(0);
1191
- $array.push($newItem);
1192
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
1193
- expect(effectFn).toHaveBeenLastCalledWith(
1194
- expect.objectContaining({
1195
- type: "push",
1196
- }),
1197
- );
1198
-
1199
- const $newItem2 = state(1);
1200
- $array.push($newItem2);
1201
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(3));
1202
- expect(effectFn).toHaveBeenLastCalledWith(
1203
- expect.objectContaining({
1204
- type: "push",
1205
- }),
1206
- );
1207
- });
1208
- });
1209
-
1210
- describe("pop action", () => {
1211
- it("should call effect when $lastAction is updated with pop action", async () => {
1212
- const $array = array<FlowState<number>>([
1213
- state(0),
1214
- state(1),
1215
- state(2),
1216
- ]);
1217
- const effectFn = vi.fn();
1218
- effect(async (t) => effectFn(await $array.$lastAction.get(t)));
1219
-
1220
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
1221
-
1222
- $array.pop();
1223
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
1224
- expect(effectFn).toHaveBeenLastCalledWith({
1225
- type: "pop",
1226
- });
1227
-
1228
- $array.pop();
1229
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(3));
1230
- expect(effectFn).toHaveBeenLastCalledWith({
1231
- type: "pop",
1232
- });
1233
- });
1234
- });
1235
-
1236
- describe("unshift action", () => {
1237
- it("should call effect when $lastAction is updated with unshift action", async () => {
1238
- const $array = array<FlowState<number>>();
1239
- const effectFn = vi.fn();
1240
- effect(async (t) => effectFn(await $array.$lastAction.get(t)));
1241
-
1242
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
1243
- expect(effectFn).toHaveBeenLastCalledWith(
1244
- expect.objectContaining({
1245
- type: "set",
1246
- }),
1247
- );
1248
-
1249
- const $newItem = state(0);
1250
- $array.unshift($newItem);
1251
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
1252
- expect(effectFn).toHaveBeenLastCalledWith(
1253
- expect.objectContaining({
1254
- type: "unshift",
1255
- }),
1256
- );
1257
-
1258
- const $newItem2 = state(1);
1259
- $array.unshift($newItem2);
1260
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(3));
1261
- expect(effectFn).toHaveBeenLastCalledWith(
1262
- expect.objectContaining({
1263
- type: "unshift",
1264
- }),
1265
- );
1266
- });
1267
- });
1268
-
1269
- describe("shift action", () => {
1270
- it("should call effect when $lastAction is updated with shift action", async () => {
1271
- const $array = array<FlowState<number>>([
1272
- state(0),
1273
- state(1),
1274
- state(2),
1275
- ]);
1276
- const effectFn = vi.fn();
1277
- effect(async (t) => effectFn(await $array.$lastAction.get(t)));
1278
-
1279
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
1280
-
1281
- $array.shift();
1282
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
1283
- expect(effectFn).toHaveBeenLastCalledWith({
1284
- type: "shift",
1285
- });
1286
-
1287
- $array.shift();
1288
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(3));
1289
- expect(effectFn).toHaveBeenLastCalledWith({
1290
- type: "shift",
1291
- });
1292
- });
1293
- });
1294
-
1295
- describe("splice action", () => {
1296
- it("should call effect when $lastAction is updated with splice action", async () => {
1297
- const $array = array<FlowState<number>>([
1298
- state(0),
1299
- state(1),
1300
- state(2),
1301
- state(3),
1302
- state(4),
1303
- ]);
1304
- const effectFn = vi.fn();
1305
- effect(async (t) => effectFn(await $array.$lastAction.get(t)));
1306
-
1307
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
1308
- expect(effectFn).toHaveBeenLastCalledWith(
1309
- expect.objectContaining({
1310
- type: "set",
1311
- }),
1312
- );
1313
-
1314
- $array.splice(1, 2);
1315
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
1316
- expect(effectFn).toHaveBeenLastCalledWith(
1317
- expect.objectContaining({
1318
- type: "splice",
1319
- start: 1,
1320
- deleteCount: 2,
1321
- }),
1322
- );
1323
-
1324
- $array.splice(1, 0, state(1), state(2));
1325
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(3));
1326
- expect(effectFn).toHaveBeenLastCalledWith(
1327
- expect.objectContaining({
1328
- type: "splice",
1329
- start: 1,
1330
- deleteCount: 0,
1331
- }),
1332
- );
1333
- });
1334
- });
1335
-
1336
- describe("clear action", () => {
1337
- it("should call effect when $lastAction is updated with clear action", async () => {
1338
- const $array = array<FlowState<number>>([
1339
- state(0),
1340
- state(1),
1341
- state(2),
1342
- state(3),
1343
- state(4),
1344
- ]);
1345
- const effectFn = vi.fn();
1346
- effect(async (t) => effectFn(await $array.$lastAction.get(t)));
1347
-
1348
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(1));
1349
- expect(effectFn).toHaveBeenLastCalledWith(
1350
- expect.objectContaining({
1351
- type: "set",
1352
- }),
1353
- );
1354
-
1355
- $array.clear();
1356
- await vi.waitFor(() => expect(effectFn).toHaveBeenCalledTimes(2));
1357
- expect(effectFn).toHaveBeenLastCalledWith({
1358
- type: "clear",
1359
- });
1360
- });
1361
- });
1362
- });
1363
- });
1364
- });
1365
- });