@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.
- package/.vscode/settings.json +3 -3
- package/CHANGELOG.md +43 -0
- package/README.md +2 -18
- package/biome.json +45 -35
- package/dist/picoflow.js +856 -1530
- package/dist/types/api/base/flowDisposable.d.ts +41 -0
- package/dist/types/api/base/flowDisposable.d.ts.map +1 -0
- package/dist/types/api/base/flowObservable.d.ts +27 -0
- package/dist/types/api/base/flowObservable.d.ts.map +1 -0
- package/dist/types/api/base/flowSubscribable.d.ts +79 -0
- package/dist/types/api/base/flowSubscribable.d.ts.map +1 -0
- package/dist/types/api/base/flowTracker.d.ts +8 -0
- package/dist/types/api/base/flowTracker.d.ts.map +1 -0
- package/dist/types/api/base/index.d.ts +5 -0
- package/dist/types/api/base/index.d.ts.map +1 -0
- package/dist/types/api/index.d.ts +3 -0
- package/dist/types/api/index.d.ts.map +1 -0
- package/dist/types/api/nodes/async/flowConstantAsync.d.ts +31 -0
- package/dist/types/api/nodes/async/flowConstantAsync.d.ts.map +1 -0
- package/dist/types/api/nodes/async/flowDerivationAsync.d.ts +37 -0
- package/dist/types/api/nodes/async/flowDerivationAsync.d.ts.map +1 -0
- package/dist/types/api/nodes/async/flowStateAsync.d.ts +41 -0
- package/dist/types/api/nodes/async/flowStateAsync.d.ts.map +1 -0
- package/dist/types/api/nodes/async/flowWritableDerivationAsync.d.ts +30 -0
- package/dist/types/api/nodes/async/flowWritableDerivationAsync.d.ts.map +1 -0
- package/dist/types/{flow → api}/nodes/async/index.d.ts +1 -2
- package/dist/types/api/nodes/async/index.d.ts.map +1 -0
- package/dist/types/api/nodes/collections/flowArray.d.ts +134 -0
- package/dist/types/api/nodes/collections/flowArray.d.ts.map +1 -0
- package/dist/types/api/nodes/collections/flowMap.d.ts +98 -0
- package/dist/types/api/nodes/collections/flowMap.d.ts.map +1 -0
- package/dist/types/api/nodes/collections/index.d.ts.map +1 -0
- package/dist/types/api/nodes/flowEffect.d.ts +28 -0
- package/dist/types/api/nodes/flowEffect.d.ts.map +1 -0
- package/dist/types/api/nodes/flowSignal.d.ts +25 -0
- package/dist/types/api/nodes/flowSignal.d.ts.map +1 -0
- package/dist/types/api/nodes/flowValue.d.ts +35 -0
- package/dist/types/api/nodes/flowValue.d.ts.map +1 -0
- package/dist/types/api/nodes/index.d.ts +8 -0
- package/dist/types/api/nodes/index.d.ts.map +1 -0
- package/dist/types/api/nodes/sync/flowConstant.d.ts +29 -0
- package/dist/types/api/nodes/sync/flowConstant.d.ts.map +1 -0
- package/dist/types/api/nodes/sync/flowDerivation.d.ts +36 -0
- package/dist/types/api/nodes/sync/flowDerivation.d.ts.map +1 -0
- package/dist/types/api/nodes/sync/flowState.d.ts +39 -0
- package/dist/types/api/nodes/sync/flowState.d.ts.map +1 -0
- package/dist/types/api/nodes/sync/flowWritableDerivation.d.ts +28 -0
- package/dist/types/api/nodes/sync/flowWritableDerivation.d.ts.map +1 -0
- package/dist/types/{flow → api}/nodes/sync/index.d.ts +1 -2
- package/dist/types/api/nodes/sync/index.d.ts.map +1 -0
- package/dist/types/api/nodes/utils.d.ts +22 -0
- package/dist/types/api/nodes/utils.d.ts.map +1 -0
- package/dist/types/base/disposable.d.ts +11 -0
- package/dist/types/base/disposable.d.ts.map +1 -0
- package/dist/types/base/executionStack.d.ts +14 -0
- package/dist/types/base/executionStack.d.ts.map +1 -0
- package/dist/types/base/index.d.ts +6 -0
- package/dist/types/base/index.d.ts.map +1 -0
- package/dist/types/base/node.d.ts +27 -0
- package/dist/types/base/node.d.ts.map +1 -0
- package/dist/types/base/observable.d.ts +37 -0
- package/dist/types/base/observable.d.ts.map +1 -0
- package/dist/types/base/observer.d.ts +25 -0
- package/dist/types/base/observer.d.ts.map +1 -0
- package/dist/types/converters/index.d.ts +2 -0
- package/dist/types/converters/index.d.ts.map +1 -0
- package/dist/types/converters/solid.d.ts +46 -0
- package/dist/types/converters/solid.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -63
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/nodes/arrayNode.d.ts +2 -0
- package/dist/types/nodes/arrayNode.d.ts.map +1 -0
- package/dist/types/nodes/effectNode.d.ts +2 -0
- package/dist/types/nodes/effectNode.d.ts.map +1 -0
- package/dist/types/nodes/index.d.ts +9 -0
- package/dist/types/nodes/index.d.ts.map +1 -0
- package/dist/types/nodes/mapNode.d.ts +2 -0
- package/dist/types/nodes/mapNode.d.ts.map +1 -0
- package/dist/types/nodes/signalNode.d.ts +2 -0
- package/dist/types/nodes/signalNode.d.ts.map +1 -0
- package/dist/types/nodes/valueAsyncNode.d.ts +2 -0
- package/dist/types/nodes/valueAsyncNode.d.ts.map +1 -0
- package/dist/types/nodes/valueNode.d.ts +2 -0
- package/dist/types/nodes/valueNode.d.ts.map +1 -0
- package/dist/types/nodes/valueSyncNode.d.ts +2 -0
- package/dist/types/nodes/valueSyncNode.d.ts.map +1 -0
- package/dist/types/schedulers/asyncResolver.d.ts +2 -0
- package/dist/types/schedulers/asyncResolver.d.ts.map +1 -0
- package/dist/types/schedulers/asyncScheduler.d.ts +2 -0
- package/dist/types/schedulers/asyncScheduler.d.ts.map +1 -0
- package/dist/types/schedulers/index.d.ts +5 -0
- package/dist/types/schedulers/index.d.ts.map +1 -0
- package/dist/types/schedulers/pendingError.d.ts +2 -0
- package/dist/types/schedulers/pendingError.d.ts.map +1 -0
- package/dist/types/schedulers/scheduler.d.ts +2 -0
- package/dist/types/schedulers/scheduler.d.ts.map +1 -0
- package/dist/types/schedulers/syncResolver.d.ts +2 -0
- package/dist/types/schedulers/syncResolver.d.ts.map +1 -0
- package/dist/types/schedulers/syncScheduler.d.ts +2 -0
- package/dist/types/schedulers/syncScheduler.d.ts.map +1 -0
- package/docs/.vitepress/config.mts +128 -93
- package/docs/api/functions/array.md +14 -37
- package/docs/api/functions/constant.md +13 -25
- package/docs/api/functions/constantAsync.md +69 -0
- package/docs/api/functions/derivation.md +14 -33
- package/docs/api/functions/derivationAsync.md +34 -0
- package/docs/api/functions/from.md +62 -153
- package/docs/api/functions/isDisposable.md +8 -30
- package/docs/api/functions/map.md +15 -36
- package/docs/api/functions/signal.md +8 -23
- package/docs/api/functions/state.md +43 -23
- package/docs/api/functions/stateAsync.md +69 -0
- package/docs/api/functions/subscribe.md +40 -0
- package/docs/api/functions/writableDerivation.md +33 -0
- package/docs/api/functions/writableDerivationAsync.md +34 -0
- package/docs/api/index.md +45 -102
- package/docs/api/interfaces/FlowArray.md +439 -0
- package/docs/api/interfaces/FlowConstant.md +220 -0
- package/docs/api/interfaces/FlowConstantAsync.md +221 -0
- package/docs/api/interfaces/FlowDerivation.md +241 -0
- package/docs/api/interfaces/FlowDerivationAsync.md +242 -0
- package/docs/api/interfaces/FlowDisposable.md +32 -38
- package/docs/api/interfaces/FlowEffect.md +64 -0
- package/docs/api/interfaces/FlowMap.md +374 -0
- package/docs/api/interfaces/FlowObservable.md +155 -0
- package/docs/api/interfaces/FlowSignal.md +156 -0
- package/docs/api/interfaces/FlowState.md +269 -0
- package/docs/api/interfaces/FlowStateAsync.md +268 -0
- package/docs/api/interfaces/FlowSubscribable.md +55 -0
- package/docs/api/interfaces/FlowTracker.md +61 -0
- package/docs/api/interfaces/FlowValue.md +222 -0
- package/docs/api/interfaces/FlowWritableDerivation.md +292 -0
- package/docs/api/interfaces/FlowWritableDerivationAsync.md +293 -0
- package/docs/api/type-aliases/DerivationFunction.md +28 -0
- package/docs/api/type-aliases/DerivationFunctionAsync.md +28 -0
- package/docs/api/type-aliases/FlowArrayAction.md +19 -8
- package/docs/api/type-aliases/FlowDataTracker.md +33 -0
- package/docs/api/type-aliases/FlowMapAction.md +48 -0
- package/docs/api/type-aliases/FlowOnDataListener.md +33 -0
- package/docs/api/type-aliases/FlowOnErrorListener.md +27 -0
- package/docs/api/type-aliases/FlowOnPendingListener.md +21 -0
- package/docs/api/type-aliases/FlowReadonly.md +22 -0
- package/docs/api/type-aliases/InitFunction.md +21 -0
- package/docs/api/type-aliases/InitFunctionAsync.md +21 -0
- package/docs/api/type-aliases/NotPromise.md +6 -3
- package/docs/api/type-aliases/UpdateFunction.md +27 -0
- package/docs/api/type-aliases/UpdateFunctionAsync.md +27 -0
- package/docs/api/typedoc-sidebar.json +1 -81
- package/docs/examples/examples.md +0 -2
- package/docs/guide/advanced/architecture.md +1234 -0
- package/docs/guide/advanced/migration-v2.md +204 -0
- package/docs/guide/advanced/solidjs.md +2 -88
- package/docs/guide/introduction/concepts.md +4 -3
- package/docs/guide/introduction/conventions.md +2 -33
- package/docs/guide/introduction/getting-started.md +28 -23
- package/docs/guide/introduction/lifecycle.md +16 -19
- package/docs/guide/primitives/array.md +102 -216
- package/docs/guide/primitives/constant.md +39 -212
- package/docs/guide/primitives/derivations.md +55 -122
- package/docs/guide/primitives/effects.md +155 -241
- package/docs/guide/primitives/map.md +64 -186
- package/docs/guide/primitives/overview.md +45 -128
- package/docs/guide/primitives/signal.md +51 -88
- package/docs/guide/primitives/state.md +34 -130
- package/package.json +56 -60
- package/src/api/base/flowDisposable.ts +44 -0
- package/src/api/base/flowObservable.ts +28 -0
- package/src/api/base/flowSubscribable.ts +87 -0
- package/src/api/base/flowTracker.ts +7 -0
- package/src/api/base/index.ts +4 -0
- package/src/{flow → api}/index.ts +0 -1
- package/src/api/nodes/async/flowConstantAsync.ts +36 -0
- package/src/api/nodes/async/flowDerivationAsync.ts +42 -0
- package/src/api/nodes/async/flowStateAsync.ts +47 -0
- package/src/api/nodes/async/flowWritableDerivationAsync.ts +33 -0
- package/src/{flow → api}/nodes/async/index.ts +1 -2
- package/src/api/nodes/collections/flowArray.ts +155 -0
- package/src/api/nodes/collections/flowMap.ts +115 -0
- package/src/api/nodes/flowEffect.ts +42 -0
- package/src/api/nodes/flowSignal.ts +28 -0
- package/src/api/nodes/flowValue.ts +36 -0
- package/src/api/nodes/index.ts +7 -0
- package/src/api/nodes/sync/flowConstant.ts +33 -0
- package/src/api/nodes/sync/flowDerivation.ts +41 -0
- package/src/api/nodes/sync/flowState.ts +45 -0
- package/src/api/nodes/sync/flowWritableDerivation.ts +31 -0
- package/src/{flow → api}/nodes/sync/index.ts +1 -2
- package/src/api/nodes/utils.ts +22 -0
- package/src/base/disposable.ts +18 -0
- package/src/base/executionStack.ts +42 -0
- package/src/base/index.ts +5 -0
- package/src/base/node.ts +98 -0
- package/src/base/observable.ts +87 -0
- package/src/base/observer.ts +51 -0
- package/src/converters/index.ts +1 -0
- package/src/converters/solid.ts +109 -0
- package/src/index.ts +2 -64
- package/src/nodes/arrayNode.ts +172 -0
- package/src/nodes/effectNode.ts +59 -0
- package/src/nodes/index.ts +8 -0
- package/src/nodes/mapNode.ts +127 -0
- package/src/nodes/signalNode.ts +21 -0
- package/src/nodes/valueAsyncNode.ts +88 -0
- package/src/nodes/valueNode.ts +144 -0
- package/src/nodes/valueSyncNode.ts +128 -0
- package/src/schedulers/asyncResolver.ts +78 -0
- package/src/schedulers/asyncScheduler.ts +66 -0
- package/src/schedulers/index.ts +4 -0
- package/src/schedulers/pendingError.ts +13 -0
- package/src/schedulers/scheduler.ts +9 -0
- package/src/schedulers/syncResolver.ts +69 -0
- package/src/schedulers/syncScheduler.ts +55 -0
- package/test/base/pendingError.test.ts +67 -0
- package/test/converters/solid.derivation.browser.test.tsx +69 -0
- package/test/converters/solid.node.test.ts +654 -0
- package/test/converters/solid.state.browser.test.tsx +1592 -0
- package/test/reactivity/flowSignal.test.ts +226 -0
- package/test/reactivity/nodes/async/asyncScheduler/asyncResolver.test.ts +593 -0
- package/test/reactivity/nodes/async/asyncScheduler/asyncScheduler.test.ts +317 -0
- package/test/reactivity/nodes/async/flowConstantAsync.test.ts +652 -0
- package/test/reactivity/nodes/async/flowDerivation.test.ts +898 -0
- package/test/reactivity/nodes/async/flowDerivationAsync.test.ts +1716 -0
- package/test/reactivity/nodes/async/flowStateAsync.test.ts +708 -0
- package/test/reactivity/nodes/async/flowWritableDerivationAsync.test.ts +614 -0
- package/test/reactivity/nodes/collections/flowArray.asyncStates.test.ts +1289 -0
- package/test/reactivity/nodes/collections/flowArray.scalars.test.ts +961 -0
- package/test/reactivity/nodes/collections/flowArray.states.test.ts +1035 -0
- package/test/reactivity/nodes/collections/flowMap.asyncStates.test.ts +960 -0
- package/test/reactivity/nodes/collections/flowMap.scalars.test.ts +775 -0
- package/test/reactivity/nodes/collections/flowMap.states.test.ts +958 -0
- package/test/reactivity/nodes/sync/flowConstant.test.ts +377 -0
- package/test/reactivity/nodes/sync/flowDerivation.test.ts +896 -0
- package/test/reactivity/nodes/sync/flowState.test.ts +341 -0
- package/test/reactivity/nodes/sync/flowWritableDerivation.test.ts +603 -0
- package/test/vitest.d.ts +10 -0
- package/tsconfig.json +31 -20
- package/typedoc.json +35 -35
- package/vite.config.ts +25 -23
- package/vitest.browser.config.ts +21 -0
- package/vitest.config.ts +12 -12
- package/.cursor/plans/unifier-flowresource-avec-flowderivation-c9506e24.plan.md +0 -372
- package/.cursor/plans/update-js-e795d61b.plan.md +0 -567
- package/dist/types/flow/base/flowDisposable.d.ts +0 -67
- package/dist/types/flow/base/flowDisposable.d.ts.map +0 -1
- package/dist/types/flow/base/flowEffect.d.ts +0 -127
- package/dist/types/flow/base/flowEffect.d.ts.map +0 -1
- package/dist/types/flow/base/flowGraph.d.ts +0 -97
- package/dist/types/flow/base/flowGraph.d.ts.map +0 -1
- package/dist/types/flow/base/flowSignal.d.ts +0 -134
- package/dist/types/flow/base/flowSignal.d.ts.map +0 -1
- package/dist/types/flow/base/flowTracker.d.ts +0 -15
- package/dist/types/flow/base/flowTracker.d.ts.map +0 -1
- package/dist/types/flow/base/index.d.ts +0 -7
- package/dist/types/flow/base/index.d.ts.map +0 -1
- package/dist/types/flow/base/utils.d.ts +0 -20
- package/dist/types/flow/base/utils.d.ts.map +0 -1
- package/dist/types/flow/collections/flowArray.d.ts +0 -148
- package/dist/types/flow/collections/flowArray.d.ts.map +0 -1
- package/dist/types/flow/collections/flowMap.d.ts +0 -224
- package/dist/types/flow/collections/flowMap.d.ts.map +0 -1
- package/dist/types/flow/collections/index.d.ts.map +0 -1
- package/dist/types/flow/index.d.ts +0 -4
- package/dist/types/flow/index.d.ts.map +0 -1
- package/dist/types/flow/nodes/async/flowConstantAsync.d.ts +0 -137
- package/dist/types/flow/nodes/async/flowConstantAsync.d.ts.map +0 -1
- package/dist/types/flow/nodes/async/flowDerivationAsync.d.ts +0 -137
- package/dist/types/flow/nodes/async/flowDerivationAsync.d.ts.map +0 -1
- package/dist/types/flow/nodes/async/flowNodeAsync.d.ts +0 -343
- package/dist/types/flow/nodes/async/flowNodeAsync.d.ts.map +0 -1
- package/dist/types/flow/nodes/async/flowReadonlyAsync.d.ts +0 -81
- package/dist/types/flow/nodes/async/flowReadonlyAsync.d.ts.map +0 -1
- package/dist/types/flow/nodes/async/flowStateAsync.d.ts +0 -111
- package/dist/types/flow/nodes/async/flowStateAsync.d.ts.map +0 -1
- package/dist/types/flow/nodes/async/index.d.ts.map +0 -1
- package/dist/types/flow/nodes/index.d.ts +0 -3
- package/dist/types/flow/nodes/index.d.ts.map +0 -1
- package/dist/types/flow/nodes/sync/flowConstant.d.ts +0 -108
- package/dist/types/flow/nodes/sync/flowConstant.d.ts.map +0 -1
- package/dist/types/flow/nodes/sync/flowDerivation.d.ts +0 -100
- package/dist/types/flow/nodes/sync/flowDerivation.d.ts.map +0 -1
- package/dist/types/flow/nodes/sync/flowNode.d.ts +0 -314
- package/dist/types/flow/nodes/sync/flowNode.d.ts.map +0 -1
- package/dist/types/flow/nodes/sync/flowReadonly.d.ts +0 -57
- package/dist/types/flow/nodes/sync/flowReadonly.d.ts.map +0 -1
- package/dist/types/flow/nodes/sync/flowState.d.ts +0 -96
- package/dist/types/flow/nodes/sync/flowState.d.ts.map +0 -1
- package/dist/types/flow/nodes/sync/index.d.ts.map +0 -1
- package/dist/types/solid/converters.d.ts +0 -57
- package/dist/types/solid/converters.d.ts.map +0 -1
- package/dist/types/solid/index.d.ts +0 -3
- package/dist/types/solid/index.d.ts.map +0 -1
- package/dist/types/solid/primitives.d.ts +0 -181
- package/dist/types/solid/primitives.d.ts.map +0 -1
- package/docs/api/classes/FlowArray.md +0 -489
- package/docs/api/classes/FlowConstant.md +0 -350
- package/docs/api/classes/FlowDerivation.md +0 -334
- package/docs/api/classes/FlowEffect.md +0 -100
- package/docs/api/classes/FlowMap.md +0 -512
- package/docs/api/classes/FlowObservable.md +0 -306
- package/docs/api/classes/FlowResource.md +0 -380
- package/docs/api/classes/FlowResourceAsync.md +0 -362
- package/docs/api/classes/FlowSignal.md +0 -160
- package/docs/api/classes/FlowState.md +0 -368
- package/docs/api/classes/FlowStream.md +0 -367
- package/docs/api/classes/FlowStreamAsync.md +0 -364
- package/docs/api/classes/SolidDerivation.md +0 -75
- package/docs/api/classes/SolidResource.md +0 -91
- package/docs/api/classes/SolidState.md +0 -71
- package/docs/api/classes/TrackingContext.md +0 -33
- package/docs/api/functions/effect.md +0 -49
- package/docs/api/functions/resource.md +0 -52
- package/docs/api/functions/resourceAsync.md +0 -50
- package/docs/api/functions/stream.md +0 -53
- package/docs/api/functions/streamAsync.md +0 -50
- package/docs/api/interfaces/SolidObservable.md +0 -19
- package/docs/api/type-aliases/FlowStreamDisposer.md +0 -15
- package/docs/api/type-aliases/FlowStreamSetter.md +0 -27
- package/docs/api/type-aliases/FlowStreamUpdater.md +0 -32
- package/docs/api/type-aliases/SolidGetter.md +0 -17
- package/docs/guide/primitives/resources.md +0 -858
- package/docs/guide/primitives/streams.md +0 -931
- package/src/flow/base/flowDisposable.ts +0 -71
- package/src/flow/base/flowEffect.ts +0 -171
- package/src/flow/base/flowGraph.ts +0 -288
- package/src/flow/base/flowSignal.ts +0 -207
- package/src/flow/base/flowTracker.ts +0 -17
- package/src/flow/base/index.ts +0 -6
- package/src/flow/base/utils.ts +0 -19
- package/src/flow/collections/flowArray.ts +0 -409
- package/src/flow/collections/flowMap.ts +0 -398
- package/src/flow/nodes/async/flowConstantAsync.ts +0 -142
- package/src/flow/nodes/async/flowDerivationAsync.ts +0 -143
- package/src/flow/nodes/async/flowNodeAsync.ts +0 -474
- package/src/flow/nodes/async/flowReadonlyAsync.ts +0 -81
- package/src/flow/nodes/async/flowStateAsync.ts +0 -116
- package/src/flow/nodes/await/advanced/index.ts +0 -5
- package/src/flow/nodes/await/advanced/resource.ts +0 -134
- package/src/flow/nodes/await/advanced/resourceAsync.ts +0 -109
- package/src/flow/nodes/await/advanced/stream.ts +0 -188
- package/src/flow/nodes/await/advanced/streamAsync.ts +0 -176
- package/src/flow/nodes/await/flowConstantAwait.ts +0 -154
- package/src/flow/nodes/await/flowDerivationAwait.ts +0 -154
- package/src/flow/nodes/await/flowNodeAwait.ts +0 -508
- package/src/flow/nodes/await/flowReadonlyAwait.ts +0 -89
- package/src/flow/nodes/await/flowStateAwait.ts +0 -130
- package/src/flow/nodes/await/index.ts +0 -5
- package/src/flow/nodes/index.ts +0 -3
- package/src/flow/nodes/sync/flowConstant.ts +0 -111
- package/src/flow/nodes/sync/flowDerivation.ts +0 -105
- package/src/flow/nodes/sync/flowNode.ts +0 -439
- package/src/flow/nodes/sync/flowReadonly.ts +0 -57
- package/src/flow/nodes/sync/flowState.ts +0 -101
- package/src/solid/converters.ts +0 -148
- package/src/solid/index.ts +0 -2
- package/src/solid/primitives.ts +0 -215
- package/test/base/flowEffect.test.ts +0 -108
- package/test/base/flowGraph.test.ts +0 -485
- package/test/base/flowSignal.test.ts +0 -372
- package/test/collections/flowArray.asyncStates.test.ts +0 -1553
- package/test/collections/flowArray.scalars.test.ts +0 -1129
- package/test/collections/flowArray.states.test.ts +0 -1365
- package/test/collections/flowMap.asyncStates.test.ts +0 -1105
- package/test/collections/flowMap.scalars.test.ts +0 -877
- package/test/collections/flowMap.states.test.ts +0 -1097
- package/test/nodes/async/flowConstantAsync.test.ts +0 -860
- package/test/nodes/async/flowDerivationAsync.test.ts +0 -1517
- package/test/nodes/async/flowStateAsync.test.ts +0 -1387
- package/test/nodes/await/advanced/resource.test.ts +0 -129
- package/test/nodes/await/advanced/resourceAsync.test.ts +0 -108
- package/test/nodes/await/advanced/stream.test.ts +0 -198
- package/test/nodes/await/advanced/streamAsync.test.ts +0 -196
- package/test/nodes/await/flowConstantAwait.test.ts +0 -643
- package/test/nodes/await/flowDerivationAwait.test.ts +0 -1583
- package/test/nodes/await/flowStateAwait.test.ts +0 -999
- package/test/nodes/mixed/derivation.test.ts +0 -1527
- package/test/nodes/sync/flowConstant.test.ts +0 -620
- package/test/nodes/sync/flowDerivation.test.ts +0 -1373
- package/test/nodes/sync/flowState.test.ts +0 -945
- package/test/solid/converters.test.ts +0 -721
- package/test/solid/primitives.test.ts +0 -1031
- /package/dist/types/{flow → api/nodes}/collections/index.d.ts +0 -0
- /package/docs/guide/advanced/{upgrading.md → migration-v1.md} +0 -0
- /package/src/{flow → api/nodes}/collections/index.ts +0 -0
|
@@ -0,0 +1,708 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { stateAsync, subscribe } from "~";
|
|
3
|
+
import { EffectNode } from "~/nodes";
|
|
4
|
+
|
|
5
|
+
describe("flowStateAsync", () => {
|
|
6
|
+
describe("unit", () => {
|
|
7
|
+
describe("initialization", () => {
|
|
8
|
+
it("should initialize with direct Promise", async () => {
|
|
9
|
+
const $state = stateAsync(Promise.resolve(1));
|
|
10
|
+
expect(await $state.pick()).toBe(1);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should initialize lazily with function", async () => {
|
|
14
|
+
const initFn = vi.fn(() => Promise.resolve(42));
|
|
15
|
+
const $state = stateAsync(initFn);
|
|
16
|
+
|
|
17
|
+
expect(initFn).not.toHaveBeenCalled();
|
|
18
|
+
|
|
19
|
+
const value = await $state.pick();
|
|
20
|
+
expect(value).toBe(42);
|
|
21
|
+
expect(initFn).toHaveBeenCalledTimes(1);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe("set", () => {
|
|
26
|
+
it("should update value with Promise", async () => {
|
|
27
|
+
const $state = stateAsync(Promise.resolve(1));
|
|
28
|
+
expect(await $state.pick()).toBe(1);
|
|
29
|
+
|
|
30
|
+
$state.set(Promise.resolve(2));
|
|
31
|
+
expect(await $state.pick()).toBe(2);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("should update value with updater function", async () => {
|
|
35
|
+
const $state = stateAsync(Promise.resolve(1));
|
|
36
|
+
expect(await $state.pick()).toBe(1);
|
|
37
|
+
|
|
38
|
+
$state.set(async (current) => (current !== undefined ? current + 1 : 0));
|
|
39
|
+
expect(await $state.pick()).toBe(2);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("should return void", () => {
|
|
43
|
+
const $state = stateAsync(Promise.resolve(1));
|
|
44
|
+
const result = $state.set(Promise.resolve(2));
|
|
45
|
+
expect(result).toBeUndefined();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("should notify when set with same value", async () => {
|
|
49
|
+
const $state = stateAsync(Promise.resolve(1));
|
|
50
|
+
const onData = vi.fn();
|
|
51
|
+
$state.subscribe(onData);
|
|
52
|
+
|
|
53
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
54
|
+
expect(onData).toHaveBeenLastCalledWith(1);
|
|
55
|
+
|
|
56
|
+
$state.set(Promise.resolve(1));
|
|
57
|
+
|
|
58
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
59
|
+
expect(onData).toHaveBeenCalledTimes(3);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("should notify when set with different value", async () => {
|
|
63
|
+
const $state = stateAsync(Promise.resolve(1));
|
|
64
|
+
const onData = vi.fn();
|
|
65
|
+
$state.subscribe(onData);
|
|
66
|
+
|
|
67
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
68
|
+
expect(onData).toHaveBeenLastCalledWith(1);
|
|
69
|
+
|
|
70
|
+
$state.set(Promise.resolve(2));
|
|
71
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
|
|
72
|
+
expect(onData).toHaveBeenLastCalledWith(2);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("should notify when updater returns same value", async () => {
|
|
76
|
+
const $state = stateAsync(Promise.resolve(5));
|
|
77
|
+
const onData = vi.fn();
|
|
78
|
+
$state.subscribe(onData);
|
|
79
|
+
|
|
80
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
81
|
+
|
|
82
|
+
$state.set(async (current) => current ?? 0);
|
|
83
|
+
|
|
84
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
85
|
+
expect(onData).toHaveBeenCalledTimes(3);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("should notify when updater returns different value", async () => {
|
|
89
|
+
const $state = stateAsync(Promise.resolve(5));
|
|
90
|
+
const onData = vi.fn();
|
|
91
|
+
$state.subscribe(onData);
|
|
92
|
+
|
|
93
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
94
|
+
expect(onData).toHaveBeenLastCalledWith(5);
|
|
95
|
+
|
|
96
|
+
$state.set(async (current) => (current ? current + 1 : 0));
|
|
97
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
|
|
98
|
+
expect(onData).toHaveBeenLastCalledWith(6);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("should handle async updater function", async () => {
|
|
102
|
+
const $state = stateAsync(Promise.resolve(1));
|
|
103
|
+
expect(await $state.pick()).toBe(1);
|
|
104
|
+
$state.set(async (current) => {
|
|
105
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
106
|
+
return (current ?? 0) + 10;
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
expect(await $state.pick()).toBe(11);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("should handle Promise rejection in set", async () => {
|
|
113
|
+
const $state = stateAsync(Promise.resolve(1));
|
|
114
|
+
const error = new Error("Set error");
|
|
115
|
+
$state.set(Promise.reject(error));
|
|
116
|
+
await expect($state.pick()).rejects.toThrow(error);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("should throw error when set is called after disposal", async () => {
|
|
120
|
+
const $state = stateAsync(Promise.resolve(1));
|
|
121
|
+
|
|
122
|
+
expect(await $state.pick()).toBe(1);
|
|
123
|
+
$state.set(Promise.resolve(2));
|
|
124
|
+
expect(await $state.pick()).toBe(2);
|
|
125
|
+
|
|
126
|
+
$state.dispose();
|
|
127
|
+
|
|
128
|
+
expect(() => $state.set(Promise.resolve(3))).toThrow("[PicoFlow] Primitive is disposed");
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe("subscribe", () => {
|
|
133
|
+
it("should return an effect", () => {
|
|
134
|
+
const $state = stateAsync(Promise.resolve(50));
|
|
135
|
+
const onData = vi.fn();
|
|
136
|
+
const effect = $state.subscribe(onData);
|
|
137
|
+
|
|
138
|
+
expect(effect).toBeInstanceOf(EffectNode);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("should call onData immediately with current value", async () => {
|
|
142
|
+
const $state = stateAsync(Promise.resolve(55));
|
|
143
|
+
const onData = vi.fn();
|
|
144
|
+
|
|
145
|
+
$state.subscribe(onData);
|
|
146
|
+
|
|
147
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
148
|
+
expect(onData).toHaveBeenLastCalledWith(55);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("should call onData with lazy init value", async () => {
|
|
152
|
+
const $state = stateAsync(async () => 60);
|
|
153
|
+
const onData = vi.fn();
|
|
154
|
+
|
|
155
|
+
$state.subscribe(onData);
|
|
156
|
+
|
|
157
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
158
|
+
expect(onData).toHaveBeenLastCalledWith(60);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("should call onData when value is updated via set()", async () => {
|
|
162
|
+
const $state = stateAsync(Promise.resolve(65));
|
|
163
|
+
const onData = vi.fn();
|
|
164
|
+
|
|
165
|
+
$state.subscribe(onData);
|
|
166
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
167
|
+
|
|
168
|
+
$state.set(Promise.resolve(70));
|
|
169
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
|
|
170
|
+
expect(onData).toHaveBeenLastCalledWith(70);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// it("should not call onData when set() with same value", async () => {
|
|
174
|
+
// const $state = stateAsync(Promise.resolve(75));
|
|
175
|
+
// const onData = vi.fn();
|
|
176
|
+
|
|
177
|
+
// $state.subscribe(onData);
|
|
178
|
+
// await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
179
|
+
|
|
180
|
+
// $state.set(Promise.resolve(80));
|
|
181
|
+
// await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
|
|
182
|
+
|
|
183
|
+
// $state.set(Promise.resolve(80));
|
|
184
|
+
// await new Promise((resolve) => setTimeout(resolve, 50));
|
|
185
|
+
// expect(onData).toHaveBeenCalledTimes(2);
|
|
186
|
+
// });
|
|
187
|
+
|
|
188
|
+
it("should not call onData after disposer is called", async () => {
|
|
189
|
+
const $state = stateAsync(Promise.resolve(85));
|
|
190
|
+
const onData = vi.fn();
|
|
191
|
+
|
|
192
|
+
const effect = $state.subscribe(onData);
|
|
193
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
194
|
+
|
|
195
|
+
effect.dispose();
|
|
196
|
+
|
|
197
|
+
$state.set(Promise.resolve(90));
|
|
198
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
199
|
+
expect(onData).toHaveBeenCalledTimes(1);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("should support multiple subscriptions", async () => {
|
|
203
|
+
const $state = stateAsync(Promise.resolve(95));
|
|
204
|
+
const onData1 = vi.fn();
|
|
205
|
+
const onData2 = vi.fn();
|
|
206
|
+
const onData3 = vi.fn();
|
|
207
|
+
|
|
208
|
+
$state.subscribe(onData1);
|
|
209
|
+
$state.subscribe(onData2);
|
|
210
|
+
$state.subscribe(onData3);
|
|
211
|
+
|
|
212
|
+
await vi.waitFor(() => {
|
|
213
|
+
expect(onData1).toHaveBeenCalledTimes(1);
|
|
214
|
+
expect(onData2).toHaveBeenCalledTimes(1);
|
|
215
|
+
expect(onData3).toHaveBeenCalledTimes(1);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
expect(onData1).toHaveBeenLastCalledWith(95);
|
|
219
|
+
expect(onData2).toHaveBeenLastCalledWith(95);
|
|
220
|
+
expect(onData3).toHaveBeenLastCalledWith(95);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it("should support multiple subscriptions with notifications via set()", async () => {
|
|
224
|
+
const $state = stateAsync(Promise.resolve(100));
|
|
225
|
+
const onData1 = vi.fn();
|
|
226
|
+
const onData2 = vi.fn();
|
|
227
|
+
|
|
228
|
+
$state.subscribe(onData1);
|
|
229
|
+
$state.subscribe(onData2);
|
|
230
|
+
|
|
231
|
+
await vi.waitFor(() => {
|
|
232
|
+
expect(onData1).toHaveBeenCalledTimes(1);
|
|
233
|
+
expect(onData2).toHaveBeenCalledTimes(1);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
$state.set(Promise.resolve(200));
|
|
237
|
+
await vi.waitFor(() => {
|
|
238
|
+
expect(onData1).toHaveBeenCalledTimes(3);
|
|
239
|
+
expect(onData2).toHaveBeenCalledTimes(3);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
expect(onData1).toHaveBeenLastCalledWith(200);
|
|
243
|
+
expect(onData2).toHaveBeenLastCalledWith(200);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("should throw error when subscribe is called after disposal", () => {
|
|
247
|
+
const $state = stateAsync(Promise.resolve(1));
|
|
248
|
+
const onData = vi.fn();
|
|
249
|
+
|
|
250
|
+
$state.dispose();
|
|
251
|
+
|
|
252
|
+
expect(() => $state.subscribe(onData)).toThrow("[PicoFlow] Primitive is disposed");
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
describe("trigger", () => {
|
|
257
|
+
it("should return void", () => {
|
|
258
|
+
const $state = stateAsync(Promise.resolve(1));
|
|
259
|
+
const result = $state.trigger();
|
|
260
|
+
expect(result).toBeUndefined();
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it("should allow multiple triggers", async () => {
|
|
264
|
+
const $state = stateAsync(Promise.resolve(1));
|
|
265
|
+
$state.trigger();
|
|
266
|
+
$state.trigger();
|
|
267
|
+
$state.trigger();
|
|
268
|
+
|
|
269
|
+
// Should not throw
|
|
270
|
+
expect(await $state.pick()).toBe(1);
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
describe("nesting", () => {
|
|
275
|
+
it("should handle nested states with set()", async () => {
|
|
276
|
+
const $stateA = stateAsync(Promise.resolve(1));
|
|
277
|
+
const $stateB = stateAsync(Promise.resolve(2));
|
|
278
|
+
const $stateC = stateAsync(
|
|
279
|
+
Promise.resolve({
|
|
280
|
+
a: $stateA,
|
|
281
|
+
b: $stateB,
|
|
282
|
+
}),
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
const value = await $stateC.pick();
|
|
286
|
+
expect(value.a).toBe($stateA);
|
|
287
|
+
expect(value.b).toBe($stateB);
|
|
288
|
+
|
|
289
|
+
$stateA.set(Promise.resolve(3));
|
|
290
|
+
expect(await $stateA.pick()).toBe(3);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it("should handle state with complex object values and set()", async () => {
|
|
294
|
+
const complexObj = {
|
|
295
|
+
nested: { deep: { value: 42 } },
|
|
296
|
+
array: [1, 2, 3],
|
|
297
|
+
};
|
|
298
|
+
const $state = stateAsync(Promise.resolve(complexObj));
|
|
299
|
+
const value = await $state.pick();
|
|
300
|
+
expect(value).toBe(complexObj);
|
|
301
|
+
expect(value.nested.deep.value).toBe(42);
|
|
302
|
+
expect(value.array).toEqual([1, 2, 3]);
|
|
303
|
+
|
|
304
|
+
const newObj = {
|
|
305
|
+
nested: { deep: { value: 100 } },
|
|
306
|
+
array: [4, 5, 6],
|
|
307
|
+
};
|
|
308
|
+
$state.set(Promise.resolve(newObj));
|
|
309
|
+
const newValue = await $state.pick();
|
|
310
|
+
expect(newValue.nested.deep.value).toBe(100);
|
|
311
|
+
expect(newValue.array).toEqual([4, 5, 6]);
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
describe("error handling", () => {
|
|
316
|
+
describe("disposed state", () => {
|
|
317
|
+
it("should throw error when set is called after disposal", async () => {
|
|
318
|
+
const $state = stateAsync(Promise.resolve(1));
|
|
319
|
+
|
|
320
|
+
await $state.pick();
|
|
321
|
+
$state.set(Promise.resolve(2));
|
|
322
|
+
$state.dispose();
|
|
323
|
+
|
|
324
|
+
expect(() => $state.set(Promise.resolve(3))).toThrow("[PicoFlow] Primitive is disposed");
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it("should throw error when trigger is called after disposal", () => {
|
|
328
|
+
const $state = stateAsync(Promise.resolve(1));
|
|
329
|
+
$state.dispose();
|
|
330
|
+
expect(() => $state.trigger()).toThrow("[PicoFlow] Primitive is disposed");
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
describe("with effect", () => {
|
|
337
|
+
describe("get", () => {
|
|
338
|
+
it("should create reactive dependency when get is used in effect", async () => {
|
|
339
|
+
const $state = stateAsync(Promise.resolve(100));
|
|
340
|
+
const onData = vi.fn();
|
|
341
|
+
const onError = vi.fn();
|
|
342
|
+
|
|
343
|
+
subscribe((t) => $state.get(t), onData, onError);
|
|
344
|
+
|
|
345
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
346
|
+
await vi.waitFor(() => expect(onError).toHaveBeenCalledTimes(0));
|
|
347
|
+
expect(onData).toHaveBeenLastCalledWith(100);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it("should call effect with initial value", async () => {
|
|
351
|
+
const $state = stateAsync(Promise.resolve(1));
|
|
352
|
+
const onData = vi.fn();
|
|
353
|
+
const onError = vi.fn();
|
|
354
|
+
|
|
355
|
+
subscribe((t) => $state.get(t), onData, onError);
|
|
356
|
+
|
|
357
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
358
|
+
await vi.waitFor(() => expect(onError).toHaveBeenCalledTimes(0));
|
|
359
|
+
expect(onData).toHaveBeenLastCalledWith(1);
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it("should call effect with lazy init value", async () => {
|
|
363
|
+
const $state = stateAsync(async () => 1);
|
|
364
|
+
const onData = vi.fn();
|
|
365
|
+
const onError = vi.fn();
|
|
366
|
+
|
|
367
|
+
subscribe((t) => $state.get(t), onData, onError);
|
|
368
|
+
|
|
369
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
370
|
+
await vi.waitFor(() => expect(onError).toHaveBeenCalledTimes(0));
|
|
371
|
+
expect(onData).toHaveBeenLastCalledWith(1);
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it("should call effect when value is updated via set()", async () => {
|
|
375
|
+
const $state = stateAsync(Promise.resolve(1));
|
|
376
|
+
const onData = vi.fn();
|
|
377
|
+
const onError = vi.fn();
|
|
378
|
+
|
|
379
|
+
subscribe((t) => $state.get(t), onData, onError);
|
|
380
|
+
|
|
381
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
382
|
+
expect(onData).toHaveBeenLastCalledWith(1);
|
|
383
|
+
|
|
384
|
+
$state.set(Promise.resolve(2));
|
|
385
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
|
|
386
|
+
expect(onData).toHaveBeenLastCalledWith(2);
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
it("should not call effect when set() with same value", async () => {
|
|
390
|
+
const $state = stateAsync(Promise.resolve(1));
|
|
391
|
+
const onData = vi.fn();
|
|
392
|
+
const onError = vi.fn();
|
|
393
|
+
|
|
394
|
+
subscribe((t) => $state.get(t), onData, onError);
|
|
395
|
+
|
|
396
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
397
|
+
|
|
398
|
+
$state.set(Promise.resolve(2));
|
|
399
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
|
|
400
|
+
expect(onData).toHaveBeenLastCalledWith(2);
|
|
401
|
+
|
|
402
|
+
$state.set(Promise.resolve(2));
|
|
403
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
404
|
+
expect(onData).toHaveBeenCalledTimes(5);
|
|
405
|
+
expect(onData).toHaveBeenLastCalledWith(2);
|
|
406
|
+
expect(onError).toHaveBeenCalledTimes(0);
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
it("should not call effect after effect is disposed", async () => {
|
|
410
|
+
const $state = stateAsync(Promise.resolve(1));
|
|
411
|
+
const onData = vi.fn();
|
|
412
|
+
const onError = vi.fn();
|
|
413
|
+
const $effect = subscribe((t) => $state.get(t), onData, onError);
|
|
414
|
+
|
|
415
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
416
|
+
expect(onData).toHaveBeenLastCalledWith(1);
|
|
417
|
+
|
|
418
|
+
$state.set(Promise.resolve(2));
|
|
419
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
|
|
420
|
+
expect(onData).toHaveBeenLastCalledWith(2);
|
|
421
|
+
|
|
422
|
+
$effect.dispose();
|
|
423
|
+
|
|
424
|
+
$state.set(Promise.resolve(3));
|
|
425
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
426
|
+
expect(onData).toHaveBeenCalledTimes(3);
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
it("should support effect depending on multiple states", async () => {
|
|
430
|
+
const $stateA = stateAsync(Promise.resolve(5));
|
|
431
|
+
const $stateB = stateAsync(Promise.resolve(10));
|
|
432
|
+
const onData = vi.fn();
|
|
433
|
+
const onError = vi.fn();
|
|
434
|
+
|
|
435
|
+
subscribe(
|
|
436
|
+
(t) => ({ a: $stateA.get(t), b: $stateB.get(t) }),
|
|
437
|
+
(data) => onData(data.a, data.b),
|
|
438
|
+
onError,
|
|
439
|
+
);
|
|
440
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
441
|
+
expect(onData).toHaveBeenLastCalledWith(5, 10);
|
|
442
|
+
|
|
443
|
+
$stateA.set(Promise.resolve(6));
|
|
444
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
|
|
445
|
+
expect(onData).toHaveBeenLastCalledWith(6, 10);
|
|
446
|
+
|
|
447
|
+
$stateB.set(Promise.resolve(11));
|
|
448
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(5));
|
|
449
|
+
expect(onData).toHaveBeenLastCalledWith(6, 11);
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
it("should support multiple effects depending on same state", async () => {
|
|
453
|
+
const $state = stateAsync(Promise.resolve(200));
|
|
454
|
+
const onData1 = vi.fn();
|
|
455
|
+
const onData2 = vi.fn();
|
|
456
|
+
const onData3 = vi.fn();
|
|
457
|
+
|
|
458
|
+
const onError1 = vi.fn();
|
|
459
|
+
const onError2 = vi.fn();
|
|
460
|
+
const onError3 = vi.fn();
|
|
461
|
+
|
|
462
|
+
subscribe((t) => $state.get(t), onData1, onError1);
|
|
463
|
+
subscribe((t) => $state.get(t), onData2, onError2);
|
|
464
|
+
subscribe((t) => $state.get(t), onData3, onError3);
|
|
465
|
+
|
|
466
|
+
await vi.waitFor(() => {
|
|
467
|
+
expect(onData1).toHaveBeenCalledTimes(1);
|
|
468
|
+
expect(onData2).toHaveBeenCalledTimes(1);
|
|
469
|
+
expect(onData3).toHaveBeenCalledTimes(1);
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
expect(onError1).toHaveBeenCalledTimes(0);
|
|
473
|
+
expect(onError2).toHaveBeenCalledTimes(0);
|
|
474
|
+
expect(onError3).toHaveBeenCalledTimes(0);
|
|
475
|
+
|
|
476
|
+
expect(onData1).toHaveBeenLastCalledWith(200);
|
|
477
|
+
expect(onData2).toHaveBeenLastCalledWith(200);
|
|
478
|
+
expect(onData3).toHaveBeenLastCalledWith(200);
|
|
479
|
+
|
|
480
|
+
$state.set(Promise.resolve(300));
|
|
481
|
+
await vi.waitFor(() => {
|
|
482
|
+
expect(onData1).toHaveBeenCalledTimes(3);
|
|
483
|
+
expect(onData2).toHaveBeenCalledTimes(3);
|
|
484
|
+
expect(onData3).toHaveBeenCalledTimes(3);
|
|
485
|
+
});
|
|
486
|
+
});
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
describe("watch", () => {
|
|
490
|
+
it("should register dependency when watch is used in effect", async () => {
|
|
491
|
+
const $state = stateAsync(Promise.resolve(400));
|
|
492
|
+
const onData = vi.fn();
|
|
493
|
+
const onError = vi.fn();
|
|
494
|
+
|
|
495
|
+
subscribe((t) => $state.watch(t), onData, onError);
|
|
496
|
+
|
|
497
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
it("should trigger re-runs when state changes via set() after watch", async () => {
|
|
501
|
+
const $state = stateAsync(Promise.resolve(500));
|
|
502
|
+
const onData = vi.fn();
|
|
503
|
+
const onError = vi.fn();
|
|
504
|
+
|
|
505
|
+
subscribe((t) => $state.watch(t), onData, onError);
|
|
506
|
+
|
|
507
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
508
|
+
|
|
509
|
+
$state.set(Promise.resolve(600));
|
|
510
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
|
|
511
|
+
});
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
describe("error handling", () => {
|
|
515
|
+
describe("compute function errors", () => {
|
|
516
|
+
it("should propagate error when lazy init throws in effect", async () => {
|
|
517
|
+
const error = new Error("Effect init error");
|
|
518
|
+
const $state = stateAsync(async () => {
|
|
519
|
+
await Promise.resolve();
|
|
520
|
+
throw error;
|
|
521
|
+
});
|
|
522
|
+
const onData = vi.fn();
|
|
523
|
+
const onError = vi.fn();
|
|
524
|
+
|
|
525
|
+
subscribe((t) => $state.get(t), onData, onError);
|
|
526
|
+
|
|
527
|
+
await vi.waitFor(() => expect(onError).toHaveBeenCalledTimes(1));
|
|
528
|
+
expect(onData).toHaveBeenCalledTimes(0);
|
|
529
|
+
expect(onError).toHaveBeenLastCalledWith(error);
|
|
530
|
+
});
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
describe("disposed state", () => {
|
|
534
|
+
it("should throw error when creating an effect with a disposed state", async () => {
|
|
535
|
+
const $state = stateAsync(Promise.resolve(1));
|
|
536
|
+
const onData = vi.fn();
|
|
537
|
+
const onError = vi.fn();
|
|
538
|
+
|
|
539
|
+
$state.dispose();
|
|
540
|
+
|
|
541
|
+
subscribe((t) => $state.get(t), onData, onError);
|
|
542
|
+
|
|
543
|
+
await vi.waitFor(() => expect(onError).toHaveBeenCalledTimes(1));
|
|
544
|
+
expect(onData).toHaveBeenCalledTimes(0);
|
|
545
|
+
expect(onError).toHaveBeenLastCalledWith(expect.any(Error));
|
|
546
|
+
});
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
describe("set errors", () => {
|
|
550
|
+
it("should handle Promise rejection during set() in effect", async () => {
|
|
551
|
+
const $state = stateAsync(Promise.resolve(1));
|
|
552
|
+
const onData = vi.fn();
|
|
553
|
+
const onError = vi.fn();
|
|
554
|
+
|
|
555
|
+
subscribe((t) => $state.get(t), onData, onError);
|
|
556
|
+
|
|
557
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
558
|
+
|
|
559
|
+
const error = new Error("Set error");
|
|
560
|
+
$state.set(Promise.reject(error));
|
|
561
|
+
|
|
562
|
+
await vi.waitFor(() => expect(onError).toHaveBeenCalledTimes(2));
|
|
563
|
+
expect(onError).toHaveBeenLastCalledWith(error);
|
|
564
|
+
});
|
|
565
|
+
});
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
describe("disposal", () => {
|
|
569
|
+
it("should not dispose effects when state is disposed", async () => {
|
|
570
|
+
const $state = stateAsync(Promise.resolve(1400));
|
|
571
|
+
const onData = vi.fn();
|
|
572
|
+
const onError = vi.fn();
|
|
573
|
+
|
|
574
|
+
const $effect = subscribe((t) => $state.get(t), onData, onError);
|
|
575
|
+
|
|
576
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
577
|
+
expect($effect.disposed).toBe(false);
|
|
578
|
+
|
|
579
|
+
$state.dispose();
|
|
580
|
+
|
|
581
|
+
expect($effect.disposed).toBe(false);
|
|
582
|
+
expect($state.disposed).toBe(true);
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
it("should unregister effects when state is disposed", async () => {
|
|
586
|
+
const $state = stateAsync(Promise.resolve(1500));
|
|
587
|
+
const onData = vi.fn();
|
|
588
|
+
const onError = vi.fn();
|
|
589
|
+
|
|
590
|
+
const $effect = subscribe((t) => $state.get(t), onData, onError);
|
|
591
|
+
|
|
592
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
593
|
+
|
|
594
|
+
$state.dispose();
|
|
595
|
+
|
|
596
|
+
// Effect should still be active but not notified
|
|
597
|
+
expect($effect.disposed).toBe(false);
|
|
598
|
+
|
|
599
|
+
// But state is disposed so operations should fail
|
|
600
|
+
await expect($state.pick()).rejects.toThrow("[PicoFlow] Primitive is disposed");
|
|
601
|
+
});
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
describe("complex cases", () => {
|
|
605
|
+
it("should handle nested states in effects with set()", async () => {
|
|
606
|
+
const $stateA = stateAsync(Promise.resolve(1));
|
|
607
|
+
const $stateB = stateAsync(Promise.resolve(2));
|
|
608
|
+
const $stateC = stateAsync(
|
|
609
|
+
Promise.resolve({
|
|
610
|
+
a: $stateA,
|
|
611
|
+
b: $stateB,
|
|
612
|
+
}),
|
|
613
|
+
);
|
|
614
|
+
|
|
615
|
+
const onData = vi.fn();
|
|
616
|
+
const onError = vi.fn();
|
|
617
|
+
|
|
618
|
+
subscribe(
|
|
619
|
+
(t) => ({
|
|
620
|
+
a: $stateC.get(t).a.get(t),
|
|
621
|
+
b: $stateC.get(t).b.get(t),
|
|
622
|
+
}),
|
|
623
|
+
(data) => onData(data.a, data.b),
|
|
624
|
+
onError,
|
|
625
|
+
);
|
|
626
|
+
|
|
627
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
628
|
+
expect(onData).toHaveBeenLastCalledWith(1, 2);
|
|
629
|
+
|
|
630
|
+
$stateA.set(Promise.resolve(3));
|
|
631
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
|
|
632
|
+
expect(onData).toHaveBeenLastCalledWith(3, 2);
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
it("should handle effect depending on multiple states with set()", async () => {
|
|
636
|
+
const $stateA = stateAsync(Promise.resolve(10));
|
|
637
|
+
const $stateB = stateAsync(Promise.resolve(20));
|
|
638
|
+
const $stateC = stateAsync(Promise.resolve(30));
|
|
639
|
+
const onData = vi.fn();
|
|
640
|
+
const onError = vi.fn();
|
|
641
|
+
|
|
642
|
+
subscribe(
|
|
643
|
+
(t) => ({
|
|
644
|
+
a: $stateA.get(t),
|
|
645
|
+
b: $stateB.get(t),
|
|
646
|
+
c: $stateC.get(t),
|
|
647
|
+
}),
|
|
648
|
+
(data) => onData(data.a, data.b, data.c),
|
|
649
|
+
onError,
|
|
650
|
+
);
|
|
651
|
+
|
|
652
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
653
|
+
expect(onData).toHaveBeenLastCalledWith(10, 20, 30);
|
|
654
|
+
|
|
655
|
+
$stateA.set(Promise.resolve(11));
|
|
656
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
|
|
657
|
+
expect(onData).toHaveBeenLastCalledWith(11, 20, 30);
|
|
658
|
+
|
|
659
|
+
$stateB.set(Promise.resolve(21));
|
|
660
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(5));
|
|
661
|
+
expect(onData).toHaveBeenLastCalledWith(11, 21, 30);
|
|
662
|
+
});
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
describe("execution order", () => {
|
|
666
|
+
it("should execute multiple effects in order", async () => {
|
|
667
|
+
const $state = stateAsync(Promise.resolve(1));
|
|
668
|
+
const onData = vi.fn();
|
|
669
|
+
|
|
670
|
+
subscribe((t) => `effect1-${$state.get(t)}`, onData);
|
|
671
|
+
|
|
672
|
+
subscribe((t) => `effect2-${$state.get(t)}`, onData);
|
|
673
|
+
|
|
674
|
+
subscribe((t) => `effect3-${$state.get(t)}`, onData);
|
|
675
|
+
|
|
676
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
|
|
677
|
+
|
|
678
|
+
expect(onData).toHaveBeenNthCalledWith(1, "effect1-1");
|
|
679
|
+
expect(onData).toHaveBeenNthCalledWith(2, "effect2-1");
|
|
680
|
+
expect(onData).toHaveBeenNthCalledWith(3, "effect3-1");
|
|
681
|
+
});
|
|
682
|
+
|
|
683
|
+
it("should handle async set() in effects", async () => {
|
|
684
|
+
const $state = stateAsync(Promise.resolve(1));
|
|
685
|
+
const onData = vi.fn();
|
|
686
|
+
|
|
687
|
+
subscribe((t) => `effect-${$state.get(t)}`, onData);
|
|
688
|
+
|
|
689
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
690
|
+
|
|
691
|
+
onData("before-set");
|
|
692
|
+
$state.set(
|
|
693
|
+
(async () => {
|
|
694
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
695
|
+
return 2;
|
|
696
|
+
})(),
|
|
697
|
+
);
|
|
698
|
+
onData("after-set");
|
|
699
|
+
|
|
700
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(4));
|
|
701
|
+
expect(onData).toHaveBeenNthCalledWith(1, "effect-1");
|
|
702
|
+
expect(onData).toHaveBeenNthCalledWith(2, "before-set");
|
|
703
|
+
expect(onData).toHaveBeenNthCalledWith(3, "after-set");
|
|
704
|
+
expect(onData).toHaveBeenNthCalledWith(4, "effect-2");
|
|
705
|
+
});
|
|
706
|
+
});
|
|
707
|
+
});
|
|
708
|
+
});
|