@ersbeth/picoflow 0.2.4 → 1.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/.cursor/plans/update-js-e795d61b.plan.md +567 -0
- package/.gitlab-ci.yml +24 -0
- package/.vscode/settings.json +3 -3
- package/CHANGELOG.md +51 -0
- package/IMPLEMENTATION_GUIDE.md +1578 -0
- package/README.md +62 -25
- package/biome.json +32 -32
- package/dist/picoflow.js +610 -436
- package/dist/types/advanced/array.d.ts +0 -6
- package/dist/types/advanced/array.d.ts.map +1 -1
- package/dist/types/advanced/index.d.ts +5 -5
- package/dist/types/advanced/index.d.ts.map +1 -1
- package/dist/types/advanced/map.d.ts +114 -23
- package/dist/types/advanced/map.d.ts.map +1 -1
- package/dist/types/advanced/resource.d.ts +51 -12
- package/dist/types/advanced/resource.d.ts.map +1 -1
- package/dist/types/advanced/resourceAsync.d.ts +28 -13
- package/dist/types/advanced/resourceAsync.d.ts.map +1 -1
- package/dist/types/advanced/stream.d.ts +74 -16
- package/dist/types/advanced/stream.d.ts.map +1 -1
- package/dist/types/advanced/streamAsync.d.ts +69 -15
- package/dist/types/advanced/streamAsync.d.ts.map +1 -1
- package/dist/types/basic/constant.d.ts +44 -16
- package/dist/types/basic/constant.d.ts.map +1 -1
- package/dist/types/basic/derivation.d.ts +73 -24
- package/dist/types/basic/derivation.d.ts.map +1 -1
- package/dist/types/basic/disposable.d.ts +65 -6
- package/dist/types/basic/disposable.d.ts.map +1 -1
- package/dist/types/basic/effect.d.ts +27 -16
- package/dist/types/basic/effect.d.ts.map +1 -1
- package/dist/types/basic/index.d.ts +7 -8
- package/dist/types/basic/index.d.ts.map +1 -1
- package/dist/types/basic/observable.d.ts +62 -13
- package/dist/types/basic/observable.d.ts.map +1 -1
- package/dist/types/basic/signal.d.ts +35 -6
- package/dist/types/basic/signal.d.ts.map +1 -1
- package/dist/types/basic/state.d.ts +25 -4
- package/dist/types/basic/state.d.ts.map +1 -1
- package/dist/types/basic/trackingContext.d.ts +33 -0
- package/dist/types/basic/trackingContext.d.ts.map +1 -0
- package/dist/types/creators.d.ts +271 -26
- package/dist/types/creators.d.ts.map +1 -1
- package/dist/types/index.d.ts +60 -7
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/solid/converters.d.ts +5 -5
- package/dist/types/solid/converters.d.ts.map +1 -1
- package/dist/types/solid/index.d.ts +2 -2
- package/dist/types/solid/index.d.ts.map +1 -1
- package/dist/types/solid/primitives.d.ts +96 -4
- package/dist/types/solid/primitives.d.ts.map +1 -1
- package/docs/.vitepress/config.mts +110 -0
- package/docs/api/classes/FlowArray.md +489 -0
- package/docs/api/classes/FlowConstant.md +350 -0
- package/docs/api/classes/FlowDerivation.md +334 -0
- package/docs/api/classes/FlowEffect.md +100 -0
- package/docs/api/classes/FlowMap.md +512 -0
- package/docs/api/classes/FlowObservable.md +306 -0
- package/docs/api/classes/FlowResource.md +380 -0
- package/docs/api/classes/FlowResourceAsync.md +362 -0
- package/docs/api/classes/FlowSignal.md +160 -0
- package/docs/api/classes/FlowState.md +368 -0
- package/docs/api/classes/FlowStream.md +367 -0
- package/docs/api/classes/FlowStreamAsync.md +364 -0
- package/docs/api/classes/SolidDerivation.md +75 -0
- package/docs/api/classes/SolidResource.md +91 -0
- package/docs/api/classes/SolidState.md +71 -0
- package/docs/api/classes/TrackingContext.md +33 -0
- package/docs/api/functions/array.md +58 -0
- package/docs/api/functions/constant.md +45 -0
- package/docs/api/functions/derivation.md +53 -0
- package/docs/api/functions/effect.md +49 -0
- package/docs/api/functions/from.md +220 -0
- package/docs/api/functions/isDisposable.md +49 -0
- package/docs/api/functions/map.md +57 -0
- package/docs/api/functions/resource.md +52 -0
- package/docs/api/functions/resourceAsync.md +50 -0
- package/docs/api/functions/signal.md +36 -0
- package/docs/api/functions/state.md +47 -0
- package/docs/api/functions/stream.md +53 -0
- package/docs/api/functions/streamAsync.md +50 -0
- package/docs/api/index.md +118 -0
- package/docs/api/interfaces/FlowDisposable.md +65 -0
- package/docs/api/interfaces/SolidObservable.md +19 -0
- package/docs/api/type-aliases/FlowArrayAction.md +49 -0
- package/docs/api/type-aliases/FlowStreamDisposer.md +15 -0
- package/docs/api/type-aliases/FlowStreamSetter.md +27 -0
- package/docs/api/type-aliases/FlowStreamUpdater.md +32 -0
- package/docs/api/type-aliases/NotPromise.md +18 -0
- package/docs/api/type-aliases/SolidGetter.md +17 -0
- package/docs/api/typedoc-sidebar.json +1 -0
- package/docs/examples/examples.md +2313 -0
- package/docs/examples/patterns.md +649 -0
- package/docs/guide/advanced/disposal.md +426 -0
- package/docs/guide/advanced/solidjs.md +221 -0
- package/docs/guide/advanced/upgrading.md +464 -0
- package/docs/guide/introduction/concepts.md +56 -0
- package/docs/guide/introduction/conventions.md +61 -0
- package/docs/guide/introduction/getting-started.md +134 -0
- package/docs/guide/introduction/lifecycle.md +371 -0
- package/docs/guide/primitives/array.md +400 -0
- package/docs/guide/primitives/constant.md +380 -0
- package/docs/guide/primitives/derivations.md +348 -0
- package/docs/guide/primitives/effects.md +458 -0
- package/docs/guide/primitives/map.md +387 -0
- package/docs/guide/primitives/overview.md +175 -0
- package/docs/guide/primitives/resources.md +858 -0
- package/docs/guide/primitives/signal.md +259 -0
- package/docs/guide/primitives/state.md +368 -0
- package/docs/guide/primitives/streams.md +931 -0
- package/docs/index.md +47 -0
- package/docs/public/logo.svg +1 -0
- package/package.json +57 -41
- package/src/advanced/array.ts +208 -210
- package/src/advanced/index.ts +7 -7
- package/src/advanced/map.ts +178 -68
- package/src/advanced/resource.ts +87 -43
- package/src/advanced/resourceAsync.ts +62 -42
- package/src/advanced/stream.ts +113 -50
- package/src/advanced/streamAsync.ts +120 -61
- package/src/basic/constant.ts +82 -49
- package/src/basic/derivation.ts +128 -84
- package/src/basic/disposable.ts +74 -15
- package/src/basic/effect.ts +85 -77
- package/src/basic/index.ts +7 -8
- package/src/basic/observable.ts +94 -36
- package/src/basic/signal.ts +133 -105
- package/src/basic/state.ts +46 -25
- package/src/basic/trackingContext.ts +45 -0
- package/src/creators.ts +297 -54
- package/src/index.ts +96 -43
- package/src/solid/converters.ts +186 -67
- package/src/solid/index.ts +8 -2
- package/src/solid/primitives.ts +167 -65
- package/test/array.test.ts +592 -612
- package/test/constant.test.ts +31 -33
- package/test/derivation.test.ts +531 -536
- package/test/effect.test.ts +21 -21
- package/test/map.test.ts +233 -137
- package/test/resource.test.ts +119 -121
- package/test/resourceAsync.test.ts +98 -100
- package/test/signal.test.ts +51 -55
- package/test/state.test.ts +186 -168
- package/test/stream.test.ts +189 -189
- package/test/streamAsync.test.ts +186 -186
- package/tsconfig.json +19 -18
- package/typedoc.json +37 -0
- package/vite.config.ts +23 -23
- package/vitest.config.ts +7 -7
- package/api/doc/index.md +0 -31
- package/api/doc/picoflow.array.md +0 -55
- package/api/doc/picoflow.constant.md +0 -55
- package/api/doc/picoflow.derivation.md +0 -55
- package/api/doc/picoflow.effect.md +0 -55
- package/api/doc/picoflow.flowarray._constructor_.md +0 -49
- package/api/doc/picoflow.flowarray._lastaction.md +0 -13
- package/api/doc/picoflow.flowarray.clear.md +0 -17
- package/api/doc/picoflow.flowarray.dispose.md +0 -55
- package/api/doc/picoflow.flowarray.get.md +0 -19
- package/api/doc/picoflow.flowarray.length.md +0 -13
- package/api/doc/picoflow.flowarray.md +0 -273
- package/api/doc/picoflow.flowarray.pop.md +0 -17
- package/api/doc/picoflow.flowarray.push.md +0 -53
- package/api/doc/picoflow.flowarray.set.md +0 -53
- package/api/doc/picoflow.flowarray.setitem.md +0 -69
- package/api/doc/picoflow.flowarray.shift.md +0 -17
- package/api/doc/picoflow.flowarray.splice.md +0 -85
- package/api/doc/picoflow.flowarray.unshift.md +0 -53
- package/api/doc/picoflow.flowarrayaction.md +0 -37
- package/api/doc/picoflow.flowconstant._constructor_.md +0 -49
- package/api/doc/picoflow.flowconstant.get.md +0 -25
- package/api/doc/picoflow.flowconstant.md +0 -88
- package/api/doc/picoflow.flowderivation._constructor_.md +0 -49
- package/api/doc/picoflow.flowderivation.get.md +0 -23
- package/api/doc/picoflow.flowderivation.md +0 -86
- package/api/doc/picoflow.flowdisposable.dispose.md +0 -55
- package/api/doc/picoflow.flowdisposable.md +0 -43
- package/api/doc/picoflow.floweffect._constructor_.md +0 -54
- package/api/doc/picoflow.floweffect.dispose.md +0 -21
- package/api/doc/picoflow.floweffect.disposed.md +0 -13
- package/api/doc/picoflow.floweffect.md +0 -131
- package/api/doc/picoflow.flowgetter.md +0 -15
- package/api/doc/picoflow.flowmap._lastdeleted.md +0 -21
- package/api/doc/picoflow.flowmap._lastset.md +0 -21
- package/api/doc/picoflow.flowmap.delete.md +0 -61
- package/api/doc/picoflow.flowmap.md +0 -133
- package/api/doc/picoflow.flowmap.setat.md +0 -77
- package/api/doc/picoflow.flowobservable.get.md +0 -19
- package/api/doc/picoflow.flowobservable.md +0 -68
- package/api/doc/picoflow.flowobservable.subscribe.md +0 -55
- package/api/doc/picoflow.flowresource._constructor_.md +0 -49
- package/api/doc/picoflow.flowresource.fetch.md +0 -27
- package/api/doc/picoflow.flowresource.get.md +0 -23
- package/api/doc/picoflow.flowresource.md +0 -100
- package/api/doc/picoflow.flowresourceasync._constructor_.md +0 -49
- package/api/doc/picoflow.flowresourceasync.fetch.md +0 -27
- package/api/doc/picoflow.flowresourceasync.get.md +0 -23
- package/api/doc/picoflow.flowresourceasync.md +0 -100
- package/api/doc/picoflow.flowsignal.dispose.md +0 -59
- package/api/doc/picoflow.flowsignal.disposed.md +0 -18
- package/api/doc/picoflow.flowsignal.md +0 -112
- package/api/doc/picoflow.flowsignal.trigger.md +0 -21
- package/api/doc/picoflow.flowstate.md +0 -52
- package/api/doc/picoflow.flowstate.set.md +0 -61
- package/api/doc/picoflow.flowstream._constructor_.md +0 -49
- package/api/doc/picoflow.flowstream.dispose.md +0 -21
- package/api/doc/picoflow.flowstream.get.md +0 -23
- package/api/doc/picoflow.flowstream.md +0 -100
- package/api/doc/picoflow.flowstreamasync._constructor_.md +0 -54
- package/api/doc/picoflow.flowstreamasync.dispose.md +0 -21
- package/api/doc/picoflow.flowstreamasync.get.md +0 -23
- package/api/doc/picoflow.flowstreamasync.md +0 -100
- package/api/doc/picoflow.flowstreamdisposer.md +0 -13
- package/api/doc/picoflow.flowstreamsetter.md +0 -13
- package/api/doc/picoflow.flowstreamupdater.md +0 -19
- package/api/doc/picoflow.flowwatcher.md +0 -15
- package/api/doc/picoflow.from.md +0 -55
- package/api/doc/picoflow.from_1.md +0 -55
- package/api/doc/picoflow.from_2.md +0 -55
- package/api/doc/picoflow.from_3.md +0 -55
- package/api/doc/picoflow.from_4.md +0 -55
- package/api/doc/picoflow.from_5.md +0 -55
- package/api/doc/picoflow.isdisposable.md +0 -55
- package/api/doc/picoflow.map.md +0 -59
- package/api/doc/picoflow.md +0 -544
- package/api/doc/picoflow.resource.md +0 -55
- package/api/doc/picoflow.resourceasync.md +0 -55
- package/api/doc/picoflow.signal.md +0 -19
- package/api/doc/picoflow.solidderivation._constructor_.md +0 -49
- package/api/doc/picoflow.solidderivation.get.md +0 -13
- package/api/doc/picoflow.solidderivation.md +0 -94
- package/api/doc/picoflow.solidgetter.md +0 -13
- package/api/doc/picoflow.solidobservable.get.md +0 -13
- package/api/doc/picoflow.solidobservable.md +0 -57
- package/api/doc/picoflow.solidresource._constructor_.md +0 -49
- package/api/doc/picoflow.solidresource.get.md +0 -13
- package/api/doc/picoflow.solidresource.latest.md +0 -13
- package/api/doc/picoflow.solidresource.md +0 -157
- package/api/doc/picoflow.solidresource.refetch.md +0 -13
- package/api/doc/picoflow.solidresource.state.md +0 -13
- package/api/doc/picoflow.solidstate._constructor_.md +0 -49
- package/api/doc/picoflow.solidstate.get.md +0 -13
- package/api/doc/picoflow.solidstate.md +0 -115
- package/api/doc/picoflow.solidstate.set.md +0 -13
- package/api/doc/picoflow.state.md +0 -55
- package/api/doc/picoflow.stream.md +0 -55
- package/api/doc/picoflow.streamasync.md +0 -55
- package/api/picoflow.public.api.md +0 -244
- package/api-extractor.json +0 -61
|
@@ -50,12 +50,6 @@ export declare class FlowArray<T> extends FlowObservable<T[]> {
|
|
|
50
50
|
* @public
|
|
51
51
|
*/
|
|
52
52
|
get length(): number;
|
|
53
|
-
/**
|
|
54
|
-
* Returns a copy of the internal array.
|
|
55
|
-
* @returns A copy of the array.
|
|
56
|
-
* @public
|
|
57
|
-
*/
|
|
58
|
-
get(): T[];
|
|
59
53
|
/**
|
|
60
54
|
* Replaces the entire array with new items.
|
|
61
55
|
* @param items - The new array of items.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../../src/advanced/array.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../../src/advanced/array.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,SAAS,EAAgB,MAAM,UAAU,CAAC;AAGxE;;;GAGG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IAC1B;IACA,IAAI,EAAE,KAAK,CAAC;IACZ,KAAK,EAAE,CAAC,EAAE,CAAC;CACV,GACD;IACA,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,CAAC,CAAC;CACP,GACD;IACA,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,CAAC,CAAC;CACP,GACD;IACA,IAAI,EAAE,KAAK,CAAC;CACX,GACD;IACA,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,CAAC,CAAC;CACP,GACD;IACA,IAAI,EAAE,OAAO,CAAC;CACb,GACD;IACA,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,CAAC,EAAE,CAAC;CACV,GACD;IACA,IAAI,EAAE,OAAO,CAAC;CACb,CAAC;AAEL;;;GAGG;AACH,qBAAa,SAAS,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,EAAE,CAAC;IACpD;;;OAGG;IACH,WAAW,EAAE,SAAS,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;IAE3C;;;;OAIG;gBACS,KAAK,GAAE,CAAC,EAAO;IAS3B;;;;OAIG;IACH,IAAI,MAAM,IAAI,MAAM,CAGnB;IAWD;;;;OAIG;IACH,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI;IAUrB;;;;;OAKG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI;IAUrC;;;;OAIG;IACH,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI;IAOnB;;;OAGG;IACH,GAAG,IAAI,IAAI;IAUX;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI;IAOtB;;;OAGG;IACH,KAAK,IAAI,IAAI;IAUb;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,CAAC,EAAE,GAAG,IAAI;IAelE;;;OAGG;IACH,KAAK,IAAI,IAAI;IAWb;;;;OAIG;IACM,OAAO,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;CAWnD"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
export type { FlowArrayAction } from './array';
|
|
2
|
+
export { FlowArray } from './array';
|
|
1
3
|
export { FlowMap } from './map';
|
|
2
|
-
export { FlowStream } from './stream';
|
|
3
|
-
export { FlowStreamAsync } from './streamAsync';
|
|
4
4
|
export { FlowResource } from './resource';
|
|
5
5
|
export { FlowResourceAsync } from './resourceAsync';
|
|
6
|
-
export type {
|
|
7
|
-
export {
|
|
8
|
-
export
|
|
6
|
+
export type { FlowStreamDisposer, FlowStreamSetter, FlowStreamUpdater, } from './stream';
|
|
7
|
+
export { FlowStream } from './stream';
|
|
8
|
+
export { FlowStreamAsync } from './streamAsync';
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/advanced/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/advanced/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,YAAY,EACX,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,GACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -1,36 +1,103 @@
|
|
|
1
1
|
import { FlowState } from '../basic/';
|
|
2
2
|
/**
|
|
3
|
-
* Represents a reactive map
|
|
3
|
+
* Represents a reactive map that extends {@link FlowState} for tracking key-value pairs.
|
|
4
4
|
*
|
|
5
5
|
* @remarks
|
|
6
|
-
* FlowMap wraps a native Map and provides reactive
|
|
7
|
-
*
|
|
8
|
-
* it exposes two reactive signals:
|
|
6
|
+
* FlowMap wraps a native JavaScript Map and provides reactive tracking at multiple granularity levels.
|
|
7
|
+
* Unlike plain reactive state, FlowMap offers fine-grained reactivity that lets you track:
|
|
9
8
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* 1. **Whole map changes**: Via `get(t)` or `pick()` on the FlowMap itself
|
|
10
|
+
* 2. **Last add operation**: Via the `$lastAdded` signal, track which key-value pair was most recently added
|
|
11
|
+
* 3. **Last update operation**: Via the `$lastUpdated` signal, track which key-value pair was most recently updated
|
|
12
|
+
* 4. **Last delete operation**: Via the `$lastDeleted` signal, track which key-value pair was most recently removed
|
|
12
13
|
*
|
|
13
|
-
*
|
|
14
|
+
* **Reactive Signals:**
|
|
15
|
+
* - **$lastAdded**: A FlowState containing `{ key?: K, value?: V }` updated on each `add()` call
|
|
16
|
+
* - **$lastUpdated**: A FlowState containing `{ key?: K, value?: V }` updated on each `update()` call
|
|
17
|
+
* - **$lastDeleted**: A FlowState containing `{ key?: K, value?: V }` updated on each `delete()` call
|
|
14
18
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
19
|
+
* These signals enable fine-grained reactivity patterns where effects can respond to specific
|
|
20
|
+
* map operations without re-processing the entire map.
|
|
21
|
+
*
|
|
22
|
+
* **Use Cases:**
|
|
23
|
+
* - Entity stores where you want to track additions/removals separately
|
|
24
|
+
* - Cache implementations with granular invalidation
|
|
25
|
+
* - Collections where operations on individual keys matter
|
|
26
|
+
* - UI state where you want to animate specific additions or removals
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const $users = map<string, User>();
|
|
31
|
+
*
|
|
32
|
+
* // Track the whole map
|
|
33
|
+
* effect((t) => {
|
|
34
|
+
* const users = $users.get(t);
|
|
35
|
+
* console.log(`Total users: ${users.size}`);
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* // Track only additions
|
|
39
|
+
* effect((t) => {
|
|
40
|
+
* const { key, value } = $users.$lastAdded.get(t);
|
|
41
|
+
* if (key && value) {
|
|
42
|
+
* console.log(`User ${key} was added:`, value);
|
|
43
|
+
* }
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* // Track only updates
|
|
47
|
+
* effect((t) => {
|
|
48
|
+
* const { key, value } = $users.$lastUpdated.get(t);
|
|
49
|
+
* if (key && value) {
|
|
50
|
+
* console.log(`User ${key} was updated:`, value);
|
|
51
|
+
* }
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* // Track only deletions
|
|
55
|
+
* effect((t) => {
|
|
56
|
+
* const { key, value } = $users.$lastDeleted.get(t);
|
|
57
|
+
* if (key && value) {
|
|
58
|
+
* console.log(`User ${key} was deleted:`, value);
|
|
59
|
+
* }
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* // Modify the map
|
|
63
|
+
* $users.add('user1', { name: 'John', age: 30 });
|
|
64
|
+
* $users.add('user2', { name: 'Jane', age: 25 });
|
|
65
|
+
* $users.update('user1', { name: 'John', age: 31 });
|
|
66
|
+
* $users.delete('user1');
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @typeParam K - The type of the map keys.
|
|
70
|
+
* @typeParam V - The type of the map values.
|
|
17
71
|
*
|
|
18
72
|
* @public
|
|
19
73
|
*/
|
|
20
74
|
export declare class FlowMap<K, V> extends FlowState<Map<K, V>> {
|
|
21
75
|
/**
|
|
22
|
-
* A reactive state that holds the most recent key and value that were
|
|
76
|
+
* A reactive state that holds the most recent key and value that were added.
|
|
23
77
|
*
|
|
24
78
|
* @remarks
|
|
25
|
-
* When a key is
|
|
79
|
+
* When a key is added via {@link FlowMap.add}, this state is updated with
|
|
26
80
|
* the corresponding key and value.
|
|
27
81
|
*
|
|
28
82
|
* @public
|
|
29
83
|
*/
|
|
30
|
-
$
|
|
31
|
-
key
|
|
32
|
-
value
|
|
33
|
-
}>;
|
|
84
|
+
$lastAdded: FlowState<{
|
|
85
|
+
key: K;
|
|
86
|
+
value: V;
|
|
87
|
+
} | null>;
|
|
88
|
+
/**
|
|
89
|
+
* A reactive state that holds the most recent key and value that were updated.
|
|
90
|
+
*
|
|
91
|
+
* @remarks
|
|
92
|
+
* When a key is updated via {@link FlowMap.update}, this state is updated with
|
|
93
|
+
* the corresponding key and value.
|
|
94
|
+
*
|
|
95
|
+
* @public
|
|
96
|
+
*/
|
|
97
|
+
$lastUpdated: FlowState<{
|
|
98
|
+
key: K;
|
|
99
|
+
value: V;
|
|
100
|
+
} | null>;
|
|
34
101
|
/**
|
|
35
102
|
* A reactive state that holds the most recent key and value that were deleted.
|
|
36
103
|
*
|
|
@@ -41,23 +108,39 @@ export declare class FlowMap<K, V> extends FlowState<Map<K, V>> {
|
|
|
41
108
|
* @public
|
|
42
109
|
*/
|
|
43
110
|
$lastDeleted: FlowState<{
|
|
44
|
-
key
|
|
45
|
-
value
|
|
46
|
-
}>;
|
|
111
|
+
key: K;
|
|
112
|
+
value: V;
|
|
113
|
+
} | null>;
|
|
47
114
|
/**
|
|
48
|
-
*
|
|
115
|
+
* Adds a new key-value pair to the map.
|
|
49
116
|
*
|
|
50
|
-
* @param key - The key
|
|
51
|
-
* @param value - The value to
|
|
117
|
+
* @param key - The key to add.
|
|
118
|
+
* @param value - The value to associate with the key.
|
|
52
119
|
* @throws If the FlowMap instance is disposed.
|
|
120
|
+
* @throws If the key already exists in the map.
|
|
53
121
|
*
|
|
54
122
|
* @remarks
|
|
55
|
-
*
|
|
123
|
+
* Adds a new entry to the internal map, emits the key-value pair via {@link FlowMap.$lastAdded},
|
|
56
124
|
* and notifies all subscribers of the change.
|
|
57
125
|
*
|
|
58
126
|
* @public
|
|
59
127
|
*/
|
|
60
|
-
|
|
128
|
+
add(key: K, value: V): void;
|
|
129
|
+
/**
|
|
130
|
+
* Updates an existing key-value pair in the map.
|
|
131
|
+
*
|
|
132
|
+
* @param key - The key to update.
|
|
133
|
+
* @param value - The new value to associate with the key.
|
|
134
|
+
* @throws If the FlowMap instance is disposed.
|
|
135
|
+
* @throws If the key does not exist in the map.
|
|
136
|
+
*
|
|
137
|
+
* @remarks
|
|
138
|
+
* Updates an existing entry in the internal map, emits the key-value pair via {@link FlowMap.$lastUpdated},
|
|
139
|
+
* and notifies all subscribers of the change.
|
|
140
|
+
*
|
|
141
|
+
* @public
|
|
142
|
+
*/
|
|
143
|
+
update(key: K, value: V): void;
|
|
61
144
|
/**
|
|
62
145
|
* Deletes the value at the specified key from the underlying map.
|
|
63
146
|
*
|
|
@@ -71,5 +154,13 @@ export declare class FlowMap<K, V> extends FlowState<Map<K, V>> {
|
|
|
71
154
|
* @public
|
|
72
155
|
*/
|
|
73
156
|
delete(key: K): void;
|
|
157
|
+
/**
|
|
158
|
+
* Disposes the FlowMap and its values.
|
|
159
|
+
* @param options - Disposal options.
|
|
160
|
+
* @public
|
|
161
|
+
*/
|
|
162
|
+
dispose(options?: {
|
|
163
|
+
self: boolean;
|
|
164
|
+
}): void;
|
|
74
165
|
}
|
|
75
166
|
//# sourceMappingURL=map.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../../src/advanced/map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../../src/advanced/map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAgB,MAAM,WAAW,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuEG;AACH,qBAAa,OAAO,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACtD;;;;;;;;OAQG;IACI,UAAU;aAAwB,CAAC;eAAS,CAAC;cAAiB;IAErE;;;;;;;;OAQG;IACI,YAAY;aAAwB,CAAC;eAAS,CAAC;cAAiB;IAEvE;;;;;;;;OAQG;IACI,YAAY;aAAwB,CAAC;eAAS,CAAC;cAAiB;IAEvE;;;;;;;;;;;;;OAaG;IACI,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAUlC;;;;;;;;;;;;;OAaG;IACI,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAUrC;;;;;;;;;;;OAWG;IACI,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI;IAS3B;;;;OAIG;IACM,OAAO,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;CAUnD"}
|
|
@@ -1,29 +1,68 @@
|
|
|
1
1
|
import { FlowObservable } from '../basic';
|
|
2
2
|
/**
|
|
3
|
-
* Represents a reactive resource that asynchronously fetches its value
|
|
3
|
+
* Represents a reactive resource that asynchronously fetches its value and returns `T | undefined`.
|
|
4
4
|
*
|
|
5
|
-
* @remarks
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* FlowResource extends FlowObservable to manage asynchronous data fetching with reactive updates.
|
|
7
|
+
* Unlike {@link FlowResourceAsync} which always returns a Promise, FlowResource returns the resolved
|
|
8
|
+
* value directly (or `undefined` if not yet fetched), making it more convenient for synchronous access
|
|
9
|
+
* patterns in effects and derivations.
|
|
10
|
+
*
|
|
11
|
+
* **Key Characteristics:**
|
|
12
|
+
* - The value is `undefined` initially, before the first fetch
|
|
13
|
+
* - Call `fetch()` to trigger the asynchronous fetch operation
|
|
14
|
+
* - When fetched, the value is compared to the current value; only different values trigger updates
|
|
15
|
+
* - Reading via `get(t)` or `pick()` returns the current value (possibly `undefined`) without triggering a fetch
|
|
16
|
+
*
|
|
17
|
+
* **Fetch Behavior:**
|
|
18
|
+
* The fetch function is NOT called automatically on construction. You must explicitly call the
|
|
19
|
+
* `fetch()` method to retrieve the resource. This gives you control over when network requests
|
|
20
|
+
* or expensive async operations occur.
|
|
21
|
+
*
|
|
22
|
+
* **Use Cases:**
|
|
23
|
+
* - API data fetching where you want synchronous access to the cached value
|
|
24
|
+
* - Lazy-loaded data that shouldn't fetch on construction
|
|
25
|
+
* - Resources that need manual refresh control
|
|
26
|
+
* - Data that may or may not be available (hence `T | undefined`)
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const $user = resource(() => fetchUserFromAPI());
|
|
31
|
+
*
|
|
32
|
+
* // Initially undefined
|
|
33
|
+
* console.log($user.pick()); // undefined
|
|
34
|
+
*
|
|
35
|
+
* // Trigger the fetch
|
|
36
|
+
* await $user.fetch();
|
|
37
|
+
* console.log($user.pick()); // { id: 1, name: 'John' }
|
|
38
|
+
*
|
|
39
|
+
* // Use in an effect
|
|
40
|
+
* effect((t) => {
|
|
41
|
+
* const user = $user.get(t);
|
|
42
|
+
* if (user) {
|
|
43
|
+
* console.log(`Hello, ${user.name}`);
|
|
44
|
+
* }
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* // Refetch to update
|
|
48
|
+
* await $user.fetch();
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @typeParam T - The type of the resource value (not including the undefined case).
|
|
9
52
|
*
|
|
10
53
|
* @public
|
|
11
54
|
*/
|
|
12
55
|
export declare class FlowResource<T> extends FlowObservable<T | undefined> {
|
|
13
56
|
/**
|
|
14
57
|
* Creates a new FlowResource.
|
|
58
|
+
*
|
|
15
59
|
* @param fetch - An asynchronous function that retrieves the resource's value.
|
|
60
|
+
* This function is not invoked on construction; you must call the `fetch()` method
|
|
61
|
+
* to execute it.
|
|
16
62
|
*
|
|
17
63
|
* @public
|
|
18
64
|
*/
|
|
19
65
|
constructor(fetch: () => Promise<T>);
|
|
20
|
-
/**
|
|
21
|
-
* Retrieves the current resource value.
|
|
22
|
-
* @returns The current value, or undefined if the resource has not been fetched yet.
|
|
23
|
-
* @throws Error if the resource is disposed.
|
|
24
|
-
* @public
|
|
25
|
-
*/
|
|
26
|
-
get(): T | undefined;
|
|
27
66
|
/**
|
|
28
67
|
* Asynchronously fetches a new value for the resource.
|
|
29
68
|
* @remarks
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../../src/advanced/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C
|
|
1
|
+
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../../src/advanced/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,qBAAa,YAAY,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,GAAG,SAAS,CAAC;IACjE;;;;;;;;OAQG;gBACS,KAAK,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC;IAcnC;;;;;;;;OAQG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAUnC,OAAO,CAAC,MAAM,CAAmB;CACjC"}
|
|
@@ -1,14 +1,36 @@
|
|
|
1
1
|
import { FlowObservable } from '../basic/';
|
|
2
2
|
/**
|
|
3
|
-
* Represents a reactive resource that asynchronously fetches its value.
|
|
3
|
+
* Represents a reactive resource that asynchronously fetches its value and always returns a Promise.
|
|
4
4
|
*
|
|
5
5
|
* @remarks
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* are notified.
|
|
6
|
+
* FlowResourceAsync extends FlowObservable and encapsulates an asynchronous fetch function.
|
|
7
|
+
* Unlike {@link FlowResource} which returns `T | undefined`, FlowResourceAsync always returns
|
|
8
|
+
* a `Promise<T>`, making it suitable for async/await patterns.
|
|
10
9
|
*
|
|
11
|
-
*
|
|
10
|
+
* **Key Characteristics:**
|
|
11
|
+
* - The first call to `get()` or `pick()` creates and caches a Promise
|
|
12
|
+
* - Subsequent calls return the same Promise until `fetch()` is called
|
|
13
|
+
* - Calling `fetch()` creates a new Promise and notifies subscribers
|
|
14
|
+
* - The Promise resolves to the fetched value of type T
|
|
15
|
+
*
|
|
16
|
+
* **Lazy Promise Creation:**
|
|
17
|
+
* The fetch function doesn't execute until the resource's value is first accessed.
|
|
18
|
+
* This allows you to define resources without immediately triggering network requests.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const $user = resourceAsync(() => fetchUserFromAPI());
|
|
23
|
+
*
|
|
24
|
+
* effect(async (t) => {
|
|
25
|
+
* const user = await $user.get(t); // Tracked, effect re-runs on fetch()
|
|
26
|
+
* console.log(user.name);
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Trigger a refetch
|
|
30
|
+
* await $user.fetch();
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @typeParam T - The type of the resource value (not the Promise itself).
|
|
12
34
|
*
|
|
13
35
|
* @public
|
|
14
36
|
*/
|
|
@@ -19,13 +41,6 @@ export declare class FlowResourceAsync<T> extends FlowObservable<Promise<T>> {
|
|
|
19
41
|
* @public
|
|
20
42
|
*/
|
|
21
43
|
constructor(fetch: () => Promise<T>);
|
|
22
|
-
/**
|
|
23
|
-
* Retrieves the current resource value.
|
|
24
|
-
* @returns The current value, or undefined if the resource has not been fetched yet.
|
|
25
|
-
* @throws Error if the resource is disposed.
|
|
26
|
-
* @public
|
|
27
|
-
*/
|
|
28
|
-
get(): Promise<T>;
|
|
29
44
|
/**
|
|
30
45
|
* Asynchronously fetches a new value for the resource.
|
|
31
46
|
* @remarks
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resourceAsync.d.ts","sourceRoot":"","sources":["../../../src/advanced/resourceAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C
|
|
1
|
+
{"version":3,"file":"resourceAsync.d.ts","sourceRoot":"","sources":["../../../src/advanced/resourceAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,qBAAa,iBAAiB,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACnE;;;;OAIG;gBACS,KAAK,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC;IAenC;;;;;;;;OAQG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQnC,OAAO,CAAC,MAAM,CAAmB;CACjC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FlowObservable } from '../basic/';
|
|
2
2
|
/**
|
|
3
3
|
* A function type that sets a new value for the reactive stream.
|
|
4
|
-
* @
|
|
4
|
+
* @typeParam T - The type of the value.
|
|
5
5
|
* @public
|
|
6
6
|
*/
|
|
7
7
|
export type FlowStreamSetter<T> = (value: T) => void;
|
|
@@ -15,36 +15,94 @@ export type FlowStreamDisposer = () => void;
|
|
|
15
15
|
* @remarks
|
|
16
16
|
* The updater receives a setter function to update the stream's value.
|
|
17
17
|
* It should return a disposer function to release any resources or subscriptions.
|
|
18
|
-
* @
|
|
18
|
+
* @typeParam T - The type of the stream value.
|
|
19
19
|
* @public
|
|
20
20
|
*/
|
|
21
21
|
export type FlowStreamUpdater<T> = (set: FlowStreamSetter<T>) => FlowStreamDisposer;
|
|
22
22
|
/**
|
|
23
|
-
* Represents a reactive stream that updates its value based on an updater function.
|
|
23
|
+
* Represents a reactive stream that updates its value based on an external updater function.
|
|
24
24
|
*
|
|
25
25
|
* @remarks
|
|
26
|
-
* FlowStream extends FlowObservable to
|
|
27
|
-
*
|
|
28
|
-
*
|
|
26
|
+
* FlowStream extends FlowObservable to bridge external event sources with PicoFlow's reactive
|
|
27
|
+
* system. It's designed for integrating with event emitters, WebSocket connections, timers,
|
|
28
|
+
* or any push-based data source that sends updates over time.
|
|
29
29
|
*
|
|
30
|
-
*
|
|
30
|
+
* **How It Works:**
|
|
31
|
+
* 1. You provide an updater function that receives a setter callback
|
|
32
|
+
* 2. The updater sets up subscriptions to external events and calls the setter with new values
|
|
33
|
+
* 3. When the setter is called, the stream notifies all dependent effects and derivations
|
|
34
|
+
* 4. The updater returns a disposer function for cleanup
|
|
35
|
+
*
|
|
36
|
+
* **Initial Value:**
|
|
37
|
+
* The stream's value is `undefined` until the first time the setter is called. This allows
|
|
38
|
+
* you to check if any data has been received yet.
|
|
39
|
+
*
|
|
40
|
+
* **Change Detection:**
|
|
41
|
+
* The stream only notifies subscribers when the new value differs from the current value
|
|
42
|
+
* (using strict equality `===`). This prevents unnecessary updates for duplicate values.
|
|
43
|
+
*
|
|
44
|
+
* **Resource Management:**
|
|
45
|
+
* The disposer function returned by your updater is automatically called when the stream
|
|
46
|
+
* is disposed. Use it to clean up subscriptions, close connections, or clear timers.
|
|
47
|
+
*
|
|
48
|
+
* **Use Cases:**
|
|
49
|
+
* - WebSocket message streams
|
|
50
|
+
* - DOM event listeners
|
|
51
|
+
* - setInterval/setTimeout timers
|
|
52
|
+
* - Server-sent events (SSE)
|
|
53
|
+
* - Observable subscriptions from other libraries
|
|
54
|
+
* - Any push-based data source
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* // WebSocket stream
|
|
59
|
+
* const $messages = stream<string>((set) => {
|
|
60
|
+
* const ws = new WebSocket('ws://example.com');
|
|
61
|
+
* ws.onmessage = (event) => set(event.data);
|
|
62
|
+
* return () => ws.close();
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* // Timer stream
|
|
66
|
+
* const $tick = stream<number>((set) => {
|
|
67
|
+
* let count = 0;
|
|
68
|
+
* const id = setInterval(() => set(count++), 1000);
|
|
69
|
+
* return () => clearInterval(id);
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* // DOM event stream
|
|
73
|
+
* const $clicks = stream<MouseEvent>((set) => {
|
|
74
|
+
* const handler = (e: MouseEvent) => set(e);
|
|
75
|
+
* document.addEventListener('click', handler);
|
|
76
|
+
* return () => document.removeEventListener('click', handler);
|
|
77
|
+
* });
|
|
78
|
+
*
|
|
79
|
+
* // Use in an effect
|
|
80
|
+
* effect((t) => {
|
|
81
|
+
* const message = $messages.get(t);
|
|
82
|
+
* if (message) {
|
|
83
|
+
* console.log('Received:', message);
|
|
84
|
+
* }
|
|
85
|
+
* });
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @typeParam T - The type of the values emitted by the stream.
|
|
31
89
|
* @public
|
|
32
90
|
*/
|
|
33
91
|
export declare class FlowStream<T> extends FlowObservable<T | undefined> {
|
|
34
92
|
/**
|
|
35
93
|
* Creates a new FlowStream.
|
|
36
|
-
*
|
|
37
|
-
*
|
|
94
|
+
*
|
|
95
|
+
* @param updater - A function that receives a setter callback and returns a disposer.
|
|
96
|
+
* The setter should be called whenever new data is available. The disposer will be
|
|
97
|
+
* invoked when the stream is disposed to clean up resources.
|
|
98
|
+
*
|
|
99
|
+
* @remarks
|
|
100
|
+
* The updater is invoked immediately during construction. Make sure to return a proper
|
|
101
|
+
* cleanup function to avoid resource leaks.
|
|
102
|
+
*
|
|
38
103
|
* @public
|
|
39
104
|
*/
|
|
40
105
|
constructor(updater: FlowStreamUpdater<T>);
|
|
41
|
-
/**
|
|
42
|
-
* Retrieves the current value of the stream.
|
|
43
|
-
* @returns The current value, or undefined if no value has been set yet.
|
|
44
|
-
* @throws Error if the stream is disposed.
|
|
45
|
-
* @public
|
|
46
|
-
*/
|
|
47
|
-
get(): T | undefined;
|
|
48
106
|
/**
|
|
49
107
|
* Disposes the stream, releasing all resources.
|
|
50
108
|
* @remarks
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../src/advanced/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AAErD;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC;AAE5C;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../src/advanced/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AAErD;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC;AAE5C;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,CAClC,GAAG,EAAE,gBAAgB,CAAC,CAAC,CAAC,KACpB,kBAAkB,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,qBAAa,UAAU,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,GAAG,SAAS,CAAC;IAC/D;;;;;;;;;;;;OAYG;gBACS,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAgBzC;;;;;;OAMG;IACa,OAAO,IAAI,IAAI;IAO/B,OAAO,CAAC,SAAS,CAAqB;IAEtC,OAAO,CAAC,IAAI;CAOZ"}
|
|
@@ -1,32 +1,86 @@
|
|
|
1
1
|
import { FlowObservable } from '../basic';
|
|
2
2
|
import { FlowStreamUpdater } from './stream';
|
|
3
3
|
/**
|
|
4
|
-
* Represents an asynchronous reactive stream that
|
|
4
|
+
* Represents an asynchronous reactive stream that always returns a Promise and updates based on an updater function.
|
|
5
5
|
*
|
|
6
6
|
* @remarks
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* FlowStreamAsync extends FlowObservable to bridge external async event sources with PicoFlow's
|
|
8
|
+
* reactive system. Unlike {@link FlowStream} which returns `T | undefined`, FlowStreamAsync always
|
|
9
|
+
* returns a `Promise<T>`, making it suitable for use with async/await patterns.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* **How It Works:**
|
|
12
|
+
* 1. On construction, creates an initial Promise that resolves when the first value arrives
|
|
13
|
+
* 2. Your updater function receives a setter callback and sets up event subscriptions
|
|
14
|
+
* 3. When the setter is called with a value, the Promise resolves (first call) or a new Promise is created (subsequent calls)
|
|
15
|
+
* 4. The updater returns a disposer function for cleanup
|
|
16
|
+
*
|
|
17
|
+
* **Promise Behavior:**
|
|
18
|
+
* - **First call to setter**: Resolves the initial Promise created at construction
|
|
19
|
+
* - **Subsequent calls**: Creates a new `Promise.resolve(value)` for immediate resolution
|
|
20
|
+
* - **Reading the value**: Always returns a Promise, either pending (initial) or resolved
|
|
21
|
+
*
|
|
22
|
+
* **Change Detection:**
|
|
23
|
+
* After the first value is set, the stream only notifies subscribers when the new value
|
|
24
|
+
* differs from the previous value (using strict equality `===`). This prevents unnecessary
|
|
25
|
+
* updates for duplicate values.
|
|
26
|
+
*
|
|
27
|
+
* **Resource Management:**
|
|
28
|
+
* The disposer function returned by your updater is automatically called when the stream
|
|
29
|
+
* is disposed. Use it to clean up subscriptions, close connections, or clear timers.
|
|
30
|
+
*
|
|
31
|
+
* **Use Cases:**
|
|
32
|
+
* - Async WebSocket message streams
|
|
33
|
+
* - Server-sent events that you want to await
|
|
34
|
+
* - Async event handlers
|
|
35
|
+
* - Integration with async iterators
|
|
36
|
+
* - Any push-based async data source
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* // Async WebSocket stream
|
|
41
|
+
* const $messages = streamAsync<string>((set) => {
|
|
42
|
+
* const ws = new WebSocket('ws://example.com');
|
|
43
|
+
* ws.onmessage = (event) => set(event.data);
|
|
44
|
+
* return () => ws.close();
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* // Use with async/await
|
|
48
|
+
* effect(async (t) => {
|
|
49
|
+
* const message = await $messages.get(t);
|
|
50
|
+
* console.log('Received:', message);
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* // Wait for the first message
|
|
54
|
+
* const firstMessage = await $messages.pick();
|
|
55
|
+
* console.log('First message:', firstMessage);
|
|
56
|
+
*
|
|
57
|
+
* // Async timer stream
|
|
58
|
+
* const $asyncTick = streamAsync<number>((set) => {
|
|
59
|
+
* let count = 0;
|
|
60
|
+
* const id = setInterval(() => set(count++), 1000);
|
|
61
|
+
* return () => clearInterval(id);
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @typeParam T - The type of the values emitted by the stream (not the Promise itself).
|
|
12
66
|
* @public
|
|
13
67
|
*/
|
|
14
68
|
export declare class FlowStreamAsync<T> extends FlowObservable<Promise<T>> {
|
|
15
69
|
/**
|
|
16
70
|
* Creates a new asynchronous FlowStream.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
71
|
+
*
|
|
72
|
+
* @param updater - A function that receives a setter callback and returns a disposer.
|
|
73
|
+
* The setter should be called whenever new data is available (can be called asynchronously).
|
|
74
|
+
* The disposer will be invoked when the stream is disposed to clean up resources.
|
|
75
|
+
*
|
|
76
|
+
* @remarks
|
|
77
|
+
* The updater is invoked immediately during construction. An initial Promise is created
|
|
78
|
+
* that will resolve when the setter is first called. Make sure to return a proper cleanup
|
|
79
|
+
* function to avoid resource leaks.
|
|
80
|
+
*
|
|
20
81
|
* @public
|
|
21
82
|
*/
|
|
22
83
|
constructor(updater: FlowStreamUpdater<T>);
|
|
23
|
-
/**
|
|
24
|
-
* Retrieves the current value of the stream as a Promise.
|
|
25
|
-
* @returns A Promise that resolves to the current value.
|
|
26
|
-
* @throws Error if the stream is disposed.
|
|
27
|
-
* @public
|
|
28
|
-
*/
|
|
29
|
-
get(): Promise<T>;
|
|
30
84
|
/**
|
|
31
85
|
* Disposes the stream, releasing all resources.
|
|
32
86
|
* @remarks In addition to disposing the underlying observable, this method calls the disposer
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streamAsync.d.ts","sourceRoot":"","sources":["../../../src/advanced/streamAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EAAsB,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAEtE
|
|
1
|
+
{"version":3,"file":"streamAsync.d.ts","sourceRoot":"","sources":["../../../src/advanced/streamAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EAAsB,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEG;AACH,qBAAa,eAAe,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACjE;;;;;;;;;;;;;OAaG;gBACS,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAoBzC;;;;;OAKG;IACa,OAAO,IAAI,IAAI;IAO/B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,aAAa,CAAC,CAAI;IAE1B,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,SAAS,CAAqB;IAEtC,OAAO,CAAC,IAAI;CAkBZ"}
|