@ersbeth/picoflow 0.2.4 → 1.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/.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 +9 -134
- 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
package/dist/types/creators.d.ts
CHANGED
|
@@ -1,94 +1,339 @@
|
|
|
1
1
|
import { FlowMap, FlowResource, FlowResourceAsync, FlowStream, FlowStreamAsync } from './advanced/';
|
|
2
2
|
import { FlowArray } from './advanced/array';
|
|
3
|
-
import { FlowConstant, FlowDerivation, FlowEffect, FlowSignal, FlowState
|
|
3
|
+
import { TrackingContext, FlowConstant, FlowDerivation, FlowEffect, FlowSignal, FlowState } from './basic/';
|
|
4
4
|
/**
|
|
5
5
|
* Creates a new reactive signal.
|
|
6
|
+
*
|
|
6
7
|
* @returns A new instance of {@link FlowSignal}.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* A signal is the simplest reactive primitive - it doesn't hold a value, but can be triggered
|
|
11
|
+
* to notify dependent effects and derivations. Use signals when you need event-like notifications
|
|
12
|
+
* without associated data.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const $refresh = signal();
|
|
17
|
+
*
|
|
18
|
+
* effect((t) => {
|
|
19
|
+
* $refresh.watch(t);
|
|
20
|
+
* console.log('Refreshing...');
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* $refresh.trigger(); // Logs: "Refreshing..."
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
7
26
|
* @public
|
|
8
27
|
*/
|
|
9
28
|
export declare function signal(): FlowSignal;
|
|
10
29
|
/**
|
|
11
30
|
* Creates a new reactive constant.
|
|
12
|
-
*
|
|
31
|
+
*
|
|
32
|
+
* @typeParam T - The type of the constant value.
|
|
33
|
+
* @param value - The value or a function that returns the value (for lazy initialization).
|
|
13
34
|
* @returns A new instance of {@link FlowConstant}.
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* A constant is an immutable reactive value that never changes after initialization.
|
|
38
|
+
* It can be initialized eagerly (direct value) or lazily (function). Use constants for
|
|
39
|
+
* configuration, computed-once values, or expensive initialization that should only run once.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* // Eager initialization
|
|
44
|
+
* const $config = constant({ apiUrl: 'https://api.example.com' });
|
|
45
|
+
*
|
|
46
|
+
* // Lazy initialization
|
|
47
|
+
* const $computed = constant(() => expensiveCalculation());
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
14
50
|
* @public
|
|
15
51
|
*/
|
|
16
52
|
export declare function constant<T>(value: T | (() => T)): FlowConstant<T>;
|
|
17
53
|
/**
|
|
18
|
-
* Creates a new reactive state holding a value.
|
|
19
|
-
*
|
|
20
|
-
* @
|
|
54
|
+
* Creates a new reactive state holding a mutable value.
|
|
55
|
+
*
|
|
56
|
+
* @typeParam T - The type of the state value.
|
|
57
|
+
* @param value - The initial value for the state, or a function returning the initial value.
|
|
21
58
|
* @returns A new instance of {@link FlowState}.
|
|
59
|
+
*
|
|
60
|
+
* @remarks
|
|
61
|
+
* State is the most common reactive primitive - a mutable container that notifies dependents
|
|
62
|
+
* when its value changes. Use `set()` to update the value and `get(t)` or `pick()` to read it.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const $count = state(0);
|
|
67
|
+
*
|
|
68
|
+
* effect((t) => {
|
|
69
|
+
* console.log($count.get(t));
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* $count.set(1); // Logs: 1
|
|
73
|
+
* $count.set(n => n + 1); // Logs: 2
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
22
76
|
* @public
|
|
23
77
|
*/
|
|
24
78
|
export declare function state<T>(value: T | (() => T)): FlowState<T>;
|
|
25
79
|
/**
|
|
26
|
-
* Creates a new reactive resource that asynchronously fetches its value
|
|
27
|
-
*
|
|
80
|
+
* Creates a new reactive resource that asynchronously fetches its value, returning `T | undefined`.
|
|
81
|
+
*
|
|
82
|
+
* @typeParam T - The type of the resource value.
|
|
28
83
|
* @param fn - An asynchronous function that fetches the resource value.
|
|
29
84
|
* @returns A new instance of {@link FlowResource}.
|
|
85
|
+
*
|
|
86
|
+
* @remarks
|
|
87
|
+
* A resource manages async data fetching with reactive updates. Unlike {@link resourceAsync},
|
|
88
|
+
* this returns the resolved value directly (or `undefined` if not fetched yet), making it
|
|
89
|
+
* easier to work with in synchronous contexts. Call `fetch()` to trigger the async operation.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const $user = resource(() => fetch('/api/user').then(r => r.json()));
|
|
94
|
+
*
|
|
95
|
+
* // Trigger fetch
|
|
96
|
+
* await $user.fetch();
|
|
97
|
+
*
|
|
98
|
+
* // Use in effect
|
|
99
|
+
* effect((t) => {
|
|
100
|
+
* const user = $user.get(t);
|
|
101
|
+
* if (user) {
|
|
102
|
+
* console.log(user.name);
|
|
103
|
+
* }
|
|
104
|
+
* });
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
30
107
|
* @public
|
|
31
108
|
*/
|
|
32
109
|
export declare function resource<T>(fn: () => Promise<T>): FlowResource<T>;
|
|
33
110
|
/**
|
|
34
|
-
* Creates a new reactive asynchronous resource that
|
|
35
|
-
*
|
|
111
|
+
* Creates a new reactive asynchronous resource that always returns a Promise.
|
|
112
|
+
*
|
|
113
|
+
* @typeParam T - The type of the resource value.
|
|
36
114
|
* @param fn - An asynchronous function that fetches the resource value.
|
|
37
115
|
* @returns A new instance of {@link FlowResourceAsync}.
|
|
116
|
+
*
|
|
117
|
+
* @remarks
|
|
118
|
+
* An async resource manages async data fetching and always returns a Promise, making it
|
|
119
|
+
* ideal for async/await patterns. Unlike {@link resource}, the Promise is created lazily
|
|
120
|
+
* on first access and cached. Call `fetch()` to create a new Promise and trigger a refetch.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const $data = resourceAsync(() => fetch('/api/data').then(r => r.json()));
|
|
125
|
+
*
|
|
126
|
+
* // Use with async/await
|
|
127
|
+
* effect(async (t) => {
|
|
128
|
+
* const data = await $data.get(t);
|
|
129
|
+
* console.log(data);
|
|
130
|
+
* });
|
|
131
|
+
*
|
|
132
|
+
* // Refetch
|
|
133
|
+
* await $data.fetch();
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
38
136
|
* @public
|
|
39
137
|
*/
|
|
40
138
|
export declare function resourceAsync<T>(fn: () => Promise<T>): FlowResourceAsync<T>;
|
|
41
139
|
/**
|
|
42
|
-
* Creates a new reactive stream.
|
|
43
|
-
*
|
|
140
|
+
* Creates a new reactive stream that bridges external event sources with PicoFlow's reactive system.
|
|
141
|
+
*
|
|
142
|
+
* @typeParam T - The type of the stream value.
|
|
44
143
|
* @param updater - A function that receives a setter to update the stream's value.
|
|
45
144
|
* It should return a disposer function to clean up resources.
|
|
46
145
|
* @returns A new instance of {@link FlowStream}.
|
|
146
|
+
*
|
|
147
|
+
* @remarks
|
|
148
|
+
* Streams are ideal for integrating push-based data sources like WebSockets, DOM events,
|
|
149
|
+
* timers, or any event emitter. The updater sets up subscriptions and calls the setter
|
|
150
|
+
* when new data arrives. The returned disposer is called on cleanup.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* // WebSocket stream
|
|
155
|
+
* const $messages = stream<string>((set) => {
|
|
156
|
+
* const ws = new WebSocket('ws://example.com');
|
|
157
|
+
* ws.onmessage = (e) => set(e.data);
|
|
158
|
+
* return () => ws.close();
|
|
159
|
+
* });
|
|
160
|
+
*
|
|
161
|
+
* // Timer stream
|
|
162
|
+
* const $tick = stream<number>((set) => {
|
|
163
|
+
* let count = 0;
|
|
164
|
+
* const id = setInterval(() => set(count++), 1000);
|
|
165
|
+
* return () => clearInterval(id);
|
|
166
|
+
* });
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
47
169
|
* @public
|
|
48
170
|
*/
|
|
49
171
|
export declare function stream<T>(updater: (set: (value: T) => void) => () => void): FlowStream<T>;
|
|
50
172
|
/**
|
|
51
|
-
* Creates a new reactive asynchronous stream.
|
|
52
|
-
*
|
|
173
|
+
* Creates a new reactive asynchronous stream that always returns a Promise.
|
|
174
|
+
*
|
|
175
|
+
* @typeParam T - The type of the stream value.
|
|
53
176
|
* @param updater - A function that receives a setter to update the stream's value.
|
|
54
177
|
* It should return a disposer function to clean up resources.
|
|
55
178
|
* @returns A new instance of {@link FlowStreamAsync}.
|
|
179
|
+
*
|
|
180
|
+
* @remarks
|
|
181
|
+
* Async streams are ideal for push-based async data sources where you want to use async/await.
|
|
182
|
+
* Unlike {@link stream}, this always returns a Promise that resolves to the value. The initial
|
|
183
|
+
* Promise is created on construction and resolves when the setter is first called.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* const $asyncMessages = streamAsync<string>((set) => {
|
|
188
|
+
* const ws = new WebSocket('ws://example.com');
|
|
189
|
+
* ws.onmessage = (e) => set(e.data);
|
|
190
|
+
* return () => ws.close();
|
|
191
|
+
* });
|
|
192
|
+
*
|
|
193
|
+
* effect(async (t) => {
|
|
194
|
+
* const message = await $asyncMessages.get(t);
|
|
195
|
+
* console.log('Received:', message);
|
|
196
|
+
* });
|
|
197
|
+
* ```
|
|
198
|
+
*
|
|
56
199
|
* @public
|
|
57
200
|
*/
|
|
58
201
|
export declare function streamAsync<T>(updater: (set: (value: T) => void) => () => void): FlowStreamAsync<T>;
|
|
59
202
|
/**
|
|
60
203
|
* Creates a new reactive derivation whose value is computed based on other reactive signals.
|
|
61
|
-
*
|
|
62
|
-
* @
|
|
63
|
-
* function
|
|
204
|
+
*
|
|
205
|
+
* @typeParam T - The type of the derived value.
|
|
206
|
+
* @param fn - A function that computes the derived value using a tracking context.
|
|
64
207
|
* @returns A new instance of {@link FlowDerivation}.
|
|
208
|
+
*
|
|
209
|
+
* @remarks
|
|
210
|
+
* A derivation is a computed reactive value that automatically tracks its dependencies and
|
|
211
|
+
* recomputes when they change. The computation is lazy - it runs only when the value is
|
|
212
|
+
* accessed, not on construction. Use derivations to create derived state without manual
|
|
213
|
+
* dependency management.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```typescript
|
|
217
|
+
* const $firstName = state('John');
|
|
218
|
+
* const $lastName = state('Doe');
|
|
219
|
+
*
|
|
220
|
+
* const $fullName = derivation((t) => {
|
|
221
|
+
* return `${$firstName.get(t)} ${$lastName.get(t)}`;
|
|
222
|
+
* });
|
|
223
|
+
*
|
|
224
|
+
* effect((t) => {
|
|
225
|
+
* console.log($fullName.get(t)); // Logs: "John Doe"
|
|
226
|
+
* });
|
|
227
|
+
*
|
|
228
|
+
* $firstName.set('Jane'); // Logs: "Jane Doe"
|
|
229
|
+
* ```
|
|
230
|
+
*
|
|
65
231
|
* @public
|
|
66
232
|
*/
|
|
67
|
-
export declare function derivation<T>(fn: (
|
|
233
|
+
export declare function derivation<T>(fn: (t: TrackingContext) => T): FlowDerivation<T>;
|
|
68
234
|
/**
|
|
69
235
|
* Creates a new reactive effect that executes a side-effect function based on its dependencies.
|
|
70
|
-
*
|
|
71
|
-
* function
|
|
236
|
+
*
|
|
237
|
+
* @param fn - A function that performs side effects using a tracking context.
|
|
72
238
|
* @returns A new instance of {@link FlowEffect}.
|
|
239
|
+
*
|
|
240
|
+
* @remarks
|
|
241
|
+
* An effect is a reactive computation that runs immediately and re-runs whenever its tracked
|
|
242
|
+
* dependencies change. Use effects for side effects like logging, DOM updates, network requests,
|
|
243
|
+
* or any operation that should respond to reactive state changes.
|
|
244
|
+
*
|
|
245
|
+
* The effect executes immediately upon creation and provides a tracking context (`t`) that you
|
|
246
|
+
* use to explicitly mark dependencies via `observable.get(t)`. Use `observable.pick()` for
|
|
247
|
+
* reads that shouldn't trigger re-runs.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```typescript
|
|
251
|
+
* const $count = state(0);
|
|
252
|
+
*
|
|
253
|
+
* const fx = effect((t) => {
|
|
254
|
+
* console.log('Count is:', $count.get(t));
|
|
255
|
+
* });
|
|
256
|
+
*
|
|
257
|
+
* $count.set(1); // Logs: "Count is: 1"
|
|
258
|
+
* $count.set(2); // Logs: "Count is: 2"
|
|
259
|
+
*
|
|
260
|
+
* // Clean up when done
|
|
261
|
+
* fx.dispose();
|
|
262
|
+
* ```
|
|
263
|
+
*
|
|
73
264
|
* @public
|
|
74
265
|
*/
|
|
75
|
-
export declare function effect(fn: (
|
|
266
|
+
export declare function effect(fn: (t: TrackingContext) => void): FlowEffect;
|
|
76
267
|
/**
|
|
77
|
-
* Creates a new reactive map state.
|
|
78
|
-
*
|
|
79
|
-
* @
|
|
268
|
+
* Creates a new reactive map state with fine-grained tracking of operations.
|
|
269
|
+
*
|
|
270
|
+
* @typeParam K - The type of the keys.
|
|
271
|
+
* @typeParam V - The type of the values.
|
|
80
272
|
* @param initial - An optional record of key-value pairs to initialize the map.
|
|
81
273
|
* @returns A new instance of {@link FlowMap}.
|
|
274
|
+
*
|
|
82
275
|
* @remarks
|
|
83
|
-
*
|
|
276
|
+
* A reactive map wraps a native JavaScript Map and provides multiple levels of reactivity:
|
|
277
|
+
* tracking the entire map, tracking individual set operations, and tracking individual
|
|
278
|
+
* delete operations. The initial record (if provided) is converted to a native Map.
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```typescript
|
|
282
|
+
* const $users = map<string, User>({
|
|
283
|
+
* 'user1': { name: 'John', age: 30 }
|
|
284
|
+
* });
|
|
285
|
+
*
|
|
286
|
+
* // Track the whole map
|
|
287
|
+
* effect((t) => {
|
|
288
|
+
* console.log('Users:', $users.get(t).size);
|
|
289
|
+
* });
|
|
290
|
+
*
|
|
291
|
+
* // Track additions
|
|
292
|
+
* effect((t) => {
|
|
293
|
+
* const { key, value } = $users.$lastSet.get(t);
|
|
294
|
+
* if (key) console.log(`Added: ${key}`);
|
|
295
|
+
* });
|
|
296
|
+
*
|
|
297
|
+
* $users.setAt('user2', { name: 'Jane', age: 25 });
|
|
298
|
+
* ```
|
|
299
|
+
*
|
|
84
300
|
* @public
|
|
85
301
|
*/
|
|
86
302
|
export declare function map<K extends string | number | symbol, V>(initial?: Record<K, V>): FlowMap<K, V>;
|
|
87
303
|
/**
|
|
88
|
-
* Creates a new reactive array.
|
|
89
|
-
*
|
|
304
|
+
* Creates a new reactive array with mutation methods and fine-grained action tracking.
|
|
305
|
+
*
|
|
306
|
+
* @typeParam T - The type of the array elements.
|
|
90
307
|
* @param initial - An optional array of initial values.
|
|
91
308
|
* @returns A new instance of {@link FlowArray}.
|
|
309
|
+
*
|
|
310
|
+
* @remarks
|
|
311
|
+
* A reactive array provides array-like mutation methods (push, pop, shift, unshift, splice)
|
|
312
|
+
* and tracks the last operation performed via `$lastAction`. This enables both whole-array
|
|
313
|
+
* reactivity and fine-grained tracking of specific mutations.
|
|
314
|
+
*
|
|
315
|
+
* The array automatically disposes disposable items when they are removed (if they implement
|
|
316
|
+
* the FlowDisposable interface).
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* ```typescript
|
|
320
|
+
* const $items = array([1, 2, 3]);
|
|
321
|
+
*
|
|
322
|
+
* // Track the whole array
|
|
323
|
+
* effect((t) => {
|
|
324
|
+
* console.log('Items:', $items.get(t));
|
|
325
|
+
* });
|
|
326
|
+
*
|
|
327
|
+
* // Track the last action
|
|
328
|
+
* effect((t) => {
|
|
329
|
+
* const action = $items.$lastAction.get(t);
|
|
330
|
+
* console.log('Action:', action.type);
|
|
331
|
+
* });
|
|
332
|
+
*
|
|
333
|
+
* $items.push(4); // Logs action: "push"
|
|
334
|
+
* $items.pop(); // Logs action: "pop"
|
|
335
|
+
* ```
|
|
336
|
+
*
|
|
92
337
|
* @public
|
|
93
338
|
*/
|
|
94
339
|
export declare function array<T>(initial?: T[]): FlowArray<T>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"creators.d.ts","sourceRoot":"","sources":["../../src/creators.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"creators.d.ts","sourceRoot":"","sources":["../../src/creators.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,OAAO,EACP,YAAY,EACZ,iBAAiB,EACjB,UAAU,EACV,eAAe,EACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EACN,YAAY,EACZ,cAAc,EACd,UAAU,EACV,UAAU,EACV,SAAS,EACT,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,MAAM,IAAI,UAAU,CAEnC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAEjE;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAE3D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAEjE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAE3E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,MAAM,CAAC,CAAC,EACvB,OAAO,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,KAAK,MAAM,IAAI,GAC9C,UAAU,CAAC,CAAC,CAAC,CAEf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC5B,OAAO,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,KAAK,MAAM,IAAI,GAC9C,eAAe,CAAC,CAAC,CAAC,CAEpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC3B,EAAE,EAAE,CAAC,CAAC,EAAE,eAAe,KAAK,CAAC,GAC3B,cAAc,CAAC,CAAC,CAAC,CAEnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,eAAe,KAAK,IAAI,GAAG,UAAU,CAEnE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,EACxD,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GACpB,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAIf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,CAEpD"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,13 +1,66 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
*
|
|
4
|
-
* PicoFlow
|
|
5
|
-
* reactive primitives such as signals, state, resources, streams, derivations,
|
|
6
|
-
* effects, and reactive maps.
|
|
4
|
+
* # PicoFlow
|
|
7
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}
|
|
8
61
|
*/
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export { from,
|
|
62
|
+
export { FlowArray, type FlowArrayAction, FlowMap, FlowResource, FlowResourceAsync, FlowStream, FlowStreamAsync, type FlowStreamDisposer, type FlowStreamSetter, type FlowStreamUpdater, } from './advanced/';
|
|
63
|
+
export { FlowConstant, FlowDerivation, type FlowDisposable, FlowEffect, FlowObservable, FlowSignal, FlowState, isDisposable, TrackingContext, } from './basic/';
|
|
64
|
+
export { array, constant, derivation, effect, map, resource, resourceAsync, signal, state, stream, streamAsync, } from './creators';
|
|
65
|
+
export { from, type NotPromise, SolidDerivation, type SolidGetter, type SolidObservable, SolidResource, SolidState, } from './solid/';
|
|
13
66
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAEH,OAAO,EACN,SAAS,EACT,KAAK,eAAe,EACpB,OAAO,EACP,YAAY,EACZ,iBAAiB,EACjB,UAAU,EACV,eAAe,EACf,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,GACtB,MAAM,aAAa,CAAC;AAErB,OAAO,EACN,YAAY,EACZ,cAAc,EACd,KAAK,cAAc,EACnB,UAAU,EACV,cAAc,EACd,UAAU,EACV,SAAS,EACT,YAAY,EACZ,eAAe,GACf,MAAM,UAAU,CAAC;AAClB,OAAO,EACN,KAAK,EACL,QAAQ,EACR,UAAU,EACV,MAAM,EACN,GAAG,EACH,QAAQ,EACR,aAAa,EACb,MAAM,EACN,KAAK,EACL,MAAM,EACN,WAAW,GACX,MAAM,YAAY,CAAC;AAEpB,OAAO,EACN,IAAI,EACJ,KAAK,UAAU,EACf,eAAe,EACf,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,aAAa,EACb,UAAU,GACV,MAAM,UAAU,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { FlowObservable, TrackingContext } from '../basic';
|
|
2
|
+
import { SolidDerivation, SolidResource } from './primitives';
|
|
3
3
|
/**
|
|
4
4
|
* Utility type that excludes Promise types from T.
|
|
5
5
|
* Used to ensure type safety for synchronous derivations/resources.
|
|
@@ -42,7 +42,7 @@ export declare function from<T>(flow: FlowObservable<Promise<NotPromise<T>>> | F
|
|
|
42
42
|
*
|
|
43
43
|
* @public
|
|
44
44
|
*/
|
|
45
|
-
export declare function from<T>(flow: (
|
|
45
|
+
export declare function from<T>(flow: (t: TrackingContext) => NotPromise<T>): SolidDerivation<NotPromise<T>>;
|
|
46
46
|
/**
|
|
47
47
|
* Converts a getter function returning a Promise into a SolidResource.
|
|
48
48
|
*
|
|
@@ -51,7 +51,7 @@ export declare function from<T>(flow: (get: FlowGetter) => NotPromise<T>): Solid
|
|
|
51
51
|
*
|
|
52
52
|
* @public
|
|
53
53
|
*/
|
|
54
|
-
export declare function from<T>(flow: (
|
|
54
|
+
export declare function from<T>(flow: (t: TrackingContext) => Promise<NotPromise<T>>): SolidResource<NotPromise<T>>;
|
|
55
55
|
/**
|
|
56
56
|
* Converts a getter function into a Solid derivation or resource, depending on whether the returned value is synchronous or asynchronous.
|
|
57
57
|
*
|
|
@@ -60,5 +60,5 @@ export declare function from<T>(flow: (get: FlowGetter) => Promise<NotPromise<T>
|
|
|
60
60
|
*
|
|
61
61
|
* @public
|
|
62
62
|
*/
|
|
63
|
-
export declare function from<T>(flow: ((
|
|
63
|
+
export declare function from<T>(flow: ((t: TrackingContext) => NotPromise<T>) | ((t: TrackingContext) => Promise<NotPromise<T>>)): SolidDerivation<T> | SolidResource<T>;
|
|
64
64
|
//# sourceMappingURL=converters.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../../src/solid/converters.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../../src/solid/converters.ts"],"names":[],"mappings":"AACA,OAAO,EAGN,cAAc,EACd,KAAK,eAAe,EACpB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,KAAK,eAAe,EAAE,aAAa,EAAc,MAAM,cAAc,CAAC;AAuI/E;;;;;GAKG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,OAAO,CAAC,OAAO,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;AAEnE;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,CAAC,EACrB,IAAI,EAAE,cAAc,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,GAC1C,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAChC;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,CAAC,EACrB,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GACjC,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAClC;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,CAAC,EACrB,IAAI,EAAE,cAAc,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAC1E,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AACjE;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,CAAC,EACrB,IAAI,EAAE,CAAC,CAAC,EAAE,eAAe,KAAK,UAAU,CAAC,CAAC,CAAC,GACzC,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAClC;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,CAAC,EACrB,IAAI,EAAE,CAAC,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAClD,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAChC;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,CAAC,EACrB,IAAI,EACD,CAAC,CAAC,CAAC,EAAE,eAAe,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,GACvC,CAAC,CAAC,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,GACjD,eAAe,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { from } from './converters';
|
|
2
|
-
export {
|
|
1
|
+
export { from, type NotPromise } from './converters';
|
|
2
|
+
export { SolidDerivation, type SolidGetter, type SolidObservable, SolidResource, SolidState, } from './primitives';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/solid/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/solid/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EACN,eAAe,EACf,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,aAAa,EACb,UAAU,GACV,MAAM,cAAc,CAAC"}
|
|
@@ -19,7 +19,30 @@ export interface SolidObservable<T> {
|
|
|
19
19
|
get: () => T;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
* Solid-style state container,
|
|
22
|
+
* Solid-style state container wrapping SolidJS's createSignal, providing a writable reactive signal.
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* SolidState is a thin wrapper around SolidJS's `createSignal` that provides a class-based
|
|
26
|
+
* interface consistent with PicoFlow's API style. It's used internally by PicoFlow's Solid
|
|
27
|
+
* integration but can also be used directly in Solid components.
|
|
28
|
+
*
|
|
29
|
+
* Unlike PicoFlow's {@link FlowState} which uses explicit tracking context, SolidState
|
|
30
|
+
* relies on SolidJS's automatic dependency tracking within reactive contexts like
|
|
31
|
+
* `createEffect` or component render functions.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const count = new SolidState(0);
|
|
36
|
+
*
|
|
37
|
+
* // In a Solid component
|
|
38
|
+
* function Counter() {
|
|
39
|
+
* return <div>{count.get()}</div>; // Automatically reactive
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* // Update the value
|
|
43
|
+
* count.set(1);
|
|
44
|
+
* count.set(prev => prev + 1);
|
|
45
|
+
* ```
|
|
23
46
|
*
|
|
24
47
|
* @typeParam T - The value type.
|
|
25
48
|
* @public
|
|
@@ -40,7 +63,35 @@ export declare class SolidState<T> implements SolidObservable<T> {
|
|
|
40
63
|
constructor(initialValue: T);
|
|
41
64
|
}
|
|
42
65
|
/**
|
|
43
|
-
* Solid-style derivation,
|
|
66
|
+
* Solid-style derivation wrapping SolidJS's createMemo, providing a computed reactive value.
|
|
67
|
+
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* SolidDerivation is a thin wrapper around SolidJS's `createMemo` that provides a class-based
|
|
70
|
+
* interface consistent with PicoFlow's API style. It creates a memoized computation that
|
|
71
|
+
* automatically tracks its dependencies and recomputes only when they change.
|
|
72
|
+
*
|
|
73
|
+
* Unlike PicoFlow's {@link FlowDerivation} which uses explicit tracking context, SolidDerivation
|
|
74
|
+
* relies on SolidJS's automatic dependency tracking. The computation function runs within
|
|
75
|
+
* SolidJS's reactive scope and automatically subscribes to any signals accessed during execution.
|
|
76
|
+
*
|
|
77
|
+
* **Memoization:**
|
|
78
|
+
* The computed value is cached and only recomputed when tracked dependencies change,
|
|
79
|
+
* providing efficient derived state management.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const firstName = new SolidState('John');
|
|
84
|
+
* const lastName = new SolidState('Doe');
|
|
85
|
+
*
|
|
86
|
+
* const fullName = new SolidDerivation(() => {
|
|
87
|
+
* return `${firstName.get()} ${lastName.get()}`;
|
|
88
|
+
* });
|
|
89
|
+
*
|
|
90
|
+
* // In a Solid component
|
|
91
|
+
* function Display() {
|
|
92
|
+
* return <div>{fullName.get()}</div>; // Automatically updates
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
44
95
|
*
|
|
45
96
|
* @typeParam T - The value type.
|
|
46
97
|
* @public
|
|
@@ -57,7 +108,48 @@ export declare class SolidDerivation<T> implements SolidObservable<T> {
|
|
|
57
108
|
constructor(calculator: SolidGetter<T>);
|
|
58
109
|
}
|
|
59
110
|
/**
|
|
60
|
-
* Solid-style resource
|
|
111
|
+
* Solid-style resource wrapping SolidJS's createResource, providing async data loading with reactive state.
|
|
112
|
+
*
|
|
113
|
+
* @remarks
|
|
114
|
+
* SolidResource is a thin wrapper around SolidJS's `createResource` that provides a class-based
|
|
115
|
+
* interface consistent with PicoFlow's API style. It manages asynchronous data fetching with
|
|
116
|
+
* built-in loading states, error handling, and automatic reactivity.
|
|
117
|
+
*
|
|
118
|
+
* Unlike PicoFlow's {@link FlowResource} or {@link FlowResourceAsync}, SolidResource integrates
|
|
119
|
+
* directly with SolidJS's Suspense and ErrorBoundary mechanisms, providing a first-class async
|
|
120
|
+
* data loading experience in Solid applications.
|
|
121
|
+
*
|
|
122
|
+
* **Resource States:**
|
|
123
|
+
* - `unresolved`: Initial state before first fetch
|
|
124
|
+
* - `pending`: Fetch is in progress
|
|
125
|
+
* - `ready`: Data has been successfully loaded
|
|
126
|
+
* - `refreshing`: Refetching while previous data is still available
|
|
127
|
+
* - `errored`: Fetch failed with an error
|
|
128
|
+
*
|
|
129
|
+
* **Properties:**
|
|
130
|
+
* - `get()`: Returns the current value (or undefined if not ready)
|
|
131
|
+
* - `state()`: Returns the current loading state
|
|
132
|
+
* - `latest()`: Returns the most recent successfully loaded value
|
|
133
|
+
* - `refetch()`: Triggers a new fetch operation
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* const user = new SolidResource(async () => {
|
|
138
|
+
* const res = await fetch('/api/user');
|
|
139
|
+
* return res.json();
|
|
140
|
+
* });
|
|
141
|
+
*
|
|
142
|
+
* // In a Solid component
|
|
143
|
+
* function UserProfile() {
|
|
144
|
+
* return (
|
|
145
|
+
* <div>
|
|
146
|
+
* {user.state() === 'pending' && <p>Loading...</p>}
|
|
147
|
+
* {user.state() === 'ready' && <p>Name: {user.get()?.name}</p>}
|
|
148
|
+
* <button onClick={() => user.refetch()}>Refresh</button>
|
|
149
|
+
* </div>
|
|
150
|
+
* );
|
|
151
|
+
* }
|
|
152
|
+
* ```
|
|
61
153
|
*
|
|
62
154
|
* @typeParam T - The value type.
|
|
63
155
|
* @public
|
|
@@ -70,7 +162,7 @@ export declare class SolidResource<T> implements SolidObservable<T | undefined>
|
|
|
70
162
|
/**
|
|
71
163
|
* Returns the current resource state.
|
|
72
164
|
*/
|
|
73
|
-
readonly state: () =>
|
|
165
|
+
readonly state: () => "unresolved" | "pending" | "errored" | "ready" | "refreshing";
|
|
74
166
|
/**
|
|
75
167
|
* Returns the latest successfully loaded value (or undefined).
|
|
76
168
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../../src/solid/primitives.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../../src/solid/primitives.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,KAAK,eAAe,EACpB,MAAM,UAAU,CAAC;AAElB;;;;;GAKG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC;IACjC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC,CAAC;CACb;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,UAAU,CAAC,CAAC,CAAE,YAAW,eAAe,CAAC,CAAC,CAAC;IACvD;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACtB;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IAE9C;;;OAGG;gBACS,YAAY,EAAE,CAAC;CAK3B;AAGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAAa,eAAe,CAAC,CAAC,CAAE,YAAW,eAAe,CAAC,CAAC,CAAC;IAC5D;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAEtB;;;OAGG;gBACS,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;CAItC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,qBAAa,aAAa,CAAC,CAAC,CAAE,YAAW,eAAe,CAAC,CAAC,GAAG,SAAS,CAAC;IACtE;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IAClC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MACb,YAAY,GACZ,SAAS,GACT,SAAS,GACT,OAAO,GACP,YAAY,CAAC;IAChB;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IACrC;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;IAE7B;;;OAGG;gBACS,OAAO,EAAE,eAAe,CAAC,IAAI,EAAE,CAAC,EAAE,OAAO,CAAC;CAOtD"}
|