@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
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import type { FlowDisposable } from "./flowDisposable";
|
|
2
|
-
import type { FlowEffect } from "./flowEffect";
|
|
3
|
-
import { FlowGraph } from "./flowGraph";
|
|
4
|
-
import type { FlowTracker } from "./flowTracker";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Event-like reactive primitive with no payload.
|
|
8
|
-
*
|
|
9
|
-
* @remarks
|
|
10
|
-
* A signal is used to broadcast that “something happened” (refresh, invalidate,
|
|
11
|
-
* notify). It does not carry data; it only notifies dependents that they should
|
|
12
|
-
* react. Track it with `watch(t)` inside an effect or derivation to re-run when
|
|
13
|
-
* the signal is triggered.
|
|
14
|
-
*
|
|
15
|
-
* Signals can be triggered and disposed. Once disposed, further interaction
|
|
16
|
-
* throws an error.
|
|
17
|
-
*
|
|
18
|
-
* @public
|
|
19
|
-
*/
|
|
20
|
-
export class FlowSignal implements FlowDisposable, FlowTracker {
|
|
21
|
-
/**
|
|
22
|
-
* Triggers the signal and notifies all dependents.
|
|
23
|
-
*
|
|
24
|
-
* @remarks
|
|
25
|
-
* Any effect/derivation that called `watch(t)` on this signal will re-run.
|
|
26
|
-
* Returns a promise that settles after notifications complete.
|
|
27
|
-
*
|
|
28
|
-
* @throws Error if the signal is disposed.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```typescript
|
|
32
|
-
* const $tick = signal();
|
|
33
|
-
*
|
|
34
|
-
* effect((t) => {
|
|
35
|
-
* $tick.watch(t);
|
|
36
|
-
* console.log("tick");
|
|
37
|
-
* });
|
|
38
|
-
*
|
|
39
|
-
* $tick.trigger(); // logs "tick"
|
|
40
|
-
* ```
|
|
41
|
-
*
|
|
42
|
-
* @public
|
|
43
|
-
*/
|
|
44
|
-
public async trigger() {
|
|
45
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
46
|
-
return FlowGraph.requestTrigger(() => this._notify());
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Registers this signal as a dependency in the current tracking context.
|
|
51
|
-
*
|
|
52
|
-
* @param context - The tracking context (`t`) provided to effects/derivations.
|
|
53
|
-
*
|
|
54
|
-
* @remarks
|
|
55
|
-
* Signals have no value to read; calling `watch(t)` simply means “re-run me
|
|
56
|
-
* when this signal is triggered.” Call this inside an effect/derivation
|
|
57
|
-
* callback where a tracking context is available.
|
|
58
|
-
*
|
|
59
|
-
* @throws Error if the signal has been disposed.
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```typescript
|
|
63
|
-
* const $refresh = signal();
|
|
64
|
-
*
|
|
65
|
-
* effect((t) => {
|
|
66
|
-
* $refresh.watch(t);
|
|
67
|
-
* console.log("refresh triggered");
|
|
68
|
-
* });
|
|
69
|
-
*
|
|
70
|
-
* $refresh.trigger(); // logs "refresh triggered"
|
|
71
|
-
* ```
|
|
72
|
-
*
|
|
73
|
-
* @public
|
|
74
|
-
*/
|
|
75
|
-
public watch(caller: FlowTracker): void {
|
|
76
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
77
|
-
caller._registerDependency(this);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Disposes the signal and cleans up its dependencies/listeners.
|
|
82
|
-
*
|
|
83
|
-
* @remarks
|
|
84
|
-
* After disposal the signal must not be used; calling `trigger` or `watch`
|
|
85
|
-
* will throw. If `options?.self` is true, only this signal is disposed; when
|
|
86
|
-
* false or omitted, dependents may also be disposed depending on the
|
|
87
|
-
* implementation.
|
|
88
|
-
*
|
|
89
|
-
* @throws Error if the signal is already disposed.
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* ```typescript
|
|
93
|
-
* const $refresh = signal();
|
|
94
|
-
* // ... use it
|
|
95
|
-
* $refresh.dispose();
|
|
96
|
-
* ```
|
|
97
|
-
*
|
|
98
|
-
* @public
|
|
99
|
-
*/
|
|
100
|
-
public dispose(options?: { self: boolean }): void {
|
|
101
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
102
|
-
if (options?.self) {
|
|
103
|
-
Array.from(this._effects).forEach((effect) => {
|
|
104
|
-
effect._unregisterDependency(this);
|
|
105
|
-
});
|
|
106
|
-
Array.from(this._listeners).forEach((listener) => {
|
|
107
|
-
listener._unregisterDependency(this);
|
|
108
|
-
});
|
|
109
|
-
} else {
|
|
110
|
-
Array.from(this._effects).forEach((effect) => {
|
|
111
|
-
effect.dispose();
|
|
112
|
-
});
|
|
113
|
-
Array.from(this._listeners).forEach((listener) => {
|
|
114
|
-
listener.dispose();
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
Array.from(this._dependencies).forEach((dependency) => {
|
|
118
|
-
this._unregisterDependency(dependency);
|
|
119
|
-
});
|
|
120
|
-
this._disposed = true;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Whether the signal has been disposed.
|
|
125
|
-
*
|
|
126
|
-
* @returns `true` if disposed; `false` while active.
|
|
127
|
-
*
|
|
128
|
-
* @remarks Use to guard operations or avoid double disposal.
|
|
129
|
-
*
|
|
130
|
-
* @public
|
|
131
|
-
*/
|
|
132
|
-
public get disposed(): boolean {
|
|
133
|
-
return this._disposed;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/* INTERNAL ------------------------------------------------------------- */
|
|
137
|
-
|
|
138
|
-
protected _disposed = false;
|
|
139
|
-
|
|
140
|
-
protected _dependencies = new Set<FlowSignal>();
|
|
141
|
-
|
|
142
|
-
protected _listeners = new Set<FlowSignal>();
|
|
143
|
-
|
|
144
|
-
protected _effects = new Set<FlowEffect>();
|
|
145
|
-
|
|
146
|
-
protected _notify(): void {
|
|
147
|
-
FlowGraph.pushEffects(Array.from(this._effects));
|
|
148
|
-
|
|
149
|
-
this._listeners.forEach((listener) => {
|
|
150
|
-
listener._notify();
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/** @internal */ _registerDependency(dependency: FlowSignal): void {
|
|
155
|
-
this._dependencies.add(dependency);
|
|
156
|
-
dependency._registerListener(this);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/** @internal */ _unregisterDependency(dependency: FlowSignal): void {
|
|
160
|
-
this._dependencies.delete(dependency);
|
|
161
|
-
dependency._unregisterListener(this);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/** @internal */ _registerListener(signal: FlowSignal): void {
|
|
165
|
-
this._listeners.add(signal);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/** @internal */ _unregisterListener(signal: FlowSignal): void {
|
|
169
|
-
this._listeners.delete(signal);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/** @internal */ _registerEffect(effect: FlowEffect): void {
|
|
173
|
-
this._effects.add(effect);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/** @internal */ _unregisterEffect(effect: FlowEffect): void {
|
|
177
|
-
this._effects.delete(effect);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Creates a new signal for event-like notifications.
|
|
183
|
-
*
|
|
184
|
-
* @returns A new instance of {@link FlowSignal}.
|
|
185
|
-
*
|
|
186
|
-
* @remarks
|
|
187
|
-
* Use signals to announce “something happened” when no payload is needed. Track
|
|
188
|
-
* them with `watch(t)` inside effects/derivations and trigger them to re-run
|
|
189
|
-
* dependents.
|
|
190
|
-
*
|
|
191
|
-
* @example
|
|
192
|
-
* ```typescript
|
|
193
|
-
* const $ready = signal();
|
|
194
|
-
*
|
|
195
|
-
* effect((t) => {
|
|
196
|
-
* $ready.watch(t);
|
|
197
|
-
* console.log("ready!");
|
|
198
|
-
* });
|
|
199
|
-
*
|
|
200
|
-
* $ready.trigger(); // logs "ready!"
|
|
201
|
-
* ```
|
|
202
|
-
*
|
|
203
|
-
* @public
|
|
204
|
-
*/
|
|
205
|
-
export function signal(): FlowSignal {
|
|
206
|
-
return new FlowSignal();
|
|
207
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { FlowSignal } from "./flowSignal";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Tracking context passed to reactive callbacks.
|
|
5
|
-
*
|
|
6
|
-
* @remarks
|
|
7
|
-
* Effects and derivations receive an instance of `FlowTracker` as the `t`
|
|
8
|
-
* parameter. Use it inside your callback to register dependencies (for example
|
|
9
|
-
* via APIs that accept `t`) so the callback can re-run when those dependencies
|
|
10
|
-
* change. Typical users do not implement this interface directly; it is
|
|
11
|
-
* implemented by the reactive primitives themselves.
|
|
12
|
-
*
|
|
13
|
-
* @public
|
|
14
|
-
*/
|
|
15
|
-
export interface FlowTracker {
|
|
16
|
-
/** @internal */ _registerDependency(signal: FlowSignal): void;
|
|
17
|
-
}
|
package/src/flow/base/index.ts
DELETED
package/src/flow/base/utils.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Excludes `Promise` types from `T`, returning `never` if `T` is a promise.
|
|
3
|
-
*
|
|
4
|
-
* @remarks
|
|
5
|
-
* Use `NotPromise<T>` to constrain generics to synchronous values. It is helpful
|
|
6
|
-
* when an API must reject promise inputs while accepting other types unchanged.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* function useSync<T>(value: NotPromise<T>) {
|
|
11
|
-
* // value cannot be a Promise
|
|
12
|
-
* return value;
|
|
13
|
-
* }
|
|
14
|
-
*
|
|
15
|
-
* useSync(123); // ok
|
|
16
|
-
* // useSync(Promise.resolve(1)); // type error
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export type NotPromise<T> = T extends Promise<unknown> ? never : T;
|
|
@@ -1,409 +0,0 @@
|
|
|
1
|
-
import { FlowGraph, isDisposable } from "../base";
|
|
2
|
-
import { FlowNode, type FlowState, state } from "../nodes";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Represents the actions that can be performed on a FlowArray.
|
|
6
|
-
* @public
|
|
7
|
-
*/
|
|
8
|
-
export type FlowArrayAction<T> =
|
|
9
|
-
| {
|
|
10
|
-
type: "set";
|
|
11
|
-
items: T[];
|
|
12
|
-
}
|
|
13
|
-
| {
|
|
14
|
-
type: "update";
|
|
15
|
-
index: number;
|
|
16
|
-
item: T;
|
|
17
|
-
}
|
|
18
|
-
| {
|
|
19
|
-
type: "push";
|
|
20
|
-
item: T;
|
|
21
|
-
}
|
|
22
|
-
| {
|
|
23
|
-
type: "pop";
|
|
24
|
-
}
|
|
25
|
-
| {
|
|
26
|
-
type: "unshift";
|
|
27
|
-
item: T;
|
|
28
|
-
}
|
|
29
|
-
| {
|
|
30
|
-
type: "shift";
|
|
31
|
-
}
|
|
32
|
-
| {
|
|
33
|
-
type: "splice";
|
|
34
|
-
start: number;
|
|
35
|
-
deleteCount: number;
|
|
36
|
-
items: T[];
|
|
37
|
-
}
|
|
38
|
-
| {
|
|
39
|
-
type: "clear";
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Represents a reactive array.
|
|
44
|
-
* @public
|
|
45
|
-
*/
|
|
46
|
-
export class FlowArray<T> extends FlowNode<T[]> {
|
|
47
|
-
/**
|
|
48
|
-
* Last action performed on the FlowArray.
|
|
49
|
-
* @public
|
|
50
|
-
*/
|
|
51
|
-
$lastAction: FlowState<FlowArrayAction<T>>;
|
|
52
|
-
protected declare _value: T[];
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Creates an instance of FlowArray.
|
|
56
|
-
* @param value - Initial array value.
|
|
57
|
-
* @public
|
|
58
|
-
*/
|
|
59
|
-
constructor(value: T[] = []) {
|
|
60
|
-
super(value);
|
|
61
|
-
this.$lastAction = state<FlowArrayAction<T>>({
|
|
62
|
-
type: "set",
|
|
63
|
-
items: value,
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Gets the current length of the array.
|
|
69
|
-
* @returns The length of the array.
|
|
70
|
-
* @public
|
|
71
|
-
*/
|
|
72
|
-
get length(): number {
|
|
73
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
74
|
-
return this._value.length;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Internal method to get the raw value.
|
|
79
|
-
* @internal
|
|
80
|
-
*/
|
|
81
|
-
protected _getRaw(): T[] {
|
|
82
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
83
|
-
return [...this._value]; // Ensure nobody can modify the original array
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Replaces the entire array with new items.
|
|
88
|
-
* @param items - The new array of items.
|
|
89
|
-
* @public
|
|
90
|
-
*/
|
|
91
|
-
override async set(items: T[]): Promise<void> {
|
|
92
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
93
|
-
const update = () => {
|
|
94
|
-
// compute current value
|
|
95
|
-
const currentValue = this._value;
|
|
96
|
-
|
|
97
|
-
if (currentValue !== items) {
|
|
98
|
-
// dispose old items
|
|
99
|
-
currentValue.forEach((item) => {
|
|
100
|
-
if (isDisposable(item)) item.dispose({ self: true });
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
// assign new items
|
|
104
|
-
this._value = items;
|
|
105
|
-
|
|
106
|
-
// emit last action
|
|
107
|
-
this.$lastAction.set({ type: "set", items: items });
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// return value changed check
|
|
111
|
-
return currentValue !== items;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const notify = () => {
|
|
115
|
-
// call super method to avoid setting dirty flag back to true
|
|
116
|
-
super._notify();
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
return FlowGraph.requestWrite(notify, update);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Replaces an item at a specific index.
|
|
124
|
-
* @param index - The index of the item to replace.
|
|
125
|
-
* @param item - The new item.
|
|
126
|
-
* @public
|
|
127
|
-
*/
|
|
128
|
-
async update(index: number, item: T): Promise<void> {
|
|
129
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
130
|
-
const update = () => {
|
|
131
|
-
if (index < 0 || index >= this._value.length) {
|
|
132
|
-
throw new Error("[PicoFlow] Index out of bounds");
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// compute current value
|
|
136
|
-
const currentValue = this._value[index];
|
|
137
|
-
|
|
138
|
-
if (currentValue !== item) {
|
|
139
|
-
// dispose item
|
|
140
|
-
if (isDisposable(currentValue)) {
|
|
141
|
-
currentValue.dispose({ self: true });
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// update item
|
|
145
|
-
this._value[index] = item;
|
|
146
|
-
|
|
147
|
-
// emit last action
|
|
148
|
-
this.$lastAction.set({ type: "update", index: index, item: item });
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// return value changed check
|
|
152
|
-
return currentValue !== item;
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
const notify = () => {
|
|
156
|
-
// call super method to avoid setting dirty flag back to true
|
|
157
|
-
super._notify();
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
return FlowGraph.requestWrite(notify, update);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Appends an item to the end of the array.
|
|
165
|
-
* @param item - The item to append.
|
|
166
|
-
* @public
|
|
167
|
-
*/
|
|
168
|
-
async push(item: T): Promise<void> {
|
|
169
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
170
|
-
const update = () => {
|
|
171
|
-
// push item
|
|
172
|
-
this._value.push(item);
|
|
173
|
-
|
|
174
|
-
// emit last action
|
|
175
|
-
this.$lastAction.set({ type: "push", item: item });
|
|
176
|
-
|
|
177
|
-
// return value changed check
|
|
178
|
-
return true;
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
const notify = () => {
|
|
182
|
-
// call super method to avoid setting dirty flag back to true
|
|
183
|
-
super._notify();
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
return FlowGraph.requestWrite(notify, update);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Removes the last item from the array.
|
|
191
|
-
* @public
|
|
192
|
-
*/
|
|
193
|
-
async pop(): Promise<void> {
|
|
194
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
195
|
-
|
|
196
|
-
const update = () => {
|
|
197
|
-
// pop item
|
|
198
|
-
const item = this._value.pop();
|
|
199
|
-
|
|
200
|
-
if (item !== undefined) {
|
|
201
|
-
// dispose item
|
|
202
|
-
if (isDisposable(item)) {
|
|
203
|
-
item.dispose({ self: true });
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// emit last action
|
|
207
|
-
this.$lastAction.set({ type: "pop" });
|
|
208
|
-
|
|
209
|
-
// return value changed check
|
|
210
|
-
return true;
|
|
211
|
-
}
|
|
212
|
-
return false;
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
const notify = () => {
|
|
216
|
-
// call super method to avoid setting dirty flag back to true
|
|
217
|
-
super._notify();
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
return FlowGraph.requestWrite(notify, update);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Inserts an item at the beginning of the array.
|
|
225
|
-
* @param item - The item to insert.
|
|
226
|
-
* @public
|
|
227
|
-
*/
|
|
228
|
-
async unshift(item: T): Promise<void> {
|
|
229
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
230
|
-
const update = () => {
|
|
231
|
-
// unshift item
|
|
232
|
-
this._value.unshift(item);
|
|
233
|
-
|
|
234
|
-
// emit last action
|
|
235
|
-
this.$lastAction.set({ type: "unshift", item: item });
|
|
236
|
-
|
|
237
|
-
// return value changed check
|
|
238
|
-
return true;
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
const notify = () => {
|
|
242
|
-
// call super method to avoid setting dirty flag back to true
|
|
243
|
-
super._notify();
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
return FlowGraph.requestWrite(notify, update);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Removes the first item from the array.
|
|
251
|
-
* @public
|
|
252
|
-
*/
|
|
253
|
-
async shift(): Promise<void> {
|
|
254
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
255
|
-
const update = () => {
|
|
256
|
-
// shift item
|
|
257
|
-
const item = this._value.shift();
|
|
258
|
-
|
|
259
|
-
if (item !== undefined) {
|
|
260
|
-
// dispose item
|
|
261
|
-
if (isDisposable(item)) {
|
|
262
|
-
item.dispose({ self: true });
|
|
263
|
-
}
|
|
264
|
-
// emit last action
|
|
265
|
-
this.$lastAction.set({ type: "shift" });
|
|
266
|
-
|
|
267
|
-
// return value changed check
|
|
268
|
-
return true;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
return false;
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
const notify = () => {
|
|
275
|
-
// call super method to avoid setting dirty flag back to true
|
|
276
|
-
super._notify();
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
return FlowGraph.requestWrite(notify, update);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Changes the content of the array.
|
|
284
|
-
* @param start - The starting index.
|
|
285
|
-
* @param deleteCount - Number of items to remove.
|
|
286
|
-
* @param newItems - New items to add.
|
|
287
|
-
* @public
|
|
288
|
-
*/
|
|
289
|
-
async splice(
|
|
290
|
-
start: number,
|
|
291
|
-
deleteCount: number,
|
|
292
|
-
...newItems: T[]
|
|
293
|
-
): Promise<void> {
|
|
294
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
295
|
-
const update = () => {
|
|
296
|
-
// splice items
|
|
297
|
-
const items = this._value.splice(start, deleteCount, ...newItems);
|
|
298
|
-
|
|
299
|
-
// dispose items
|
|
300
|
-
items.forEach((item) => {
|
|
301
|
-
if (isDisposable(item)) item.dispose({ self: true });
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
// emit last action
|
|
305
|
-
this.$lastAction.set({
|
|
306
|
-
type: "splice",
|
|
307
|
-
start: start,
|
|
308
|
-
deleteCount: deleteCount,
|
|
309
|
-
items: newItems,
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
// return value changed check
|
|
313
|
-
return true;
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
const notify = () => {
|
|
317
|
-
// call super method to avoid setting dirty flag back to true
|
|
318
|
-
super._notify();
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
return FlowGraph.requestWrite(notify, update);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* Clears all items from the array.
|
|
326
|
-
* @public
|
|
327
|
-
*/
|
|
328
|
-
async clear(): Promise<void> {
|
|
329
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
330
|
-
const update = () => {
|
|
331
|
-
// dispose old items
|
|
332
|
-
const items = [...this._value];
|
|
333
|
-
items.forEach((item) => {
|
|
334
|
-
if (isDisposable(item)) item.dispose({ self: true });
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
// clear array
|
|
338
|
-
this._value = [];
|
|
339
|
-
|
|
340
|
-
// emit last action
|
|
341
|
-
this.$lastAction.set({ type: "clear" });
|
|
342
|
-
|
|
343
|
-
// return value changed check
|
|
344
|
-
return true;
|
|
345
|
-
};
|
|
346
|
-
|
|
347
|
-
const notify = () => {
|
|
348
|
-
// call super method to avoid setting dirty flag back to true
|
|
349
|
-
super._notify();
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
return FlowGraph.requestWrite(notify, update);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Disposes the FlowArray and its items.
|
|
357
|
-
* @param options - Disposal options.
|
|
358
|
-
* @public
|
|
359
|
-
*/
|
|
360
|
-
override dispose(options?: { self: boolean }): void {
|
|
361
|
-
super.dispose(options);
|
|
362
|
-
this._value.forEach((item) => {
|
|
363
|
-
if (isDisposable(item)) item.dispose(options);
|
|
364
|
-
});
|
|
365
|
-
this._value = [];
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
/* INTERNAL */
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* Creates a new reactive array with mutation methods and fine-grained action tracking.
|
|
373
|
-
*
|
|
374
|
-
* @typeParam T - The type of the array elements.
|
|
375
|
-
* @param initial - An optional array of initial values.
|
|
376
|
-
* @returns A new instance of {@link FlowArray}.
|
|
377
|
-
*
|
|
378
|
-
* @remarks
|
|
379
|
-
* A reactive array provides array-like mutation methods (push, pop, shift, unshift, splice)
|
|
380
|
-
* and tracks the last operation performed via `$lastAction`. This enables both whole-array
|
|
381
|
-
* reactivity and fine-grained tracking of specific mutations.
|
|
382
|
-
*
|
|
383
|
-
* The array automatically disposes disposable items when they are removed (if they implement
|
|
384
|
-
* the FlowDisposable interface).
|
|
385
|
-
*
|
|
386
|
-
* @example
|
|
387
|
-
* ```typescript
|
|
388
|
-
* const $items = array([1, 2, 3]);
|
|
389
|
-
*
|
|
390
|
-
* // Track the whole array
|
|
391
|
-
* effect((t) => {
|
|
392
|
-
* console.log('Items:', $items.get(t));
|
|
393
|
-
* });
|
|
394
|
-
*
|
|
395
|
-
* // Track the last action
|
|
396
|
-
* effect((t) => {
|
|
397
|
-
* const action = $items.$lastAction.get(t);
|
|
398
|
-
* console.log('Action:', action.type);
|
|
399
|
-
* });
|
|
400
|
-
*
|
|
401
|
-
* $items.push(4); // Logs action: "push"
|
|
402
|
-
* $items.pop(); // Logs action: "pop"
|
|
403
|
-
* ```
|
|
404
|
-
*
|
|
405
|
-
* @public
|
|
406
|
-
*/
|
|
407
|
-
export function array<T>(initial?: T[]): FlowArray<T> {
|
|
408
|
-
return new FlowArray<T>(initial);
|
|
409
|
-
}
|