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