@ersbeth/picoflow 1.1.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +857 -1528
- 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 -53
- 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 -139
- 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,652 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { constantAsync, subscribe } from "~";
|
|
3
|
+
import { EffectNode } from "~/nodes";
|
|
4
|
+
|
|
5
|
+
describe("flowConstantAsync", () => {
|
|
6
|
+
describe("unit", () => {
|
|
7
|
+
describe("initialization / pick", () => {
|
|
8
|
+
it("should initialize with direct Promise", async () => {
|
|
9
|
+
const $constant = constantAsync(Promise.resolve(1));
|
|
10
|
+
expect(await $constant.pick()).toBe(1);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should initialize lazily with function", async () => {
|
|
14
|
+
const initFn = vi.fn(() => Promise.resolve(42));
|
|
15
|
+
const $constant = constantAsync(initFn);
|
|
16
|
+
|
|
17
|
+
// Function should not be called yet
|
|
18
|
+
expect(initFn).not.toHaveBeenCalled();
|
|
19
|
+
|
|
20
|
+
// First access triggers initialization
|
|
21
|
+
const value = await $constant.pick();
|
|
22
|
+
expect(value).toBe(42);
|
|
23
|
+
expect(initFn).toHaveBeenCalledTimes(1);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("should compute initial value lazily on first access", async () => {
|
|
27
|
+
const computeFn = vi.fn(() => Promise.resolve(42));
|
|
28
|
+
const $constant = constantAsync(computeFn);
|
|
29
|
+
|
|
30
|
+
// Function should not be called yet
|
|
31
|
+
expect(computeFn).not.toHaveBeenCalled();
|
|
32
|
+
|
|
33
|
+
// First access triggers computation
|
|
34
|
+
const value = await $constant.pick();
|
|
35
|
+
expect(value).toBe(42);
|
|
36
|
+
expect(computeFn).toHaveBeenCalledTimes(1);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("should call initializer function only once", async () => {
|
|
40
|
+
const computeFn = vi.fn(() => Promise.resolve(100));
|
|
41
|
+
const $constant = constantAsync(computeFn);
|
|
42
|
+
|
|
43
|
+
// Multiple accesses should only call compute once
|
|
44
|
+
await $constant.pick();
|
|
45
|
+
await $constant.pick();
|
|
46
|
+
await $constant.pick();
|
|
47
|
+
|
|
48
|
+
expect(computeFn).toHaveBeenCalledTimes(1);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("should cache Promise after initialization", async () => {
|
|
52
|
+
const computeFn = vi.fn(() => Promise.resolve("cached"));
|
|
53
|
+
const $constant = constantAsync(computeFn);
|
|
54
|
+
|
|
55
|
+
const value1 = await $constant.pick();
|
|
56
|
+
const value2 = await $constant.pick();
|
|
57
|
+
const value3 = await $constant.pick();
|
|
58
|
+
|
|
59
|
+
expect(value1).toBe("cached");
|
|
60
|
+
expect(value2).toBe("cached");
|
|
61
|
+
expect(value3).toBe("cached");
|
|
62
|
+
expect(computeFn).toHaveBeenCalledTimes(1);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("should handle initializer function using closure to capture values", async () => {
|
|
66
|
+
let externalValue = 10;
|
|
67
|
+
const $constant = constantAsync(() => {
|
|
68
|
+
// Closure captures external value at computation time
|
|
69
|
+
return Promise.resolve(externalValue * 2);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Constant computes once with captured value
|
|
73
|
+
expect(await $constant.pick()).toBe(20);
|
|
74
|
+
|
|
75
|
+
// Changing external value should not affect constant (it's cached)
|
|
76
|
+
externalValue = 20;
|
|
77
|
+
expect(await $constant.pick()).toBe(20); // Still cached value
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("should handle number values", async () => {
|
|
81
|
+
const $constant = constantAsync(Promise.resolve(42));
|
|
82
|
+
expect(await $constant.pick()).toBe(42);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("should handle string values", async () => {
|
|
86
|
+
const $constant = constantAsync(Promise.resolve("hello"));
|
|
87
|
+
expect(await $constant.pick()).toBe("hello");
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("should handle object values", async () => {
|
|
91
|
+
const obj = { a: 1, b: 2 };
|
|
92
|
+
const $constant = constantAsync(Promise.resolve(obj));
|
|
93
|
+
const value = await $constant.pick();
|
|
94
|
+
expect(value).toBe(obj);
|
|
95
|
+
expect(value).toEqual({ a: 1, b: 2 });
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("should handle array values", async () => {
|
|
99
|
+
const arr = [1, 2, 3];
|
|
100
|
+
const $constant = constantAsync(Promise.resolve(arr));
|
|
101
|
+
const value = await $constant.pick();
|
|
102
|
+
expect(value).toBe(arr);
|
|
103
|
+
expect(value).toEqual([1, 2, 3]);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("should handle undefined values", async () => {
|
|
107
|
+
const $constant = constantAsync(Promise.resolve(undefined));
|
|
108
|
+
const value = await $constant.pick();
|
|
109
|
+
expect(value).toBeUndefined();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("should handle null values", async () => {
|
|
113
|
+
const $constant = constantAsync(Promise.resolve(null));
|
|
114
|
+
const value = await $constant.pick();
|
|
115
|
+
expect(value).toBeNull();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe("error handling", () => {
|
|
119
|
+
it("pick should throw error when pick is called after disposal", async () => {
|
|
120
|
+
const $constant = constantAsync(Promise.resolve(1));
|
|
121
|
+
|
|
122
|
+
expect(await $constant.pick()).toBe(1);
|
|
123
|
+
|
|
124
|
+
$constant.dispose();
|
|
125
|
+
|
|
126
|
+
await expect($constant.pick()).rejects.toThrow("[PicoFlow] Primitive is disposed");
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("should throw error when subscribe is called after disposal", () => {
|
|
130
|
+
const $constant = constantAsync(Promise.resolve(1));
|
|
131
|
+
const onData = vi.fn();
|
|
132
|
+
|
|
133
|
+
$constant.dispose();
|
|
134
|
+
|
|
135
|
+
expect(() => $constant.subscribe(onData)).toThrow("[PicoFlow] Primitive is disposed");
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("should propagate error when pick is called on rejecting Promise", async () => {
|
|
139
|
+
const error = new Error("Compute error");
|
|
140
|
+
const $constant = constantAsync(Promise.reject(error));
|
|
141
|
+
|
|
142
|
+
await expect($constant.pick()).rejects.toThrow("Compute error");
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("should propagate error when pick is called on rejecting initializer function", async () => {
|
|
146
|
+
const error = new Error("Compute error");
|
|
147
|
+
const $constant = constantAsync(() => Promise.reject(error));
|
|
148
|
+
|
|
149
|
+
await expect($constant.pick()).rejects.toThrow("Compute error");
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
describe("pick", () => {
|
|
155
|
+
it("should return Promise without tracking", async () => {
|
|
156
|
+
const $constant = constantAsync(Promise.resolve(15));
|
|
157
|
+
const promise = $constant.pick();
|
|
158
|
+
|
|
159
|
+
expect(promise).toBeInstanceOf(Promise);
|
|
160
|
+
const value = await promise;
|
|
161
|
+
expect(value).toBe(15);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("should compute lazy value on first pick call", async () => {
|
|
165
|
+
const initFn = vi.fn(() => Promise.resolve(25));
|
|
166
|
+
const $constant = constantAsync(initFn);
|
|
167
|
+
|
|
168
|
+
expect(initFn).not.toHaveBeenCalled();
|
|
169
|
+
const promise = $constant.pick();
|
|
170
|
+
expect(promise).toBeInstanceOf(Promise);
|
|
171
|
+
const value = await promise;
|
|
172
|
+
expect(value).toBe(25);
|
|
173
|
+
expect(initFn).toHaveBeenCalledTimes(1);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it("should return cached Promise on subsequent pick calls", async () => {
|
|
177
|
+
const initFn = vi.fn(() => Promise.resolve(30));
|
|
178
|
+
const $constant = constantAsync(initFn);
|
|
179
|
+
|
|
180
|
+
const promise1 = $constant.pick();
|
|
181
|
+
const promise2 = $constant.pick();
|
|
182
|
+
const promise3 = $constant.pick();
|
|
183
|
+
|
|
184
|
+
const value1 = await promise1;
|
|
185
|
+
const value2 = await promise2;
|
|
186
|
+
const value3 = await promise3;
|
|
187
|
+
|
|
188
|
+
expect(value1).toBe(30);
|
|
189
|
+
expect(value2).toBe(30);
|
|
190
|
+
expect(value3).toBe(30);
|
|
191
|
+
expect(initFn).toHaveBeenCalledTimes(1);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("should await Promise to get value", async () => {
|
|
195
|
+
const $constant = constantAsync(Promise.resolve(35));
|
|
196
|
+
const value = await $constant.pick();
|
|
197
|
+
expect(value).toBe(35);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("should throw error when pick is called after disposal", async () => {
|
|
201
|
+
const $constant = constantAsync(Promise.resolve(1));
|
|
202
|
+
|
|
203
|
+
expect(await $constant.pick()).toBe(1);
|
|
204
|
+
|
|
205
|
+
$constant.dispose();
|
|
206
|
+
|
|
207
|
+
await expect($constant.pick()).rejects.toThrow("[PicoFlow] Primitive is disposed");
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
describe("subscribe", () => {
|
|
212
|
+
it("should return an effect", () => {
|
|
213
|
+
const $constant = constantAsync(Promise.resolve(50));
|
|
214
|
+
const onData = vi.fn();
|
|
215
|
+
const effect = $constant.subscribe((value) => onData(value));
|
|
216
|
+
expect(effect).toBeInstanceOf(EffectNode);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("should call onData immediately with T", async () => {
|
|
220
|
+
const $constant = constantAsync(Promise.resolve(55));
|
|
221
|
+
const onData = vi.fn();
|
|
222
|
+
|
|
223
|
+
$constant.subscribe(onData);
|
|
224
|
+
|
|
225
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
226
|
+
expect(onData).toHaveBeenCalledTimes(1);
|
|
227
|
+
expect(onData).toHaveBeenLastCalledWith(55);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it("should not call onData after constant disposal", async () => {
|
|
231
|
+
const $constant = constantAsync(Promise.resolve(65));
|
|
232
|
+
const onData = vi.fn();
|
|
233
|
+
|
|
234
|
+
$constant.subscribe(onData);
|
|
235
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
236
|
+
|
|
237
|
+
$constant.dispose();
|
|
238
|
+
|
|
239
|
+
// Wait to ensure onData is not called again
|
|
240
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
241
|
+
expect(onData).toHaveBeenCalledTimes(1);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it("should not call onData after disposer is called", async () => {
|
|
245
|
+
const $constant = constantAsync(Promise.resolve(70));
|
|
246
|
+
const onData = vi.fn();
|
|
247
|
+
|
|
248
|
+
const effect = $constant.subscribe(onData);
|
|
249
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
250
|
+
|
|
251
|
+
effect.dispose();
|
|
252
|
+
|
|
253
|
+
// Wait to ensure onData is not called again
|
|
254
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
255
|
+
expect(onData).toHaveBeenCalledTimes(1);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it("should support multiple subscriptions", async () => {
|
|
259
|
+
const $constant = constantAsync(Promise.resolve(75));
|
|
260
|
+
const onData1 = vi.fn();
|
|
261
|
+
const onData2 = vi.fn();
|
|
262
|
+
const onData3 = vi.fn();
|
|
263
|
+
|
|
264
|
+
$constant.subscribe(onData1);
|
|
265
|
+
$constant.subscribe(onData2);
|
|
266
|
+
$constant.subscribe(onData3);
|
|
267
|
+
|
|
268
|
+
await vi.waitFor(() => {
|
|
269
|
+
expect(onData1).toHaveBeenCalledTimes(1);
|
|
270
|
+
expect(onData2).toHaveBeenCalledTimes(1);
|
|
271
|
+
expect(onData3).toHaveBeenCalledTimes(1);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
expect(onData1).toHaveBeenLastCalledWith(75);
|
|
275
|
+
expect(onData2).toHaveBeenLastCalledWith(75);
|
|
276
|
+
expect(onData3).toHaveBeenLastCalledWith(75);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
describe("error handling", () => {
|
|
280
|
+
it("should throw error when subscribe is called after disposal", () => {
|
|
281
|
+
const $constant = constantAsync(Promise.resolve(1));
|
|
282
|
+
const onData = vi.fn();
|
|
283
|
+
|
|
284
|
+
$constant.dispose();
|
|
285
|
+
expect(() => $constant.subscribe(onData)).toThrow("[PicoFlow] Primitive is disposed");
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
describe("disposal", () => {
|
|
291
|
+
it("should have disposed property set to false initially", () => {
|
|
292
|
+
const $constant = constantAsync(Promise.resolve(1));
|
|
293
|
+
expect($constant.disposed).toBe(false);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it("should have disposed property set to true after disposal", () => {
|
|
297
|
+
const $constant = constantAsync(Promise.resolve(1));
|
|
298
|
+
$constant.dispose();
|
|
299
|
+
expect($constant.disposed).toBe(true);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it("should accept self option without throwing", () => {
|
|
303
|
+
const $constant = constantAsync(Promise.resolve(1));
|
|
304
|
+
expect(() => $constant.dispose()).not.toThrow();
|
|
305
|
+
expect($constant.disposed).toBe(true);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it("should accept default options without throwing", () => {
|
|
309
|
+
const $constant = constantAsync(Promise.resolve(1));
|
|
310
|
+
expect(() => $constant.dispose()).not.toThrow();
|
|
311
|
+
expect($constant.disposed).toBe(true);
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
describe("error handling", () => {
|
|
315
|
+
it("should throw error when disposed twice", () => {
|
|
316
|
+
const $constant = constantAsync(Promise.resolve(1));
|
|
317
|
+
$constant.dispose();
|
|
318
|
+
expect(() => $constant.dispose()).toThrow("[PicoFlow] Primitive is disposed");
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
describe("special cases", () => {
|
|
324
|
+
it("should handle lazy function using closure to capture values", async () => {
|
|
325
|
+
let externalValue = 10;
|
|
326
|
+
const $constant = constantAsync(() => Promise.resolve(externalValue * 2));
|
|
327
|
+
|
|
328
|
+
const value1 = await $constant.pick();
|
|
329
|
+
expect(value1).toBe(20);
|
|
330
|
+
|
|
331
|
+
// Changing external value should not affect constant (it's cached)
|
|
332
|
+
externalValue = 20;
|
|
333
|
+
const value2 = await $constant.pick();
|
|
334
|
+
expect(value2).toBe(20);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it("should handle Promise that rejects", async () => {
|
|
338
|
+
const error = new Error("Promise rejected");
|
|
339
|
+
const $constant = constantAsync(Promise.reject(error));
|
|
340
|
+
|
|
341
|
+
await expect($constant.pick()).rejects.toThrow("Promise rejected");
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it("should handle lazy function that rejects", async () => {
|
|
345
|
+
const error = new Error("Lazy function rejected");
|
|
346
|
+
const $constant = constantAsync(() => Promise.reject(error));
|
|
347
|
+
|
|
348
|
+
await expect($constant.pick()).rejects.toThrow("Lazy function rejected");
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it("should handle Promise that resolves to null", async () => {
|
|
352
|
+
const $constant = constantAsync(Promise.resolve(null));
|
|
353
|
+
const value = await $constant.pick();
|
|
354
|
+
expect(value).toBeNull();
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it("should handle Promise that resolves to undefined", async () => {
|
|
358
|
+
const $constant = constantAsync(Promise.resolve(undefined));
|
|
359
|
+
const value = await $constant.pick();
|
|
360
|
+
expect(value).toBeUndefined();
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
it("should handle complex object values in Promise", async () => {
|
|
364
|
+
const complexObj = {
|
|
365
|
+
nested: { deep: { value: 42 } },
|
|
366
|
+
array: [1, 2, 3],
|
|
367
|
+
};
|
|
368
|
+
const $constant = constantAsync(Promise.resolve(complexObj));
|
|
369
|
+
const value = await $constant.pick();
|
|
370
|
+
expect(value).toBe(complexObj);
|
|
371
|
+
expect(value.nested.deep.value).toBe(42);
|
|
372
|
+
expect(value.array).toEqual([1, 2, 3]);
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
describe("error handling", () => {
|
|
377
|
+
describe("compute function errors", () => {
|
|
378
|
+
it("should propagate error when pick is called", async () => {
|
|
379
|
+
const error = new Error("Compute error");
|
|
380
|
+
const $constant = constantAsync(Promise.reject<never>(error));
|
|
381
|
+
|
|
382
|
+
await expect($constant.pick()).rejects.toThrow("Compute error");
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
describe("disposed constant", () => {
|
|
387
|
+
it("should throw error when pick is called after disposal", async () => {
|
|
388
|
+
const $constant = constantAsync(Promise.resolve(1));
|
|
389
|
+
|
|
390
|
+
$constant.dispose();
|
|
391
|
+
|
|
392
|
+
await expect($constant.pick()).rejects.toThrow("[PicoFlow] Primitive is disposed");
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
describe("with effect", () => {
|
|
399
|
+
describe("get", () => {
|
|
400
|
+
it("should create reactive dependency when get is used in effect", async () => {
|
|
401
|
+
const $constant = constantAsync(Promise.resolve(100));
|
|
402
|
+
const onData = vi.fn();
|
|
403
|
+
const onError = vi.fn();
|
|
404
|
+
|
|
405
|
+
subscribe((t) => $constant.get(t), onData, onError);
|
|
406
|
+
|
|
407
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
408
|
+
expect(onError).toHaveBeenCalledTimes(0);
|
|
409
|
+
expect(onData).toHaveBeenLastCalledWith(100);
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
it("should call effect with initial value", async () => {
|
|
413
|
+
const $constant = constantAsync(Promise.resolve(1));
|
|
414
|
+
const onData = vi.fn();
|
|
415
|
+
const onError = vi.fn();
|
|
416
|
+
|
|
417
|
+
subscribe((t) => $constant.get(t), onData, onError);
|
|
418
|
+
|
|
419
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
420
|
+
expect(onError).toHaveBeenCalledTimes(0);
|
|
421
|
+
expect(onData).toHaveBeenLastCalledWith(1);
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
it("should call effect with lazy init value", async () => {
|
|
425
|
+
const $constant = constantAsync(() => Promise.resolve(1));
|
|
426
|
+
const onData = vi.fn();
|
|
427
|
+
const onError = vi.fn();
|
|
428
|
+
|
|
429
|
+
subscribe((t) => $constant.get(t), onData, onError);
|
|
430
|
+
|
|
431
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
432
|
+
expect(onError).toHaveBeenCalledTimes(0);
|
|
433
|
+
expect(onData).toHaveBeenLastCalledWith(1);
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
it("should not re-execute effect when constant value does not change", async () => {
|
|
437
|
+
const $constant = constantAsync(Promise.resolve(300));
|
|
438
|
+
const onData = vi.fn();
|
|
439
|
+
const onError = vi.fn();
|
|
440
|
+
|
|
441
|
+
subscribe((t) => $constant.get(t), onData, onError);
|
|
442
|
+
|
|
443
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
444
|
+
await vi.waitFor(() => expect(onError).toHaveBeenCalledTimes(0));
|
|
445
|
+
// Wait to ensure effect doesn't re-run (constant is immutable)
|
|
446
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
447
|
+
expect(onData).toHaveBeenCalledTimes(1);
|
|
448
|
+
expect(onError).toHaveBeenCalledTimes(0);
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
it("should not re-execute effect when async constant value is immutable (closure)", async () => {
|
|
452
|
+
let capturedValue = 5;
|
|
453
|
+
const $constant = constantAsync(() => Promise.resolve(capturedValue * 3));
|
|
454
|
+
|
|
455
|
+
const onData = vi.fn();
|
|
456
|
+
const onError = vi.fn();
|
|
457
|
+
|
|
458
|
+
subscribe((t) => $constant.get(t), onData, onError);
|
|
459
|
+
|
|
460
|
+
// Initial execution with computed value (5 * 3 = 15)
|
|
461
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
462
|
+
expect(onData).toHaveBeenLastCalledWith(15);
|
|
463
|
+
|
|
464
|
+
// Change captured value - constant is cached, so effect should not re-run
|
|
465
|
+
capturedValue = 10;
|
|
466
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
467
|
+
|
|
468
|
+
// Effect should not re-run because constant is immutable and cached
|
|
469
|
+
expect(onData).toHaveBeenCalledTimes(1);
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
it("should support multiple effects depending on same constant", async () => {
|
|
473
|
+
const $constant = constantAsync(Promise.resolve(400));
|
|
474
|
+
const onData1 = vi.fn();
|
|
475
|
+
const onData2 = vi.fn();
|
|
476
|
+
const onData3 = vi.fn();
|
|
477
|
+
|
|
478
|
+
const onError1 = vi.fn();
|
|
479
|
+
const onError2 = vi.fn();
|
|
480
|
+
const onError3 = vi.fn();
|
|
481
|
+
|
|
482
|
+
subscribe((t) => $constant.get(t), onData1, onError1);
|
|
483
|
+
|
|
484
|
+
subscribe((t) => $constant.get(t), onData2, onError2);
|
|
485
|
+
|
|
486
|
+
subscribe((t) => $constant.get(t), onData3, onError3);
|
|
487
|
+
|
|
488
|
+
await vi.waitFor(() => {
|
|
489
|
+
expect(onData1).toHaveBeenCalledTimes(1);
|
|
490
|
+
expect(onData2).toHaveBeenCalledTimes(1);
|
|
491
|
+
expect(onData3).toHaveBeenCalledTimes(1);
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
expect(onError1).toHaveBeenCalledTimes(0);
|
|
495
|
+
expect(onError2).toHaveBeenCalledTimes(0);
|
|
496
|
+
expect(onError3).toHaveBeenCalledTimes(0);
|
|
497
|
+
|
|
498
|
+
expect(onData1).toHaveBeenLastCalledWith(400);
|
|
499
|
+
expect(onData2).toHaveBeenLastCalledWith(400);
|
|
500
|
+
expect(onData3).toHaveBeenLastCalledWith(400);
|
|
501
|
+
});
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
describe("watch", () => {
|
|
505
|
+
it("should register dependency when watch is used in effect", async () => {
|
|
506
|
+
const $constant = constantAsync(Promise.resolve(500));
|
|
507
|
+
const onData = vi.fn();
|
|
508
|
+
const onError = vi.fn();
|
|
509
|
+
|
|
510
|
+
subscribe(
|
|
511
|
+
(t) => {
|
|
512
|
+
$constant.watch(t);
|
|
513
|
+
},
|
|
514
|
+
onData,
|
|
515
|
+
onError,
|
|
516
|
+
);
|
|
517
|
+
|
|
518
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
it("should not trigger re-runs when constant is watched (immutable)", async () => {
|
|
522
|
+
const $constant = constantAsync(Promise.resolve(600));
|
|
523
|
+
const onData = vi.fn();
|
|
524
|
+
const onError = vi.fn();
|
|
525
|
+
|
|
526
|
+
subscribe(
|
|
527
|
+
(t) => {
|
|
528
|
+
$constant.watch(t);
|
|
529
|
+
},
|
|
530
|
+
onData,
|
|
531
|
+
onError,
|
|
532
|
+
);
|
|
533
|
+
|
|
534
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
535
|
+
|
|
536
|
+
// Wait to ensure effect doesn't re-run
|
|
537
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
538
|
+
expect(onData).toHaveBeenCalledTimes(1);
|
|
539
|
+
});
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
describe("disposal", () => {
|
|
543
|
+
it("should not dispose effects when constant is disposed", async () => {
|
|
544
|
+
const $constant = constantAsync(Promise.resolve(1200));
|
|
545
|
+
const onData = vi.fn();
|
|
546
|
+
const onError = vi.fn();
|
|
547
|
+
const $effect = subscribe(
|
|
548
|
+
(t) => {
|
|
549
|
+
$constant.get(t);
|
|
550
|
+
},
|
|
551
|
+
onData,
|
|
552
|
+
onError,
|
|
553
|
+
);
|
|
554
|
+
|
|
555
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
556
|
+
expect($effect.disposed).toBe(false);
|
|
557
|
+
|
|
558
|
+
$constant.dispose();
|
|
559
|
+
|
|
560
|
+
expect($effect.disposed).toBe(false);
|
|
561
|
+
expect($constant.disposed).toBe(true);
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
it("should unregister effects when constant is disposed", async () => {
|
|
565
|
+
const $constant = constantAsync(Promise.resolve(1300));
|
|
566
|
+
const onData = vi.fn();
|
|
567
|
+
const onError = vi.fn();
|
|
568
|
+
|
|
569
|
+
const $effect = subscribe(
|
|
570
|
+
(t) => {
|
|
571
|
+
$constant.get(t);
|
|
572
|
+
},
|
|
573
|
+
onData,
|
|
574
|
+
onError,
|
|
575
|
+
);
|
|
576
|
+
|
|
577
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
578
|
+
|
|
579
|
+
$constant.dispose();
|
|
580
|
+
|
|
581
|
+
// Effect should still be active but not notified
|
|
582
|
+
expect($effect.disposed).toBe(false);
|
|
583
|
+
|
|
584
|
+
// But constant is disposed so operations should fail
|
|
585
|
+
await expect($constant.pick()).rejects.toThrow("[PicoFlow] Primitive is disposed");
|
|
586
|
+
});
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
describe("error handling", () => {
|
|
590
|
+
describe("compute function errors", () => {
|
|
591
|
+
it("should propagate error when used inside an async effect", async () => {
|
|
592
|
+
const error = new Error("Effect compute error");
|
|
593
|
+
const $constant = constantAsync(() => Promise.reject<never>(error));
|
|
594
|
+
const onData = vi.fn();
|
|
595
|
+
const onError = vi.fn();
|
|
596
|
+
|
|
597
|
+
subscribe((t) => $constant.get(t), onData, onError);
|
|
598
|
+
|
|
599
|
+
// Wait for the effect to settle and check for error
|
|
600
|
+
await vi.waitFor(() => expect(onError).toHaveBeenCalledTimes(1));
|
|
601
|
+
expect(onData).toHaveBeenCalledTimes(0);
|
|
602
|
+
expect(onError).toHaveBeenCalledTimes(1);
|
|
603
|
+
expect(onError).toHaveBeenLastCalledWith(error);
|
|
604
|
+
});
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
describe("disposed constant", () => {
|
|
608
|
+
it("should throw error when creating an effect with a disposed async constant", async () => {
|
|
609
|
+
const $constant = constantAsync(Promise.resolve(1));
|
|
610
|
+
const onData = vi.fn();
|
|
611
|
+
const onError = vi.fn();
|
|
612
|
+
|
|
613
|
+
$constant.dispose();
|
|
614
|
+
|
|
615
|
+
subscribe((t) => $constant.get(t), onData, onError);
|
|
616
|
+
|
|
617
|
+
await vi.waitFor(() => expect(onError).toHaveBeenCalledTimes(1));
|
|
618
|
+
expect(onData).toHaveBeenCalledTimes(0);
|
|
619
|
+
expect(onError).toHaveBeenLastCalledWith(expect.any(Error));
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
it("should throw error when watching a disposed constant", async () => {
|
|
623
|
+
const $constant = constantAsync(Promise.resolve(1));
|
|
624
|
+
const onData = vi.fn();
|
|
625
|
+
const onError = vi.fn();
|
|
626
|
+
|
|
627
|
+
$constant.dispose();
|
|
628
|
+
|
|
629
|
+
subscribe((t) => $constant.watch(t), onData, onError);
|
|
630
|
+
|
|
631
|
+
await vi.waitFor(() => expect(onError).toHaveBeenCalledTimes(1));
|
|
632
|
+
expect(onData).toHaveBeenCalledTimes(0);
|
|
633
|
+
expect(onError).toHaveBeenLastCalledWith(expect.any(Error));
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
it("should throw error when getting a disposed constant", async () => {
|
|
637
|
+
const $constant = constantAsync(Promise.resolve(1));
|
|
638
|
+
const onData = vi.fn();
|
|
639
|
+
const onError = vi.fn();
|
|
640
|
+
|
|
641
|
+
$constant.dispose();
|
|
642
|
+
|
|
643
|
+
subscribe((t) => $constant.get(t), onData, onError);
|
|
644
|
+
|
|
645
|
+
await vi.waitFor(() => expect(onError).toHaveBeenCalledTimes(1));
|
|
646
|
+
expect(onData).toHaveBeenCalledTimes(0);
|
|
647
|
+
expect(onError).toHaveBeenLastCalledWith(expect.any(Error));
|
|
648
|
+
});
|
|
649
|
+
});
|
|
650
|
+
});
|
|
651
|
+
});
|
|
652
|
+
});
|