@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,961 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { array, subscribe } from "~";
|
|
3
|
+
|
|
4
|
+
describe("FlowArray", () => {
|
|
5
|
+
describe("unit", () => {
|
|
6
|
+
describe("initialization", () => {
|
|
7
|
+
it("should initialize with provided values", async () => {
|
|
8
|
+
const $array = array([1, 2, 3]);
|
|
9
|
+
|
|
10
|
+
expect(await $array.pick()).toEqual([1, 2, 3]);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should initialize with empty array when no value provided", async () => {
|
|
14
|
+
const $array = array<number>();
|
|
15
|
+
|
|
16
|
+
expect(await $array.pick()).toEqual([]);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe("disposal", () => {
|
|
21
|
+
it("should have disposed property set to false initially and true after disposal", () => {
|
|
22
|
+
const $array = array([1, 2, 3]);
|
|
23
|
+
expect($array.disposed).toBe(false);
|
|
24
|
+
$array.dispose();
|
|
25
|
+
expect($array.disposed).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should throw error when disposed twice", () => {
|
|
29
|
+
const $array = array([1, 2, 3]);
|
|
30
|
+
$array.dispose();
|
|
31
|
+
expect(() => $array.dispose()).toThrow("[PicoFlow] Primitive is disposed");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("should throw when pick is called after disposal", async () => {
|
|
35
|
+
const $array = array([1, 2, 3]);
|
|
36
|
+
$array.dispose();
|
|
37
|
+
await expect($array.pick()).rejects.toThrow("[PicoFlow] Primitive is disposed");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should throw when set is called after disposal", () => {
|
|
41
|
+
const $array = array([1, 2, 3]);
|
|
42
|
+
$array.dispose();
|
|
43
|
+
expect(() => $array.set([1])).toThrow("[PicoFlow] Primitive is disposed");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("should throw when update is called after disposal", () => {
|
|
47
|
+
const $array = array([1, 2, 3]);
|
|
48
|
+
$array.dispose();
|
|
49
|
+
expect(() => $array.update(0, 3)).toThrow("[PicoFlow] Primitive is disposed");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("should throw when push is called after disposal", () => {
|
|
53
|
+
const $array = array([1, 2, 3]);
|
|
54
|
+
$array.dispose();
|
|
55
|
+
expect(() => $array.push(3)).toThrow("[PicoFlow] Primitive is disposed");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("should throw when pop is called after disposal", () => {
|
|
59
|
+
const $array = array([1, 2, 3]);
|
|
60
|
+
$array.dispose();
|
|
61
|
+
expect(() => $array.pop()).toThrow("[PicoFlow] Primitive is disposed");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should throw when unshift is called after disposal", () => {
|
|
65
|
+
const $array = array([1, 2, 3]);
|
|
66
|
+
$array.dispose();
|
|
67
|
+
expect(() => $array.unshift(3)).toThrow("[PicoFlow] Primitive is disposed");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("should throw when shift is called after disposal", () => {
|
|
71
|
+
const $array = array([1, 2, 3]);
|
|
72
|
+
$array.dispose();
|
|
73
|
+
expect(() => $array.shift()).toThrow("[PicoFlow] Primitive is disposed");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("should throw when splice is called after disposal", () => {
|
|
77
|
+
const $array = array<number>([0, 1, 2, 3, 4]);
|
|
78
|
+
$array.dispose();
|
|
79
|
+
expect(() => $array.splice(1, 2)).toThrow("[PicoFlow] Primitive is disposed");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("should throw when clear is called after disposal", () => {
|
|
83
|
+
const $array = array<number>([0, 1, 2, 3, 4]);
|
|
84
|
+
$array.dispose();
|
|
85
|
+
expect(() => $array.clear()).toThrow("[PicoFlow] Primitive is disposed");
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe("length", () => {
|
|
90
|
+
it("should return correct length", () => {
|
|
91
|
+
const $array = array([1, 2, 3]);
|
|
92
|
+
expect($array.length).toBe(3);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("should return zero for empty array", () => {
|
|
96
|
+
const $array = array<number>([]);
|
|
97
|
+
expect($array.length).toBe(0);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("should throw when length is accessed after disposal", () => {
|
|
101
|
+
const $array = array([1, 2, 3]);
|
|
102
|
+
$array.dispose();
|
|
103
|
+
expect(() => $array.length).toThrow("[PicoFlow] Primitive is disposed");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("should update length when array is modified", () => {
|
|
107
|
+
const $array = array<number>([]);
|
|
108
|
+
expect($array.length).toBe(0);
|
|
109
|
+
|
|
110
|
+
$array.push(1);
|
|
111
|
+
expect($array.length).toBe(1);
|
|
112
|
+
|
|
113
|
+
$array.push(2);
|
|
114
|
+
expect($array.length).toBe(2);
|
|
115
|
+
|
|
116
|
+
$array.pop();
|
|
117
|
+
expect($array.length).toBe(1);
|
|
118
|
+
|
|
119
|
+
$array.unshift(0);
|
|
120
|
+
expect($array.length).toBe(2);
|
|
121
|
+
|
|
122
|
+
$array.shift();
|
|
123
|
+
expect($array.length).toBe(1);
|
|
124
|
+
|
|
125
|
+
$array.clear();
|
|
126
|
+
expect($array.length).toBe(0);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe("set", () => {
|
|
131
|
+
it("should update array when set is called", async () => {
|
|
132
|
+
const $array = array([0, 1, 2]);
|
|
133
|
+
expect(await $array.pick()).toEqual([0, 1, 2]);
|
|
134
|
+
|
|
135
|
+
$array.set([1, 2, 3]);
|
|
136
|
+
expect(await $array.pick()).toEqual([1, 2, 3]);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
describe("update", () => {
|
|
141
|
+
it("should update item at specific index", async () => {
|
|
142
|
+
const $array = array([0, 1, 2]);
|
|
143
|
+
expect(await $array.pick()).toEqual([0, 1, 2]);
|
|
144
|
+
|
|
145
|
+
$array.update(0, 1);
|
|
146
|
+
expect(await $array.pick()).toEqual([1, 1, 2]);
|
|
147
|
+
|
|
148
|
+
$array.update(1, 2);
|
|
149
|
+
expect(await $array.pick()).toEqual([1, 2, 2]);
|
|
150
|
+
|
|
151
|
+
$array.update(2, 3);
|
|
152
|
+
expect(await $array.pick()).toEqual([1, 2, 3]);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("should throw when update is called with negative index", () => {
|
|
156
|
+
const $array = array([1, 2, 3]);
|
|
157
|
+
expect(() => $array.update(-1, 0)).toThrow("[PicoFlow] Index out of bounds");
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("should throw when update is called with index >= length", () => {
|
|
161
|
+
const $array = array([1, 2, 3]);
|
|
162
|
+
expect(() => $array.update(3, 0)).toThrow("[PicoFlow] Index out of bounds");
|
|
163
|
+
expect(() => $array.update(10, 0)).toThrow("[PicoFlow] Index out of bounds");
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("should handle boundary indices correctly", async () => {
|
|
167
|
+
const $array = array([0, 1, 2]);
|
|
168
|
+
$array.update(0, 10);
|
|
169
|
+
expect(await $array.pick()).toEqual([10, 1, 2]);
|
|
170
|
+
|
|
171
|
+
$array.update(2, 20);
|
|
172
|
+
expect(await $array.pick()).toEqual([10, 1, 20]);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
describe("push", () => {
|
|
177
|
+
it("should append item to end of array", async () => {
|
|
178
|
+
const $array = array<number>([]);
|
|
179
|
+
expect(await $array.pick()).toEqual([]);
|
|
180
|
+
|
|
181
|
+
$array.push(0);
|
|
182
|
+
expect(await $array.pick()).toEqual([0]);
|
|
183
|
+
|
|
184
|
+
$array.push(1);
|
|
185
|
+
expect(await $array.pick()).toEqual([0, 1]);
|
|
186
|
+
|
|
187
|
+
$array.push(2);
|
|
188
|
+
expect(await $array.pick()).toEqual([0, 1, 2]);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("should handle operations on empty array", () => {
|
|
192
|
+
const $array = array<number>([]);
|
|
193
|
+
expect($array.length).toBe(0);
|
|
194
|
+
$array.push(1);
|
|
195
|
+
expect($array.length).toBe(1);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe("pop", () => {
|
|
200
|
+
it("should remove last item from array", async () => {
|
|
201
|
+
const $array = array([0, 1, 2]);
|
|
202
|
+
expect(await $array.pick()).toEqual([0, 1, 2]);
|
|
203
|
+
|
|
204
|
+
$array.pop();
|
|
205
|
+
expect(await $array.pick()).toEqual([0, 1]);
|
|
206
|
+
|
|
207
|
+
$array.pop();
|
|
208
|
+
expect(await $array.pick()).toEqual([0]);
|
|
209
|
+
|
|
210
|
+
$array.pop();
|
|
211
|
+
expect(await $array.pick()).toEqual([]);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("should handle operations on empty array", () => {
|
|
215
|
+
const $array = array<number>([]);
|
|
216
|
+
expect($array.length).toBe(0);
|
|
217
|
+
$array.pop();
|
|
218
|
+
expect($array.length).toBe(0);
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
describe("unshift", () => {
|
|
223
|
+
it("should insert item at beginning of array", async () => {
|
|
224
|
+
const $array = array<number>([]);
|
|
225
|
+
expect(await $array.pick()).toEqual([]);
|
|
226
|
+
|
|
227
|
+
$array.unshift(0);
|
|
228
|
+
expect(await $array.pick()).toEqual([0]);
|
|
229
|
+
|
|
230
|
+
$array.unshift(1);
|
|
231
|
+
expect(await $array.pick()).toEqual([1, 0]);
|
|
232
|
+
|
|
233
|
+
$array.unshift(2);
|
|
234
|
+
expect(await $array.pick()).toEqual([2, 1, 0]);
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
describe("shift", () => {
|
|
239
|
+
it("should remove first item from array", async () => {
|
|
240
|
+
const $array = array([0, 1, 2]);
|
|
241
|
+
expect(await $array.pick()).toEqual([0, 1, 2]);
|
|
242
|
+
|
|
243
|
+
$array.shift();
|
|
244
|
+
expect(await $array.pick()).toEqual([1, 2]);
|
|
245
|
+
|
|
246
|
+
$array.shift();
|
|
247
|
+
expect(await $array.pick()).toEqual([2]);
|
|
248
|
+
|
|
249
|
+
$array.shift();
|
|
250
|
+
expect(await $array.pick()).toEqual([]);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("should handle operations on empty array", () => {
|
|
254
|
+
const $array = array<number>([]);
|
|
255
|
+
expect($array.length).toBe(0);
|
|
256
|
+
$array.shift();
|
|
257
|
+
expect($array.length).toBe(0);
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
describe("splice", () => {
|
|
262
|
+
it("should remove items from array", async () => {
|
|
263
|
+
const $array = array<number>([0, 1, 2, 3, 4]);
|
|
264
|
+
expect(await $array.pick()).toEqual([0, 1, 2, 3, 4]);
|
|
265
|
+
|
|
266
|
+
$array.splice(1, 2);
|
|
267
|
+
expect(await $array.pick()).toEqual([0, 3, 4]);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it("should insert items into array", async () => {
|
|
271
|
+
const $array = array<number>([0, 1, 2, 3, 4]);
|
|
272
|
+
$array.splice(1, 0, 10, 11);
|
|
273
|
+
expect(await $array.pick()).toEqual([0, 10, 11, 1, 2, 3, 4]);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it("should replace items in array", async () => {
|
|
277
|
+
const $array = array<number>([0, 1, 2, 3, 4]);
|
|
278
|
+
$array.splice(1, 2, 10, 11);
|
|
279
|
+
expect(await $array.pick()).toEqual([0, 10, 11, 3, 4]);
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
describe("clear", () => {
|
|
284
|
+
it("should remove all items from array", async () => {
|
|
285
|
+
const $array = array<number>([0, 1, 2, 3, 4]);
|
|
286
|
+
expect(await $array.pick()).toEqual([0, 1, 2, 3, 4]);
|
|
287
|
+
|
|
288
|
+
$array.clear();
|
|
289
|
+
expect(await $array.pick()).toEqual([]);
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
describe("$lastAction", () => {
|
|
294
|
+
describe("set action", () => {
|
|
295
|
+
it("should initialize $lastAction with set action on creation", async () => {
|
|
296
|
+
const $array = array([1, 2, 3]);
|
|
297
|
+
const action = await $array.$lastAction.pick();
|
|
298
|
+
expect(action).toEqual({
|
|
299
|
+
type: "set",
|
|
300
|
+
setItems: [1, 2, 3],
|
|
301
|
+
clearedItems: [],
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it("should update $lastAction with set action when set is called", async () => {
|
|
306
|
+
const $array = array([0, 1, 2]);
|
|
307
|
+
$array.set([1, 2, 3]);
|
|
308
|
+
const action = await $array.$lastAction.pick();
|
|
309
|
+
expect(action).toEqual({
|
|
310
|
+
type: "set",
|
|
311
|
+
setItems: [1, 2, 3],
|
|
312
|
+
clearedItems: [0, 1, 2],
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it("should have correct structure for set action (setItems and clearedItems)", async () => {
|
|
317
|
+
const $array = array([1, 2, 3]);
|
|
318
|
+
const action = await $array.$lastAction.pick();
|
|
319
|
+
expect(action).toHaveProperty("type", "set");
|
|
320
|
+
if (action.type === "set") {
|
|
321
|
+
expect(action).toHaveProperty("setItems");
|
|
322
|
+
expect(action).toHaveProperty("clearedItems");
|
|
323
|
+
expect(Array.isArray(action.setItems)).toBe(true);
|
|
324
|
+
expect(Array.isArray(action.clearedItems)).toBe(true);
|
|
325
|
+
expect(action.setItems).toEqual([1, 2, 3]);
|
|
326
|
+
expect(action.clearedItems).toEqual([]);
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
describe("update action", () => {
|
|
332
|
+
it("should update $lastAction with update action when update is called", async () => {
|
|
333
|
+
const $array = array([0, 1, 2]);
|
|
334
|
+
$array.update(1, 10);
|
|
335
|
+
const action = await $array.$lastAction.pick();
|
|
336
|
+
expect(action).toEqual({
|
|
337
|
+
type: "update",
|
|
338
|
+
index: 1,
|
|
339
|
+
setItem: 10,
|
|
340
|
+
clearedItem: 1,
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it("should have correct structure for update action (index, setItem, clearedItem)", async () => {
|
|
345
|
+
const $array = array([1, 2, 3]);
|
|
346
|
+
$array.update(0, 10);
|
|
347
|
+
const action = await $array.$lastAction.pick();
|
|
348
|
+
expect(action).toHaveProperty("type", "update");
|
|
349
|
+
if (action.type === "update") {
|
|
350
|
+
expect(action).toHaveProperty("index");
|
|
351
|
+
expect(action).toHaveProperty("setItem");
|
|
352
|
+
expect(action).toHaveProperty("clearedItem");
|
|
353
|
+
expect(action.index).toBe(0);
|
|
354
|
+
expect(action.setItem).toBe(10);
|
|
355
|
+
expect(action.clearedItem).toBe(1);
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
describe("push action", () => {
|
|
361
|
+
it("should update $lastAction with push action when push is called", async () => {
|
|
362
|
+
const $array = array<number>([]);
|
|
363
|
+
$array.push(42);
|
|
364
|
+
const action = await $array.$lastAction.pick();
|
|
365
|
+
expect(action).toEqual({
|
|
366
|
+
type: "push",
|
|
367
|
+
addedItem: 42,
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it("should have correct structure for push action (addedItem)", async () => {
|
|
372
|
+
const $array = array<number>([]);
|
|
373
|
+
$array.push(100);
|
|
374
|
+
const action = await $array.$lastAction.pick();
|
|
375
|
+
expect(action).toHaveProperty("type", "push");
|
|
376
|
+
if (action.type === "push") {
|
|
377
|
+
expect(action).toHaveProperty("addedItem");
|
|
378
|
+
expect(action.addedItem).toBe(100);
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
describe("pop action", () => {
|
|
384
|
+
it("should update $lastAction with pop action when pop is called", async () => {
|
|
385
|
+
const $array = array([1, 2, 3]);
|
|
386
|
+
$array.pop();
|
|
387
|
+
const action = await $array.$lastAction.pick();
|
|
388
|
+
expect(action).toEqual({
|
|
389
|
+
type: "pop",
|
|
390
|
+
removedItem: 3,
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
it("should have correct structure for pop action (removedItem)", async () => {
|
|
395
|
+
const $array = array([1, 2, 3]);
|
|
396
|
+
$array.pop();
|
|
397
|
+
const action = await $array.$lastAction.pick();
|
|
398
|
+
expect(action).toHaveProperty("type", "pop");
|
|
399
|
+
if (action.type === "pop") {
|
|
400
|
+
expect(action).toHaveProperty("removedItem");
|
|
401
|
+
expect(action.removedItem).toBe(3);
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
it("should have removedItem undefined when pop is called on empty array", async () => {
|
|
406
|
+
const $array = array<number>([]);
|
|
407
|
+
$array.pop();
|
|
408
|
+
const action = await $array.$lastAction.pick();
|
|
409
|
+
expect(action).toHaveProperty("type", "pop");
|
|
410
|
+
if (action.type === "pop") {
|
|
411
|
+
expect(action).toHaveProperty("removedItem");
|
|
412
|
+
expect(action.removedItem).toBeUndefined();
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
describe("unshift action", () => {
|
|
418
|
+
it("should update $lastAction with unshift action when unshift is called", async () => {
|
|
419
|
+
const $array = array<number>([]);
|
|
420
|
+
$array.unshift(42);
|
|
421
|
+
const action = await $array.$lastAction.pick();
|
|
422
|
+
expect(action).toEqual({
|
|
423
|
+
type: "unshift",
|
|
424
|
+
addedItem: 42,
|
|
425
|
+
});
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it("should have correct structure for unshift action (addedItem)", async () => {
|
|
429
|
+
const $array = array<number>([]);
|
|
430
|
+
$array.unshift(200);
|
|
431
|
+
const action = await $array.$lastAction.pick();
|
|
432
|
+
expect(action).toHaveProperty("type", "unshift");
|
|
433
|
+
if (action.type === "unshift") {
|
|
434
|
+
expect(action).toHaveProperty("addedItem");
|
|
435
|
+
expect(action.addedItem).toBe(200);
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
describe("shift action", () => {
|
|
441
|
+
it("should update $lastAction with shift action when shift is called", async () => {
|
|
442
|
+
const $array = array([1, 2, 3]);
|
|
443
|
+
$array.shift();
|
|
444
|
+
const action = await $array.$lastAction.pick();
|
|
445
|
+
expect(action).toEqual({
|
|
446
|
+
type: "shift",
|
|
447
|
+
removedItem: 1,
|
|
448
|
+
});
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
it("should have correct structure for shift action (removedItem)", async () => {
|
|
452
|
+
const $array = array([1, 2, 3]);
|
|
453
|
+
$array.shift();
|
|
454
|
+
const action = await $array.$lastAction.pick();
|
|
455
|
+
expect(action).toHaveProperty("type", "shift");
|
|
456
|
+
if (action.type === "shift") {
|
|
457
|
+
expect(action).toHaveProperty("removedItem");
|
|
458
|
+
expect(action.removedItem).toBe(1);
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
it("should have removedItem undefined when shift is called on empty array", async () => {
|
|
463
|
+
const $array = array<number>([]);
|
|
464
|
+
$array.shift();
|
|
465
|
+
const action = await $array.$lastAction.pick();
|
|
466
|
+
expect(action).toHaveProperty("type", "shift");
|
|
467
|
+
if (action.type === "shift") {
|
|
468
|
+
expect(action).toHaveProperty("removedItem");
|
|
469
|
+
expect(action.removedItem).toBeUndefined();
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
describe("splice action", () => {
|
|
475
|
+
it("should update $lastAction with splice action when splice is called", async () => {
|
|
476
|
+
const $array = array<number>([0, 1, 2, 3, 4]);
|
|
477
|
+
$array.splice(1, 2, 10, 11);
|
|
478
|
+
const action = await $array.$lastAction.pick();
|
|
479
|
+
expect(action).toEqual({
|
|
480
|
+
type: "splice",
|
|
481
|
+
start: 1,
|
|
482
|
+
deleteCount: 2,
|
|
483
|
+
addedItems: [10, 11],
|
|
484
|
+
removedItems: [1, 2],
|
|
485
|
+
});
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
it("should have correct structure for splice action (start, deleteCount, addedItems, removedItems)", async () => {
|
|
489
|
+
const $array = array<number>([0, 1, 2]);
|
|
490
|
+
$array.splice(1, 1, 100);
|
|
491
|
+
const action = await $array.$lastAction.pick();
|
|
492
|
+
expect(action).toHaveProperty("type", "splice");
|
|
493
|
+
if (action.type === "splice") {
|
|
494
|
+
expect(action).toHaveProperty("start");
|
|
495
|
+
expect(action).toHaveProperty("deleteCount");
|
|
496
|
+
expect(action).toHaveProperty("addedItems");
|
|
497
|
+
expect(action).toHaveProperty("removedItems");
|
|
498
|
+
expect(action.start).toBe(1);
|
|
499
|
+
expect(action.deleteCount).toBe(1);
|
|
500
|
+
expect(Array.isArray(action.addedItems)).toBe(true);
|
|
501
|
+
expect(Array.isArray(action.removedItems)).toBe(true);
|
|
502
|
+
expect(action.addedItems).toEqual([100]);
|
|
503
|
+
expect(action.removedItems).toEqual([1]);
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
describe("clear action", () => {
|
|
509
|
+
it("should update $lastAction with clear action when clear is called", async () => {
|
|
510
|
+
const $array = array<number>([0, 1, 2, 3, 4]);
|
|
511
|
+
$array.clear();
|
|
512
|
+
const action = await $array.$lastAction.pick();
|
|
513
|
+
expect(action).toEqual({
|
|
514
|
+
type: "clear",
|
|
515
|
+
clearedItems: [0, 1, 2, 3, 4],
|
|
516
|
+
});
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
it("should have correct structure for clear action (clearedItems)", async () => {
|
|
520
|
+
const $array = array<number>([1, 2, 3]);
|
|
521
|
+
$array.clear();
|
|
522
|
+
const action = await $array.$lastAction.pick();
|
|
523
|
+
expect(action).toHaveProperty("type", "clear");
|
|
524
|
+
if (action.type === "clear") {
|
|
525
|
+
expect(action).toHaveProperty("clearedItems");
|
|
526
|
+
expect(Array.isArray(action.clearedItems)).toBe(true);
|
|
527
|
+
expect(action.clearedItems).toEqual([1, 2, 3]);
|
|
528
|
+
}
|
|
529
|
+
});
|
|
530
|
+
});
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
describe("edge cases", () => {
|
|
534
|
+
it("should handle multiple rapid operations", async () => {
|
|
535
|
+
const $array = array<number>([]);
|
|
536
|
+
$array.push(1);
|
|
537
|
+
$array.push(2);
|
|
538
|
+
$array.push(3);
|
|
539
|
+
$array.pop();
|
|
540
|
+
$array.shift();
|
|
541
|
+
$array.unshift(0);
|
|
542
|
+
expect(await $array.pick()).toEqual([0, 2]);
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
it("should handle boundary indices correctly", async () => {
|
|
546
|
+
const $array = array([0, 1, 2]);
|
|
547
|
+
$array.update(0, 10);
|
|
548
|
+
$array.update(2, 20);
|
|
549
|
+
expect(await $array.pick()).toEqual([10, 1, 20]);
|
|
550
|
+
});
|
|
551
|
+
});
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
describe("integration", () => {
|
|
555
|
+
describe("with effects", () => {
|
|
556
|
+
describe("reactivity", () => {
|
|
557
|
+
it("should call effect when initialized", async () => {
|
|
558
|
+
const $array = array([1, 2, 3]);
|
|
559
|
+
const onData = vi.fn();
|
|
560
|
+
subscribe((t) => $array.get(t), onData);
|
|
561
|
+
|
|
562
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
563
|
+
expect(onData).toHaveBeenLastCalledWith([1, 2, 3]);
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
it("should call effect when updated with set", async () => {
|
|
567
|
+
const $array = array<number>([0, 1, 2]);
|
|
568
|
+
const onData = vi.fn();
|
|
569
|
+
subscribe((t) => $array.get(t), onData);
|
|
570
|
+
|
|
571
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
572
|
+
expect(onData).toHaveBeenLastCalledWith([0, 1, 2]);
|
|
573
|
+
|
|
574
|
+
$array.set([1, 2, 3]);
|
|
575
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
|
|
576
|
+
expect(onData).toHaveBeenLastCalledWith([1, 2, 3]);
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
it("should call effect when updated with push/pop", async () => {
|
|
580
|
+
const $array = array<number>();
|
|
581
|
+
const onData = vi.fn();
|
|
582
|
+
subscribe((t) => $array.get(t), onData);
|
|
583
|
+
|
|
584
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
585
|
+
expect(onData).toHaveBeenLastCalledWith([]);
|
|
586
|
+
|
|
587
|
+
$array.push(0);
|
|
588
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
|
|
589
|
+
expect(onData).toHaveBeenLastCalledWith([0]);
|
|
590
|
+
|
|
591
|
+
$array.push(1);
|
|
592
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
|
|
593
|
+
expect(onData).toHaveBeenLastCalledWith([0, 1]);
|
|
594
|
+
|
|
595
|
+
$array.push(2);
|
|
596
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(4));
|
|
597
|
+
expect(onData).toHaveBeenLastCalledWith([0, 1, 2]);
|
|
598
|
+
|
|
599
|
+
$array.pop();
|
|
600
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(5));
|
|
601
|
+
expect(onData).toHaveBeenLastCalledWith([0, 1]);
|
|
602
|
+
|
|
603
|
+
$array.pop();
|
|
604
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(6));
|
|
605
|
+
expect(onData).toHaveBeenLastCalledWith([0]);
|
|
606
|
+
|
|
607
|
+
$array.pop();
|
|
608
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(7));
|
|
609
|
+
expect(onData).toHaveBeenLastCalledWith([]);
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
it("should call effect when updated with unshift/shift", async () => {
|
|
613
|
+
const $array = array<number>();
|
|
614
|
+
const onData = vi.fn();
|
|
615
|
+
subscribe((t) => $array.get(t), onData);
|
|
616
|
+
|
|
617
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
618
|
+
expect(onData).toHaveBeenLastCalledWith([]);
|
|
619
|
+
|
|
620
|
+
$array.unshift(0);
|
|
621
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
|
|
622
|
+
expect(onData).toHaveBeenLastCalledWith([0]);
|
|
623
|
+
|
|
624
|
+
$array.unshift(1);
|
|
625
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
|
|
626
|
+
expect(onData).toHaveBeenLastCalledWith([1, 0]);
|
|
627
|
+
|
|
628
|
+
$array.unshift(2);
|
|
629
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(4));
|
|
630
|
+
expect(onData).toHaveBeenLastCalledWith([2, 1, 0]);
|
|
631
|
+
|
|
632
|
+
$array.shift();
|
|
633
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(5));
|
|
634
|
+
expect(onData).toHaveBeenLastCalledWith([1, 0]);
|
|
635
|
+
|
|
636
|
+
$array.shift();
|
|
637
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(6));
|
|
638
|
+
expect(onData).toHaveBeenLastCalledWith([0]);
|
|
639
|
+
|
|
640
|
+
$array.shift();
|
|
641
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(7));
|
|
642
|
+
expect(onData).toHaveBeenLastCalledWith([]);
|
|
643
|
+
});
|
|
644
|
+
|
|
645
|
+
it("should call effect when updated with splice", async () => {
|
|
646
|
+
const $array = array<number>([0, 1, 2, 3, 4]);
|
|
647
|
+
const onData = vi.fn();
|
|
648
|
+
subscribe((t) => $array.get(t), onData);
|
|
649
|
+
|
|
650
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
651
|
+
expect(onData).toHaveBeenLastCalledWith([0, 1, 2, 3, 4]);
|
|
652
|
+
|
|
653
|
+
$array.splice(1, 2);
|
|
654
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
|
|
655
|
+
expect(onData).toHaveBeenLastCalledWith([0, 3, 4]);
|
|
656
|
+
|
|
657
|
+
$array.splice(1, 0, 1, 2);
|
|
658
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
|
|
659
|
+
expect(onData).toHaveBeenLastCalledWith([0, 1, 2, 3, 4]);
|
|
660
|
+
});
|
|
661
|
+
|
|
662
|
+
it("should call effect when updated with clear", async () => {
|
|
663
|
+
const $array = array<number>([0, 1, 2, 3, 4]);
|
|
664
|
+
const onData = vi.fn();
|
|
665
|
+
subscribe((t) => $array.get(t), onData);
|
|
666
|
+
|
|
667
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
668
|
+
expect(onData).toHaveBeenLastCalledWith([0, 1, 2, 3, 4]);
|
|
669
|
+
|
|
670
|
+
$array.clear();
|
|
671
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
|
|
672
|
+
expect(onData).toHaveBeenLastCalledWith([]);
|
|
673
|
+
});
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
describe("item reactivity", () => {
|
|
677
|
+
it("should call effect when item is updated", async () => {
|
|
678
|
+
const $array = array<number>([0, 1, 2]);
|
|
679
|
+
const onData = vi.fn();
|
|
680
|
+
const onData0 = vi.fn();
|
|
681
|
+
const onData1 = vi.fn();
|
|
682
|
+
const onData2 = vi.fn();
|
|
683
|
+
|
|
684
|
+
subscribe((t) => $array.get(t), onData);
|
|
685
|
+
subscribe((t) => $array.get(t)[0], onData0);
|
|
686
|
+
subscribe((t) => $array.get(t)[1], onData1);
|
|
687
|
+
subscribe((t) => $array.get(t)[2], onData2);
|
|
688
|
+
|
|
689
|
+
$array.update(0, 1);
|
|
690
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
|
|
691
|
+
expect(onData).toHaveBeenLastCalledWith([1, 1, 2]);
|
|
692
|
+
await vi.waitFor(() => expect(onData0).toHaveBeenCalledTimes(2));
|
|
693
|
+
expect(onData0).toHaveBeenLastCalledWith(1);
|
|
694
|
+
await vi.waitFor(() => expect(onData1).toHaveBeenCalledTimes(2));
|
|
695
|
+
expect(onData1).toHaveBeenLastCalledWith(1);
|
|
696
|
+
await vi.waitFor(() => expect(onData2).toHaveBeenCalledTimes(2));
|
|
697
|
+
expect(onData2).toHaveBeenLastCalledWith(2);
|
|
698
|
+
|
|
699
|
+
$array.update(1, 2);
|
|
700
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
|
|
701
|
+
expect(onData).toHaveBeenLastCalledWith([1, 2, 2]);
|
|
702
|
+
await vi.waitFor(() => expect(onData0).toHaveBeenCalledTimes(3));
|
|
703
|
+
expect(onData0).toHaveBeenLastCalledWith(1);
|
|
704
|
+
await vi.waitFor(() => expect(onData1).toHaveBeenCalledTimes(3));
|
|
705
|
+
expect(onData1).toHaveBeenLastCalledWith(2);
|
|
706
|
+
await vi.waitFor(() => expect(onData2).toHaveBeenCalledTimes(3));
|
|
707
|
+
expect(onData2).toHaveBeenLastCalledWith(2);
|
|
708
|
+
|
|
709
|
+
$array.update(2, 3);
|
|
710
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(4));
|
|
711
|
+
expect(onData).toHaveBeenLastCalledWith([1, 2, 3]);
|
|
712
|
+
await vi.waitFor(() => expect(onData0).toHaveBeenCalledTimes(4));
|
|
713
|
+
expect(onData0).toHaveBeenLastCalledWith(1);
|
|
714
|
+
await vi.waitFor(() => expect(onData1).toHaveBeenCalledTimes(4));
|
|
715
|
+
expect(onData1).toHaveBeenLastCalledWith(2);
|
|
716
|
+
await vi.waitFor(() => expect(onData2).toHaveBeenCalledTimes(4));
|
|
717
|
+
expect(onData2).toHaveBeenLastCalledWith(3);
|
|
718
|
+
});
|
|
719
|
+
|
|
720
|
+
it("should call effect when item is replaced", async () => {
|
|
721
|
+
const $array = array<number>([0, 1, 2]);
|
|
722
|
+
const onData = vi.fn();
|
|
723
|
+
const onData0 = vi.fn();
|
|
724
|
+
|
|
725
|
+
subscribe((t) => $array.get(t), onData);
|
|
726
|
+
subscribe((t) => $array.get(t)[0], onData0);
|
|
727
|
+
|
|
728
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
729
|
+
expect(onData).toHaveBeenLastCalledWith([0, 1, 2]);
|
|
730
|
+
await vi.waitFor(() => expect(onData0).toHaveBeenCalledTimes(1));
|
|
731
|
+
expect(onData0).toHaveBeenLastCalledWith(0);
|
|
732
|
+
|
|
733
|
+
$array.update(0, 3);
|
|
734
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
|
|
735
|
+
expect(onData).toHaveBeenLastCalledWith([3, 1, 2]);
|
|
736
|
+
await vi.waitFor(() => expect(onData0).toHaveBeenCalledTimes(2));
|
|
737
|
+
expect(onData0).toHaveBeenLastCalledWith(3);
|
|
738
|
+
|
|
739
|
+
$array.shift();
|
|
740
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
|
|
741
|
+
expect(onData).toHaveBeenLastCalledWith([1, 2]);
|
|
742
|
+
await vi.waitFor(() => expect(onData0).toHaveBeenCalledTimes(3));
|
|
743
|
+
expect(onData0).toHaveBeenLastCalledWith(1);
|
|
744
|
+
|
|
745
|
+
$array.unshift(4);
|
|
746
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(4));
|
|
747
|
+
expect(onData).toHaveBeenLastCalledWith([4, 1, 2]);
|
|
748
|
+
await vi.waitFor(() => expect(onData0).toHaveBeenCalledTimes(4));
|
|
749
|
+
expect(onData0).toHaveBeenLastCalledWith(4);
|
|
750
|
+
});
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
describe("lastAction reactivity", () => {
|
|
754
|
+
describe("set action", () => {
|
|
755
|
+
it("should call effect when $lastAction is updated with set action", async () => {
|
|
756
|
+
const $array = array([0, 1, 2]);
|
|
757
|
+
const onData = vi.fn();
|
|
758
|
+
subscribe((t) => $array.$lastAction.get(t), onData);
|
|
759
|
+
|
|
760
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
761
|
+
expect(onData).toHaveBeenLastCalledWith({
|
|
762
|
+
type: "set",
|
|
763
|
+
setItems: [0, 1, 2],
|
|
764
|
+
clearedItems: [],
|
|
765
|
+
});
|
|
766
|
+
|
|
767
|
+
$array.set([1, 2, 3]);
|
|
768
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
|
|
769
|
+
expect(onData).toHaveBeenLastCalledWith({
|
|
770
|
+
type: "set",
|
|
771
|
+
setItems: [1, 2, 3],
|
|
772
|
+
clearedItems: [0, 1, 2],
|
|
773
|
+
});
|
|
774
|
+
});
|
|
775
|
+
});
|
|
776
|
+
|
|
777
|
+
describe("update action", () => {
|
|
778
|
+
it("should call effect when $lastAction is updated with update action", async () => {
|
|
779
|
+
const $array = array([0, 1, 2]);
|
|
780
|
+
const onData = vi.fn();
|
|
781
|
+
subscribe((t) => $array.$lastAction.get(t), onData);
|
|
782
|
+
|
|
783
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
784
|
+
|
|
785
|
+
$array.update(1, 10);
|
|
786
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
|
|
787
|
+
expect(onData).toHaveBeenLastCalledWith({
|
|
788
|
+
type: "update",
|
|
789
|
+
index: 1,
|
|
790
|
+
setItem: 10,
|
|
791
|
+
clearedItem: 1,
|
|
792
|
+
});
|
|
793
|
+
});
|
|
794
|
+
});
|
|
795
|
+
|
|
796
|
+
describe("push action", () => {
|
|
797
|
+
it("should call effect when $lastAction is updated with push action", async () => {
|
|
798
|
+
const $array = array<number>();
|
|
799
|
+
const onData = vi.fn();
|
|
800
|
+
subscribe((t) => $array.$lastAction.get(t), onData);
|
|
801
|
+
|
|
802
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
803
|
+
expect(onData).toHaveBeenLastCalledWith({
|
|
804
|
+
type: "set",
|
|
805
|
+
setItems: [],
|
|
806
|
+
clearedItems: [],
|
|
807
|
+
});
|
|
808
|
+
|
|
809
|
+
$array.push(0);
|
|
810
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
|
|
811
|
+
expect(onData).toHaveBeenLastCalledWith({
|
|
812
|
+
type: "push",
|
|
813
|
+
addedItem: 0,
|
|
814
|
+
});
|
|
815
|
+
|
|
816
|
+
$array.push(1);
|
|
817
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
|
|
818
|
+
expect(onData).toHaveBeenLastCalledWith({
|
|
819
|
+
type: "push",
|
|
820
|
+
addedItem: 1,
|
|
821
|
+
});
|
|
822
|
+
});
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
describe("pop action", () => {
|
|
826
|
+
it("should call effect when $lastAction is updated with pop action", async () => {
|
|
827
|
+
const $array = array<number>([0, 1, 2]);
|
|
828
|
+
const onData = vi.fn();
|
|
829
|
+
subscribe((t) => $array.$lastAction.get(t), onData);
|
|
830
|
+
|
|
831
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
832
|
+
|
|
833
|
+
$array.pop();
|
|
834
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
|
|
835
|
+
expect(onData).toHaveBeenLastCalledWith({
|
|
836
|
+
type: "pop",
|
|
837
|
+
removedItem: 2,
|
|
838
|
+
});
|
|
839
|
+
|
|
840
|
+
$array.pop();
|
|
841
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
|
|
842
|
+
expect(onData).toHaveBeenLastCalledWith({
|
|
843
|
+
type: "pop",
|
|
844
|
+
removedItem: 1,
|
|
845
|
+
});
|
|
846
|
+
});
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
describe("unshift action", () => {
|
|
850
|
+
it("should call effect when $lastAction is updated with unshift action", async () => {
|
|
851
|
+
const $array = array<number>();
|
|
852
|
+
const onData = vi.fn();
|
|
853
|
+
subscribe((t) => $array.$lastAction.get(t), onData);
|
|
854
|
+
|
|
855
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
856
|
+
expect(onData).toHaveBeenLastCalledWith({
|
|
857
|
+
type: "set",
|
|
858
|
+
setItems: [],
|
|
859
|
+
clearedItems: [],
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
$array.unshift(0);
|
|
863
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
|
|
864
|
+
expect(onData).toHaveBeenLastCalledWith({
|
|
865
|
+
type: "unshift",
|
|
866
|
+
addedItem: 0,
|
|
867
|
+
});
|
|
868
|
+
|
|
869
|
+
$array.unshift(1);
|
|
870
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
|
|
871
|
+
expect(onData).toHaveBeenLastCalledWith({
|
|
872
|
+
type: "unshift",
|
|
873
|
+
addedItem: 1,
|
|
874
|
+
});
|
|
875
|
+
});
|
|
876
|
+
});
|
|
877
|
+
|
|
878
|
+
describe("shift action", () => {
|
|
879
|
+
it("should call effect when $lastAction is updated with shift action", async () => {
|
|
880
|
+
const $array = array<number>([0, 1, 2]);
|
|
881
|
+
const onData = vi.fn();
|
|
882
|
+
subscribe((t) => $array.$lastAction.get(t), onData);
|
|
883
|
+
|
|
884
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
885
|
+
|
|
886
|
+
$array.shift();
|
|
887
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
|
|
888
|
+
expect(onData).toHaveBeenLastCalledWith({
|
|
889
|
+
type: "shift",
|
|
890
|
+
removedItem: 0,
|
|
891
|
+
});
|
|
892
|
+
|
|
893
|
+
$array.shift();
|
|
894
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
|
|
895
|
+
expect(onData).toHaveBeenLastCalledWith({
|
|
896
|
+
type: "shift",
|
|
897
|
+
removedItem: 1,
|
|
898
|
+
});
|
|
899
|
+
});
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
describe("splice action", () => {
|
|
903
|
+
it("should call effect when $lastAction is updated with splice action", async () => {
|
|
904
|
+
const $array = array<number>([0, 1, 2, 3, 4]);
|
|
905
|
+
const onData = vi.fn();
|
|
906
|
+
subscribe((t) => $array.$lastAction.get(t), onData);
|
|
907
|
+
|
|
908
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
909
|
+
expect(onData).toHaveBeenLastCalledWith({
|
|
910
|
+
type: "set",
|
|
911
|
+
setItems: [0, 1, 2, 3, 4],
|
|
912
|
+
clearedItems: [],
|
|
913
|
+
});
|
|
914
|
+
|
|
915
|
+
$array.splice(1, 2);
|
|
916
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
|
|
917
|
+
expect(onData).toHaveBeenLastCalledWith({
|
|
918
|
+
type: "splice",
|
|
919
|
+
start: 1,
|
|
920
|
+
deleteCount: 2,
|
|
921
|
+
addedItems: [],
|
|
922
|
+
removedItems: [1, 2],
|
|
923
|
+
});
|
|
924
|
+
|
|
925
|
+
$array.splice(1, 0, 1, 2);
|
|
926
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
|
|
927
|
+
expect(onData).toHaveBeenLastCalledWith({
|
|
928
|
+
type: "splice",
|
|
929
|
+
start: 1,
|
|
930
|
+
deleteCount: 0,
|
|
931
|
+
addedItems: [1, 2],
|
|
932
|
+
removedItems: [],
|
|
933
|
+
});
|
|
934
|
+
});
|
|
935
|
+
});
|
|
936
|
+
|
|
937
|
+
describe("clear action", () => {
|
|
938
|
+
it("should call effect when $lastAction is updated with clear action", async () => {
|
|
939
|
+
const $array = array<number>([0, 1, 2, 3, 4]);
|
|
940
|
+
const onData = vi.fn();
|
|
941
|
+
subscribe((t) => $array.$lastAction.get(t), onData);
|
|
942
|
+
|
|
943
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
944
|
+
expect(onData).toHaveBeenLastCalledWith({
|
|
945
|
+
type: "set",
|
|
946
|
+
setItems: [0, 1, 2, 3, 4],
|
|
947
|
+
clearedItems: [],
|
|
948
|
+
});
|
|
949
|
+
|
|
950
|
+
$array.clear();
|
|
951
|
+
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
|
|
952
|
+
expect(onData).toHaveBeenLastCalledWith({
|
|
953
|
+
type: "clear",
|
|
954
|
+
clearedItems: [0, 1, 2, 3, 4],
|
|
955
|
+
});
|
|
956
|
+
});
|
|
957
|
+
});
|
|
958
|
+
});
|
|
959
|
+
});
|
|
960
|
+
});
|
|
961
|
+
});
|