@ersbeth/picoflow 1.1.2 → 2.0.1
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 +854 -1520
- 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 +29 -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 +36 -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 +23 -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 +35 -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 +25 -0
- package/dist/types/nodes/arrayNode.d.ts.map +1 -0
- package/dist/types/nodes/effectNode.d.ts +16 -0
- package/dist/types/nodes/effectNode.d.ts.map +1 -0
- package/dist/types/nodes/index.d.ts +8 -0
- package/dist/types/nodes/index.d.ts.map +1 -0
- package/dist/types/nodes/mapNode.d.ts +19 -0
- package/dist/types/nodes/mapNode.d.ts.map +1 -0
- package/dist/types/nodes/signalNode.d.ts +10 -0
- package/dist/types/nodes/signalNode.d.ts.map +1 -0
- package/dist/types/nodes/valueAsyncNode.d.ts +23 -0
- package/dist/types/nodes/valueAsyncNode.d.ts.map +1 -0
- package/dist/types/nodes/valueNode.d.ts +20 -0
- package/dist/types/nodes/valueNode.d.ts.map +1 -0
- package/dist/types/nodes/valueSyncNode.d.ts +23 -0
- package/dist/types/nodes/valueSyncNode.d.ts.map +1 -0
- package/dist/types/schedulers/asyncResolver.d.ts +19 -0
- package/dist/types/schedulers/asyncResolver.d.ts.map +1 -0
- package/dist/types/schedulers/asyncScheduler.d.ts +20 -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 +9 -0
- package/dist/types/schedulers/pendingError.d.ts.map +1 -0
- package/dist/types/schedulers/scheduler.d.ts +10 -0
- package/dist/types/schedulers/scheduler.d.ts.map +1 -0
- package/dist/types/schedulers/syncResolver.d.ts +19 -0
- package/dist/types/schedulers/syncResolver.d.ts.map +1 -0
- package/dist/types/schedulers/syncScheduler.d.ts +19 -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 +63 -79
- 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 +37 -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 +24 -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 +92 -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 +180 -0
- package/src/nodes/effectNode.ts +58 -0
- package/src/nodes/index.ts +7 -0
- package/src/nodes/mapNode.ts +125 -0
- package/src/nodes/signalNode.ts +19 -0
- package/src/nodes/valueAsyncNode.ts +85 -0
- package/src/nodes/valueNode.ts +148 -0
- package/src/nodes/valueSyncNode.ts +125 -0
- package/src/schedulers/asyncResolver.ts +78 -0
- package/src/schedulers/asyncScheduler.ts +66 -0
- package/src/schedulers/index.ts +4 -0
- package/src/schedulers/pendingError.ts +13 -0
- package/src/schedulers/scheduler.ts +9 -0
- package/src/schedulers/syncResolver.ts +69 -0
- package/src/schedulers/syncScheduler.ts +55 -0
- package/test/base/pendingError.test.ts +67 -0
- package/test/converters/solid.derivation.browser.test.tsx +69 -0
- package/test/converters/solid.node.test.ts +654 -0
- package/test/converters/solid.state.browser.test.tsx +1592 -0
- package/test/reactivity/flowSignal.test.ts +226 -0
- package/test/reactivity/nodes/async/asyncScheduler/asyncResolver.test.ts +593 -0
- package/test/reactivity/nodes/async/asyncScheduler/asyncScheduler.test.ts +317 -0
- package/test/reactivity/nodes/async/flowConstantAsync.test.ts +652 -0
- package/test/reactivity/nodes/async/flowDerivation.test.ts +898 -0
- package/test/reactivity/nodes/async/flowDerivationAsync.test.ts +1716 -0
- package/test/reactivity/nodes/async/flowStateAsync.test.ts +708 -0
- package/test/reactivity/nodes/async/flowWritableDerivationAsync.test.ts +614 -0
- package/test/reactivity/nodes/collections/flowArray.asyncStates.test.ts +1289 -0
- package/test/reactivity/nodes/collections/flowArray.scalars.test.ts +961 -0
- package/test/reactivity/nodes/collections/flowArray.states.test.ts +1035 -0
- package/test/reactivity/nodes/collections/flowMap.asyncStates.test.ts +960 -0
- package/test/reactivity/nodes/collections/flowMap.scalars.test.ts +775 -0
- package/test/reactivity/nodes/collections/flowMap.states.test.ts +958 -0
- package/test/reactivity/nodes/sync/flowConstant.test.ts +377 -0
- package/test/reactivity/nodes/sync/flowDerivation.test.ts +896 -0
- package/test/reactivity/nodes/sync/flowState.test.ts +341 -0
- package/test/reactivity/nodes/sync/flowWritableDerivation.test.ts +603 -0
- package/test/vitest.d.ts +10 -0
- package/tsconfig.json +31 -20
- package/typedoc.json +35 -35
- package/vite.config.ts +25 -23
- package/vitest.browser.config.ts +21 -0
- package/vitest.config.ts +12 -12
- package/.cursor/plans/unifier-flowresource-avec-flowderivation-c9506e24.plan.md +0 -372
- package/.cursor/plans/update-js-e795d61b.plan.md +0 -567
- package/dist/types/flow/base/flowDisposable.d.ts +0 -67
- package/dist/types/flow/base/flowDisposable.d.ts.map +0 -1
- package/dist/types/flow/base/flowEffect.d.ts +0 -127
- package/dist/types/flow/base/flowEffect.d.ts.map +0 -1
- package/dist/types/flow/base/flowGraph.d.ts +0 -97
- package/dist/types/flow/base/flowGraph.d.ts.map +0 -1
- package/dist/types/flow/base/flowSignal.d.ts +0 -134
- package/dist/types/flow/base/flowSignal.d.ts.map +0 -1
- package/dist/types/flow/base/flowTracker.d.ts +0 -15
- package/dist/types/flow/base/flowTracker.d.ts.map +0 -1
- package/dist/types/flow/base/index.d.ts +0 -7
- package/dist/types/flow/base/index.d.ts.map +0 -1
- package/dist/types/flow/base/utils.d.ts +0 -20
- package/dist/types/flow/base/utils.d.ts.map +0 -1
- package/dist/types/flow/collections/flowArray.d.ts +0 -148
- package/dist/types/flow/collections/flowArray.d.ts.map +0 -1
- package/dist/types/flow/collections/flowMap.d.ts +0 -224
- package/dist/types/flow/collections/flowMap.d.ts.map +0 -1
- package/dist/types/flow/collections/index.d.ts.map +0 -1
- package/dist/types/flow/index.d.ts +0 -4
- package/dist/types/flow/index.d.ts.map +0 -1
- package/dist/types/flow/nodes/async/flowConstantAsync.d.ts +0 -137
- package/dist/types/flow/nodes/async/flowConstantAsync.d.ts.map +0 -1
- package/dist/types/flow/nodes/async/flowDerivationAsync.d.ts +0 -137
- package/dist/types/flow/nodes/async/flowDerivationAsync.d.ts.map +0 -1
- package/dist/types/flow/nodes/async/flowNodeAsync.d.ts +0 -343
- package/dist/types/flow/nodes/async/flowNodeAsync.d.ts.map +0 -1
- package/dist/types/flow/nodes/async/flowReadonlyAsync.d.ts +0 -81
- package/dist/types/flow/nodes/async/flowReadonlyAsync.d.ts.map +0 -1
- package/dist/types/flow/nodes/async/flowStateAsync.d.ts +0 -111
- package/dist/types/flow/nodes/async/flowStateAsync.d.ts.map +0 -1
- package/dist/types/flow/nodes/async/index.d.ts.map +0 -1
- package/dist/types/flow/nodes/index.d.ts +0 -3
- package/dist/types/flow/nodes/index.d.ts.map +0 -1
- package/dist/types/flow/nodes/sync/flowConstant.d.ts +0 -108
- package/dist/types/flow/nodes/sync/flowConstant.d.ts.map +0 -1
- package/dist/types/flow/nodes/sync/flowDerivation.d.ts +0 -100
- package/dist/types/flow/nodes/sync/flowDerivation.d.ts.map +0 -1
- package/dist/types/flow/nodes/sync/flowNode.d.ts +0 -314
- package/dist/types/flow/nodes/sync/flowNode.d.ts.map +0 -1
- package/dist/types/flow/nodes/sync/flowReadonly.d.ts +0 -57
- package/dist/types/flow/nodes/sync/flowReadonly.d.ts.map +0 -1
- package/dist/types/flow/nodes/sync/flowState.d.ts +0 -96
- package/dist/types/flow/nodes/sync/flowState.d.ts.map +0 -1
- package/dist/types/flow/nodes/sync/index.d.ts.map +0 -1
- package/dist/types/solid/converters.d.ts +0 -57
- package/dist/types/solid/converters.d.ts.map +0 -1
- package/dist/types/solid/index.d.ts +0 -3
- package/dist/types/solid/index.d.ts.map +0 -1
- package/dist/types/solid/primitives.d.ts +0 -181
- package/dist/types/solid/primitives.d.ts.map +0 -1
- package/docs/api/classes/FlowArray.md +0 -489
- package/docs/api/classes/FlowConstant.md +0 -350
- package/docs/api/classes/FlowDerivation.md +0 -334
- package/docs/api/classes/FlowEffect.md +0 -100
- package/docs/api/classes/FlowMap.md +0 -512
- package/docs/api/classes/FlowObservable.md +0 -306
- package/docs/api/classes/FlowResource.md +0 -380
- package/docs/api/classes/FlowResourceAsync.md +0 -362
- package/docs/api/classes/FlowSignal.md +0 -160
- package/docs/api/classes/FlowState.md +0 -368
- package/docs/api/classes/FlowStream.md +0 -367
- package/docs/api/classes/FlowStreamAsync.md +0 -364
- package/docs/api/classes/SolidDerivation.md +0 -75
- package/docs/api/classes/SolidResource.md +0 -91
- package/docs/api/classes/SolidState.md +0 -71
- package/docs/api/classes/TrackingContext.md +0 -33
- package/docs/api/functions/effect.md +0 -49
- package/docs/api/functions/resource.md +0 -52
- package/docs/api/functions/resourceAsync.md +0 -50
- package/docs/api/functions/stream.md +0 -53
- package/docs/api/functions/streamAsync.md +0 -50
- package/docs/api/interfaces/SolidObservable.md +0 -19
- package/docs/api/type-aliases/FlowStreamDisposer.md +0 -15
- package/docs/api/type-aliases/FlowStreamSetter.md +0 -27
- package/docs/api/type-aliases/FlowStreamUpdater.md +0 -32
- package/docs/api/type-aliases/SolidGetter.md +0 -17
- package/docs/guide/primitives/resources.md +0 -858
- package/docs/guide/primitives/streams.md +0 -931
- package/src/flow/base/flowDisposable.ts +0 -71
- package/src/flow/base/flowEffect.ts +0 -171
- package/src/flow/base/flowGraph.ts +0 -288
- package/src/flow/base/flowSignal.ts +0 -207
- package/src/flow/base/flowTracker.ts +0 -17
- package/src/flow/base/index.ts +0 -6
- package/src/flow/base/utils.ts +0 -19
- package/src/flow/collections/flowArray.ts +0 -409
- package/src/flow/collections/flowMap.ts +0 -398
- package/src/flow/nodes/async/flowConstantAsync.ts +0 -142
- package/src/flow/nodes/async/flowDerivationAsync.ts +0 -143
- package/src/flow/nodes/async/flowNodeAsync.ts +0 -474
- package/src/flow/nodes/async/flowReadonlyAsync.ts +0 -81
- package/src/flow/nodes/async/flowStateAsync.ts +0 -116
- package/src/flow/nodes/await/advanced/index.ts +0 -5
- package/src/flow/nodes/await/advanced/resource.ts +0 -134
- package/src/flow/nodes/await/advanced/resourceAsync.ts +0 -109
- package/src/flow/nodes/await/advanced/stream.ts +0 -188
- package/src/flow/nodes/await/advanced/streamAsync.ts +0 -176
- package/src/flow/nodes/await/flowConstantAwait.ts +0 -154
- package/src/flow/nodes/await/flowDerivationAwait.ts +0 -154
- package/src/flow/nodes/await/flowNodeAwait.ts +0 -508
- package/src/flow/nodes/await/flowReadonlyAwait.ts +0 -89
- package/src/flow/nodes/await/flowStateAwait.ts +0 -130
- package/src/flow/nodes/await/index.ts +0 -5
- package/src/flow/nodes/index.ts +0 -3
- package/src/flow/nodes/sync/flowConstant.ts +0 -111
- package/src/flow/nodes/sync/flowDerivation.ts +0 -105
- package/src/flow/nodes/sync/flowNode.ts +0 -439
- package/src/flow/nodes/sync/flowReadonly.ts +0 -57
- package/src/flow/nodes/sync/flowState.ts +0 -101
- package/src/solid/converters.ts +0 -148
- package/src/solid/index.ts +0 -2
- package/src/solid/primitives.ts +0 -215
- package/test/base/flowEffect.test.ts +0 -108
- package/test/base/flowGraph.test.ts +0 -485
- package/test/base/flowSignal.test.ts +0 -372
- package/test/collections/flowArray.asyncStates.test.ts +0 -1553
- package/test/collections/flowArray.scalars.test.ts +0 -1129
- package/test/collections/flowArray.states.test.ts +0 -1365
- package/test/collections/flowMap.asyncStates.test.ts +0 -1105
- package/test/collections/flowMap.scalars.test.ts +0 -877
- package/test/collections/flowMap.states.test.ts +0 -1097
- package/test/nodes/async/flowConstantAsync.test.ts +0 -860
- package/test/nodes/async/flowDerivationAsync.test.ts +0 -1517
- package/test/nodes/async/flowStateAsync.test.ts +0 -1387
- package/test/nodes/await/advanced/resource.test.ts +0 -129
- package/test/nodes/await/advanced/resourceAsync.test.ts +0 -108
- package/test/nodes/await/advanced/stream.test.ts +0 -198
- package/test/nodes/await/advanced/streamAsync.test.ts +0 -196
- package/test/nodes/await/flowConstantAwait.test.ts +0 -643
- package/test/nodes/await/flowDerivationAwait.test.ts +0 -1583
- package/test/nodes/await/flowStateAwait.test.ts +0 -999
- package/test/nodes/mixed/derivation.test.ts +0 -1527
- package/test/nodes/sync/flowConstant.test.ts +0 -620
- package/test/nodes/sync/flowDerivation.test.ts +0 -1373
- package/test/nodes/sync/flowState.test.ts +0 -945
- package/test/solid/converters.test.ts +0 -721
- package/test/solid/primitives.test.ts +0 -1031
- /package/dist/types/{flow → api/nodes}/collections/index.d.ts +0 -0
- /package/docs/guide/advanced/{upgrading.md → migration-v1.md} +0 -0
- /package/src/{flow → api/nodes}/collections/index.ts +0 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { createEffect, createResource, onCleanup, onMount, type Resource, resetErrorBoundaries } from "solid-js";
|
|
2
|
+
import { type FlowEffect, type FlowObservable, type FlowTracker, type NotPromise, subscribe } from "../api";
|
|
3
|
+
import { ValueAsyncNode, ValueSyncNode } from "../nodes";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Internal helper that converts a PicoFlow node into a SolidJS resource.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
function fromNode<T>(node: ValueAsyncNode<T> | ValueSyncNode<T>): Resource<T> {
|
|
10
|
+
const [resource, { refetch }] = createResource(() => node.pick());
|
|
11
|
+
|
|
12
|
+
let fx: FlowEffect;
|
|
13
|
+
|
|
14
|
+
onMount(() => {
|
|
15
|
+
fx = subscribe(
|
|
16
|
+
// data
|
|
17
|
+
(t) => node.get(t),
|
|
18
|
+
// onData
|
|
19
|
+
() => {
|
|
20
|
+
refetch(); // Force createResource to refetch
|
|
21
|
+
},
|
|
22
|
+
// onError
|
|
23
|
+
() => {
|
|
24
|
+
refetch(); // Force createResource to refetch
|
|
25
|
+
},
|
|
26
|
+
// onPending
|
|
27
|
+
() => {
|
|
28
|
+
refetch(); // Force createResource to refetch
|
|
29
|
+
},
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
createEffect(() => {
|
|
34
|
+
// reset error boundaries when error state changes
|
|
35
|
+
resource.error ?? resource();
|
|
36
|
+
resetErrorBoundaries();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
onCleanup(() => fx.dispose());
|
|
40
|
+
|
|
41
|
+
return resource;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Internal helper that wraps a getter function in a PicoFlow node and converts it to a SolidJS resource.
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
function fromGetter<T>(getter: (t: FlowTracker) => NotPromise<T>): Resource<T> {
|
|
49
|
+
const derivation = new ValueSyncNode<T>((t) => {
|
|
50
|
+
return getter(t);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return fromNode(derivation);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Converts a PicoFlow observable or getter function into a SolidJS resource.
|
|
58
|
+
*
|
|
59
|
+
* @param flow - The FlowObservable or getter function to convert.
|
|
60
|
+
* @returns A SolidJS Resource that wraps the value or computation.
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
* This function bridges PicoFlow's reactive system with SolidJS, allowing you to use
|
|
64
|
+
* PicoFlow primitives and computations within Solid components. All conversions return a
|
|
65
|
+
* SolidJS Resource, which can handle both synchronous and asynchronous values seamlessly.
|
|
66
|
+
*
|
|
67
|
+
* The conversion works with:
|
|
68
|
+
* - **FlowObservable**: Any PicoFlow reactive primitive (e.g., from `state()`, `derivation()`, `stateAsync()`, `derivationAsync()`)
|
|
69
|
+
* - **Getter functions**: Computation functions that use a FlowTracker to access reactive values
|
|
70
|
+
*
|
|
71
|
+
* The created Resource automatically subscribes to the PicoFlow observables and updates
|
|
72
|
+
* when their values change. The subscription is properly cleaned up when the Solid
|
|
73
|
+
* component unmounts.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* import { from } from 'picoflow/solid';
|
|
78
|
+
* import { state, derivation } from 'picoflow';
|
|
79
|
+
*
|
|
80
|
+
* // Convert a PicoFlow state to a Solid resource
|
|
81
|
+
* const $count = state(0);
|
|
82
|
+
* const solidCount = from($count);
|
|
83
|
+
*
|
|
84
|
+
* // Use in a Solid component
|
|
85
|
+
* function Counter() {
|
|
86
|
+
* return <div>Count: {solidCount()}</div>;
|
|
87
|
+
* }
|
|
88
|
+
*
|
|
89
|
+
* // Or convert a computation function
|
|
90
|
+
* const solidDerived = from((t) => {
|
|
91
|
+
* return $count.get(t) * 2;
|
|
92
|
+
* });
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @public
|
|
96
|
+
*/
|
|
97
|
+
export function from<T>(flow: FlowObservable<T>): Resource<T>;
|
|
98
|
+
export function from<T>(flow: (t: FlowTracker) => NotPromise<T>): Resource<T>;
|
|
99
|
+
export function from<T>(flow: FlowObservable<T> | ((t: FlowTracker) => NotPromise<T>)): Resource<T> {
|
|
100
|
+
if (flow instanceof ValueAsyncNode || flow instanceof ValueSyncNode) {
|
|
101
|
+
return fromNode(flow);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (typeof flow === "function") {
|
|
105
|
+
return fromGetter(flow);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
throw new Error("Invalid flow type");
|
|
109
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,64 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* # PicoFlow
|
|
5
|
-
*
|
|
6
|
-
* PicoFlow is a lightweight reactive dataflow library that provides a comprehensive set of
|
|
7
|
-
* reactive primitives for building reactive applications with explicit dependency tracking.
|
|
8
|
-
*
|
|
9
|
-
* ## Core Concepts
|
|
10
|
-
*
|
|
11
|
-
* **Reactive Primitives:**
|
|
12
|
-
* - {@link FlowSignal}: Event-like notifications without values
|
|
13
|
-
* - {@link FlowState}: Mutable reactive values
|
|
14
|
-
* - {@link FlowConstant}: Immutable reactive values (computed once)
|
|
15
|
-
* - {@link FlowDerivation}: Computed values that track dependencies
|
|
16
|
-
* - {@link FlowEffect}: Side effects that run when dependencies change
|
|
17
|
-
*
|
|
18
|
-
* **Advanced Primitives:**
|
|
19
|
-
* - {@link FlowArray}: Reactive arrays with mutation tracking
|
|
20
|
-
* - {@link FlowMap}: Reactive maps with operation tracking
|
|
21
|
-
* - {@link FlowResource}: Async data fetching returning `T | undefined`
|
|
22
|
-
* - {@link FlowResourceAsync}: Async data fetching returning `Promise<T>`
|
|
23
|
-
* - {@link FlowStream}: Event streams from external sources
|
|
24
|
-
* - {@link FlowStreamAsync}: Async event streams returning Promises
|
|
25
|
-
*
|
|
26
|
-
* **Tracking Context:**
|
|
27
|
-
* - {@link TrackingContext}: The core mechanism for explicit dependency tracking
|
|
28
|
-
* - Use `observable.get(t)` to read with tracking
|
|
29
|
-
* - Use `observable.pick()` to read without tracking
|
|
30
|
-
* - Use `signal.watch(t)` to track signals without values
|
|
31
|
-
*
|
|
32
|
-
* ## Key Features
|
|
33
|
-
*
|
|
34
|
-
* - **Explicit tracking**: Full control over what triggers re-execution via TrackingContext
|
|
35
|
-
* - **Lazy evaluation**: Derivations compute only when accessed
|
|
36
|
-
* - **Fine-grained reactivity**: Track specific operations on collections
|
|
37
|
-
* - **Resource management**: Automatic cleanup with dispose patterns
|
|
38
|
-
* - **SolidJS integration**: Seamless bridge to SolidJS primitives
|
|
39
|
-
*
|
|
40
|
-
* ## Basic Usage
|
|
41
|
-
*
|
|
42
|
-
* ```typescript
|
|
43
|
-
* import { state, effect, derivation } from 'picoflow';
|
|
44
|
-
*
|
|
45
|
-
* // Create reactive state
|
|
46
|
-
* const $count = state(0);
|
|
47
|
-
*
|
|
48
|
-
* // Create derived value
|
|
49
|
-
* const $double = derivation((t) => $count.get(t) * 2);
|
|
50
|
-
*
|
|
51
|
-
* // Create effect
|
|
52
|
-
* effect((t) => {
|
|
53
|
-
* console.log('Count:', $count.get(t), 'Double:', $double.get(t));
|
|
54
|
-
* });
|
|
55
|
-
*
|
|
56
|
-
* // Update state
|
|
57
|
-
* $count.set(1); // Logs: "Count: 1 Double: 2"
|
|
58
|
-
* ```
|
|
59
|
-
*
|
|
60
|
-
* @see {@link https://github.com/yourusername/picoflow | GitHub Repository}
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
export * from "./flow";
|
|
64
|
-
export * from "./solid";
|
|
1
|
+
export * from "./api";
|
|
2
|
+
export * from "./converters";
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import type { FlowArray, FlowArrayAction, FlowTracker, NotPromise, UpdateFunction } from "../api";
|
|
2
|
+
import { Disposable } from "../base";
|
|
3
|
+
import { ValueSyncNode } from "./valueSyncNode";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Internal implementation of reactive array with mutation tracking.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export class ArrayNode<T> extends ValueSyncNode<T[]> implements FlowArray<T> {
|
|
10
|
+
$lastAction: ValueSyncNode<FlowArrayAction<T>>;
|
|
11
|
+
protected declare _value: T[];
|
|
12
|
+
|
|
13
|
+
constructor(value: T[] = []) {
|
|
14
|
+
super(value);
|
|
15
|
+
this.$lastAction = new ValueSyncNode<FlowArrayAction<T>>({
|
|
16
|
+
type: "set",
|
|
17
|
+
setItems: value,
|
|
18
|
+
clearedItems: [],
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
override get(tracker: FlowTracker): T[] {
|
|
23
|
+
const values = super.get(tracker);
|
|
24
|
+
return [...values];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
override async pick(): Promise<T[]> {
|
|
28
|
+
const values = await super.pick();
|
|
29
|
+
return [...values];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get length(): number {
|
|
33
|
+
if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
34
|
+
return this._value.length;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
override set(items: NotPromise<T[]>): T[];
|
|
38
|
+
override set(updater: UpdateFunction<T[]>): T[];
|
|
39
|
+
override set(itemsOrUpdater: NotPromise<T[]> | UpdateFunction<T[]>): T[] {
|
|
40
|
+
if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
41
|
+
|
|
42
|
+
// compute previous value
|
|
43
|
+
const previousValue = this._value;
|
|
44
|
+
|
|
45
|
+
// set new value
|
|
46
|
+
// @ts-expect-error - we know that this._value is an array
|
|
47
|
+
super.set(itemsOrUpdater);
|
|
48
|
+
|
|
49
|
+
// emit last action
|
|
50
|
+
this.$lastAction.set({
|
|
51
|
+
type: "set",
|
|
52
|
+
setItems: this._value,
|
|
53
|
+
clearedItems: previousValue,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// return previous value
|
|
57
|
+
return previousValue;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
update(index: number, item: T): T | undefined {
|
|
61
|
+
if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
62
|
+
|
|
63
|
+
if (index < 0 || index >= this._value.length) {
|
|
64
|
+
throw new Error("[PicoFlow] Index out of bounds");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// compute previous value
|
|
68
|
+
const previousValue = this._value[index];
|
|
69
|
+
|
|
70
|
+
// update item
|
|
71
|
+
this._value[index] = item;
|
|
72
|
+
this.notifyDependents();
|
|
73
|
+
|
|
74
|
+
// emit last action
|
|
75
|
+
this.$lastAction.set({
|
|
76
|
+
type: "update",
|
|
77
|
+
index: index,
|
|
78
|
+
setItem: item,
|
|
79
|
+
clearedItem: previousValue,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// return previous value
|
|
83
|
+
return previousValue;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
push(item: T): void {
|
|
87
|
+
if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
88
|
+
|
|
89
|
+
// push item
|
|
90
|
+
this._value.push(item);
|
|
91
|
+
this.notifyDependents();
|
|
92
|
+
|
|
93
|
+
// emit last action
|
|
94
|
+
this.$lastAction.set({ type: "push", addedItem: item });
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
pop(): T | undefined {
|
|
98
|
+
if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
99
|
+
|
|
100
|
+
// pop item
|
|
101
|
+
const item = this._value.pop();
|
|
102
|
+
this.notifyDependents();
|
|
103
|
+
|
|
104
|
+
// emit last action
|
|
105
|
+
this.$lastAction.set({ type: "pop", removedItem: item });
|
|
106
|
+
|
|
107
|
+
// return previous value
|
|
108
|
+
return item;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
unshift(item: T): void {
|
|
112
|
+
if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
113
|
+
|
|
114
|
+
// unshift item
|
|
115
|
+
this._value.unshift(item);
|
|
116
|
+
this.notifyDependents();
|
|
117
|
+
|
|
118
|
+
// emit last action
|
|
119
|
+
this.$lastAction.set({ type: "unshift", addedItem: item });
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
shift(): T | undefined {
|
|
123
|
+
if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
124
|
+
|
|
125
|
+
// shift item
|
|
126
|
+
const item = this._value.shift();
|
|
127
|
+
this.notifyDependents();
|
|
128
|
+
|
|
129
|
+
// emit last action
|
|
130
|
+
this.$lastAction.set({ type: "shift", removedItem: item });
|
|
131
|
+
|
|
132
|
+
// return previous value
|
|
133
|
+
return item;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
splice(start: number, deleteCount: number, ...newItems: T[]): T[] {
|
|
137
|
+
if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
138
|
+
|
|
139
|
+
// splice items
|
|
140
|
+
const items = this._value.splice(start, deleteCount, ...newItems);
|
|
141
|
+
this.notifyDependents();
|
|
142
|
+
|
|
143
|
+
// emit last action
|
|
144
|
+
this.$lastAction.set({
|
|
145
|
+
type: "splice",
|
|
146
|
+
start: start,
|
|
147
|
+
deleteCount: deleteCount,
|
|
148
|
+
addedItems: newItems,
|
|
149
|
+
removedItems: items,
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// return value changed check
|
|
153
|
+
return items;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
clear(): T[] {
|
|
157
|
+
if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
158
|
+
|
|
159
|
+
// compute previous value
|
|
160
|
+
const previousValue = [...this._value];
|
|
161
|
+
|
|
162
|
+
// clear array
|
|
163
|
+
this._value = [];
|
|
164
|
+
this.notifyDependents();
|
|
165
|
+
|
|
166
|
+
// emit last action
|
|
167
|
+
this.$lastAction.set({ type: "clear", clearedItems: previousValue });
|
|
168
|
+
|
|
169
|
+
// return value changed check
|
|
170
|
+
return previousValue;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
override dispose(): void {
|
|
174
|
+
super.dispose();
|
|
175
|
+
this._value.forEach((item) => {
|
|
176
|
+
if (item instanceof Disposable) item.dispose();
|
|
177
|
+
});
|
|
178
|
+
this._value = [];
|
|
179
|
+
}
|
|
180
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FlowDataTracker,
|
|
3
|
+
FlowEffect,
|
|
4
|
+
FlowOnDataListener,
|
|
5
|
+
FlowOnErrorListener,
|
|
6
|
+
FlowOnPendingListener,
|
|
7
|
+
} from "../api";
|
|
8
|
+
import { ExecutionStack, Observer } from "../base";
|
|
9
|
+
import { PendingError } from "../schedulers";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Reactive effect that automatically re-executes when its dependencies change.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export class EffectNode<T> extends Observer implements FlowEffect {
|
|
16
|
+
private _data: FlowDataTracker<T>;
|
|
17
|
+
private _onData: FlowOnDataListener<T>;
|
|
18
|
+
private _onError?: FlowOnErrorListener;
|
|
19
|
+
private _onPending?: FlowOnPendingListener;
|
|
20
|
+
|
|
21
|
+
constructor(
|
|
22
|
+
data: FlowDataTracker<T>,
|
|
23
|
+
onData: FlowOnDataListener<T>,
|
|
24
|
+
onError?: FlowOnErrorListener,
|
|
25
|
+
onPending?: FlowOnPendingListener,
|
|
26
|
+
) {
|
|
27
|
+
super();
|
|
28
|
+
this._data = data;
|
|
29
|
+
this._onData = onData;
|
|
30
|
+
this._onError = onError;
|
|
31
|
+
this._onPending = onPending;
|
|
32
|
+
this.execute();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
notify(): void {
|
|
36
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
37
|
+
ExecutionStack.pushEffect(this as unknown as EffectNode<unknown>);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
execute(): void {
|
|
41
|
+
try {
|
|
42
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
43
|
+
this.clearDependencies();
|
|
44
|
+
const data = this._data(this);
|
|
45
|
+
this._onData(data);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if (error instanceof PendingError) {
|
|
48
|
+
this._onPending?.();
|
|
49
|
+
} else {
|
|
50
|
+
if (this._onError) {
|
|
51
|
+
this._onError(error instanceof Error ? error : new Error(String(error)));
|
|
52
|
+
} else {
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { FlowMap, FlowMapAction, NotPromise, UpdateFunction } from "../api";
|
|
2
|
+
import { Disposable } from "../base";
|
|
3
|
+
import { ValueSyncNode } from "./valueSyncNode";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Internal implementation of reactive map with mutation tracking.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export class MapNode<K, V> extends ValueSyncNode<Map<K, V>> implements FlowMap<K, V> {
|
|
10
|
+
public $lastAction: ValueSyncNode<FlowMapAction<K, V>>;
|
|
11
|
+
protected declare _value: Map<K, V>;
|
|
12
|
+
|
|
13
|
+
constructor(value: Map<K, V> = new Map()) {
|
|
14
|
+
super(value);
|
|
15
|
+
this.$lastAction = new ValueSyncNode<FlowMapAction<K, V>>({
|
|
16
|
+
type: "set",
|
|
17
|
+
setMap: value,
|
|
18
|
+
clearedMap: new Map(),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
add(key: K, value: V) {
|
|
23
|
+
if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
24
|
+
|
|
25
|
+
// get value
|
|
26
|
+
const previousValue = this._value.get(key);
|
|
27
|
+
if (previousValue) {
|
|
28
|
+
throw new Error("[PicoFlow] Key already exists");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// add key
|
|
32
|
+
this._value.set(key, value);
|
|
33
|
+
this.notifyDependents();
|
|
34
|
+
|
|
35
|
+
// emit last action
|
|
36
|
+
this.$lastAction.set({ type: "add", key, addedValue: value });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
update(key: K, value: V): V {
|
|
40
|
+
if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
41
|
+
|
|
42
|
+
// get value
|
|
43
|
+
const previousValue = this._value.get(key);
|
|
44
|
+
if (!previousValue) throw new Error("[PicoFlow] Key does not exist");
|
|
45
|
+
|
|
46
|
+
// update key
|
|
47
|
+
this._value.set(key, value);
|
|
48
|
+
this.notifyDependents();
|
|
49
|
+
|
|
50
|
+
// emit last action
|
|
51
|
+
this.$lastAction.set({
|
|
52
|
+
type: "update",
|
|
53
|
+
key,
|
|
54
|
+
setValue: value,
|
|
55
|
+
clearedValue: previousValue,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// return previous value
|
|
59
|
+
return previousValue;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
delete(key: K): V {
|
|
63
|
+
if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
64
|
+
|
|
65
|
+
// get value
|
|
66
|
+
const value = this._value.get(key);
|
|
67
|
+
if (value === undefined) throw new Error("[PicoFlow] Key does not exist");
|
|
68
|
+
|
|
69
|
+
// delete key
|
|
70
|
+
this._value.delete(key);
|
|
71
|
+
this.notifyDependents();
|
|
72
|
+
|
|
73
|
+
// emit last action
|
|
74
|
+
this.$lastAction.set({ type: "delete", key, removedValue: value });
|
|
75
|
+
|
|
76
|
+
// return previous value
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
override set(map: NotPromise<Map<K, V>>): Map<K, V>;
|
|
81
|
+
override set(updater: UpdateFunction<Map<K, V>>): Map<K, V>;
|
|
82
|
+
override set(mapOrUpdater: NotPromise<Map<K, V>> | UpdateFunction<Map<K, V>>): Map<K, V> {
|
|
83
|
+
if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
84
|
+
// compute current value
|
|
85
|
+
const previousValue = this._value;
|
|
86
|
+
|
|
87
|
+
// @ts-expect-error - we know that this._value is a Map
|
|
88
|
+
super.set(mapOrUpdater);
|
|
89
|
+
|
|
90
|
+
// emit last action
|
|
91
|
+
this.$lastAction.set({
|
|
92
|
+
type: "set",
|
|
93
|
+
setMap: this._value,
|
|
94
|
+
clearedMap: previousValue,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// return previous value
|
|
98
|
+
return previousValue;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
clear(): Map<K, V> {
|
|
102
|
+
if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
103
|
+
|
|
104
|
+
// compute previous value
|
|
105
|
+
const previousValue = this._value;
|
|
106
|
+
|
|
107
|
+
// clear map
|
|
108
|
+
this._value = new Map();
|
|
109
|
+
this.notifyDependents();
|
|
110
|
+
|
|
111
|
+
// emit last action
|
|
112
|
+
this.$lastAction.set({ type: "clear", clearedMap: previousValue });
|
|
113
|
+
|
|
114
|
+
// return value changed check
|
|
115
|
+
return previousValue;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
override dispose(): void {
|
|
119
|
+
super.dispose();
|
|
120
|
+
this._value.forEach((item) => {
|
|
121
|
+
if (item instanceof Disposable) item.dispose();
|
|
122
|
+
});
|
|
123
|
+
this._value.clear();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { FlowEffect, FlowOnDataListener, FlowOnErrorListener, FlowOnPendingListener, FlowSignal } from "../api";
|
|
2
|
+
import { Observable, type Observer } from "../base";
|
|
3
|
+
import { EffectNode } from "./effectNode";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Manual trigger that notifies subscribers without carrying data.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export class SignalNode extends Observable<void> implements FlowSignal {
|
|
10
|
+
subscribe(
|
|
11
|
+
onTrigger: FlowOnDataListener<void>,
|
|
12
|
+
onError?: FlowOnErrorListener,
|
|
13
|
+
onPending?: FlowOnPendingListener,
|
|
14
|
+
): FlowEffect {
|
|
15
|
+
if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
16
|
+
const effect = new EffectNode<void>((t) => this.watch(t as unknown as Observer), onTrigger, onError, onPending);
|
|
17
|
+
return effect;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { DerivationFunctionAsync, InitFunctionAsync, NotPromise, UpdateFunctionAsync } from "../api";
|
|
2
|
+
import { AsyncScheduler } from "../schedulers";
|
|
3
|
+
import { ValueNode } from "./valueNode";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Function that computes a value asynchronously (either initialization or derivation).
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export type ComputeFunctionAsync<T> = InitFunctionAsync<T> | DerivationFunctionAsync<T>;
|
|
10
|
+
/**
|
|
11
|
+
* Asynchronous reactive value that resolves promises and propagates results when settled.
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export class ValueAsyncNode<T extends NotPromise<unknown>> extends ValueNode<T> {
|
|
15
|
+
protected _scheduler: AsyncScheduler<T>;
|
|
16
|
+
private _compute: () => Promise<T>;
|
|
17
|
+
|
|
18
|
+
constructor(promiseOrCompute: Promise<T> | ComputeFunctionAsync<T>) {
|
|
19
|
+
super();
|
|
20
|
+
if (typeof promiseOrCompute === "function") {
|
|
21
|
+
// compute is a function
|
|
22
|
+
this._compute = () => promiseOrCompute(this, this._value);
|
|
23
|
+
} else {
|
|
24
|
+
// compute is a promise
|
|
25
|
+
this._compute = () => promiseOrCompute;
|
|
26
|
+
}
|
|
27
|
+
this.status = "dirty";
|
|
28
|
+
this._scheduler = new AsyncScheduler(
|
|
29
|
+
() => this._compute(),
|
|
30
|
+
(value) => this._onResolve(value as NotPromise<T>),
|
|
31
|
+
(error) => this._onReject(error),
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private _onResolve(value: NotPromise<T>) {
|
|
36
|
+
this.status = "resolved";
|
|
37
|
+
this._value = value;
|
|
38
|
+
this._error = undefined;
|
|
39
|
+
this.notifyDependents();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private _onReject(error: unknown) {
|
|
43
|
+
this.status = "error";
|
|
44
|
+
this._error = error;
|
|
45
|
+
this.notifyDependents();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
set(promise: Promise<T>): void;
|
|
49
|
+
set(updater: UpdateFunctionAsync<T>): void;
|
|
50
|
+
set(promiseOrUpdater: Promise<T> | UpdateFunctionAsync<T>): void {
|
|
51
|
+
if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
52
|
+
|
|
53
|
+
if (typeof promiseOrUpdater === "function") {
|
|
54
|
+
const updater = promiseOrUpdater as UpdateFunctionAsync<T>;
|
|
55
|
+
switch (this.status) {
|
|
56
|
+
case "resolved": {
|
|
57
|
+
this.status = "pending";
|
|
58
|
+
this._scheduler.overwrite(updater(this._value));
|
|
59
|
+
this.notifyDependents();
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
case "pending":
|
|
63
|
+
case "error":
|
|
64
|
+
case "dirty": {
|
|
65
|
+
// TODO: For now we use latest value to compute the next value
|
|
66
|
+
// Maybe we should throw instead ?
|
|
67
|
+
this.status = "pending";
|
|
68
|
+
this._scheduler.overwrite(updater(this._value));
|
|
69
|
+
this.notifyDependents();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
this.status = "pending";
|
|
75
|
+
const promise = promiseOrUpdater;
|
|
76
|
+
this._scheduler.overwrite(promise);
|
|
77
|
+
this.notifyDependents();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
refresh(): void {
|
|
82
|
+
if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
83
|
+
this.execute();
|
|
84
|
+
}
|
|
85
|
+
}
|