@ersbeth/picoflow 0.0.1 → 0.2.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/api/doc/index.md +1 -1
- package/api/doc/picoflow.array.md +55 -0
- package/api/doc/picoflow.constant.md +55 -0
- package/api/doc/picoflow.derivation.md +1 -1
- package/api/doc/picoflow.effect.md +1 -1
- package/api/doc/picoflow.flowarray._constructor_.md +49 -0
- package/api/doc/picoflow.flowarray._lastaction.md +13 -0
- package/api/doc/picoflow.flowarray.clear.md +17 -0
- package/api/doc/picoflow.flowarray.dispose.md +55 -0
- package/api/doc/picoflow.flowarray.get.md +19 -0
- package/api/doc/picoflow.flowarray.length.md +13 -0
- package/api/doc/picoflow.flowarray.md +273 -0
- package/api/doc/picoflow.flowarray.pop.md +17 -0
- package/api/doc/picoflow.flowarray.push.md +53 -0
- package/api/doc/picoflow.flowarray.set.md +53 -0
- package/api/doc/picoflow.flowarray.setitem.md +69 -0
- package/api/doc/picoflow.flowarray.shift.md +17 -0
- package/api/doc/picoflow.flowarray.splice.md +85 -0
- package/api/doc/picoflow.flowarray.unshift.md +53 -0
- package/api/doc/picoflow.flowarrayaction.md +37 -0
- package/api/doc/picoflow.flowconstant._constructor_.md +49 -0
- package/api/doc/picoflow.flowconstant.get.md +25 -0
- package/api/doc/picoflow.flowconstant.md +88 -0
- package/api/doc/picoflow.flowderivation._constructor_.md +2 -2
- package/api/doc/picoflow.flowderivation.get.md +2 -2
- package/api/doc/picoflow.flowderivation.md +2 -2
- package/api/doc/picoflow.flowdisposable.dispose.md +55 -0
- package/api/doc/picoflow.flowdisposable.md +43 -0
- package/api/doc/picoflow.floweffect._constructor_.md +7 -2
- package/api/doc/picoflow.floweffect.dispose.md +3 -3
- package/api/doc/picoflow.floweffect.disposed.md +1 -1
- package/api/doc/picoflow.floweffect.md +4 -4
- package/api/doc/picoflow.flowgetter.md +2 -2
- package/api/doc/picoflow.flowmap._lastdeleted.md +1 -1
- package/api/doc/picoflow.flowmap._lastset.md +1 -1
- package/api/doc/picoflow.flowmap.delete.md +6 -2
- package/api/doc/picoflow.flowmap.md +5 -7
- package/api/doc/picoflow.flowmap.setat.md +6 -2
- package/api/doc/picoflow.flowobservable.get.md +3 -3
- package/api/doc/picoflow.flowobservable.md +18 -4
- package/api/doc/picoflow.flowobservable.subscribe.md +55 -0
- package/api/doc/picoflow.flowresource._constructor_.md +2 -18
- package/api/doc/picoflow.flowresource.fetch.md +1 -1
- package/api/doc/picoflow.flowresource.get.md +4 -4
- package/api/doc/picoflow.flowresource.md +4 -4
- package/api/doc/picoflow.flowresourceasync._constructor_.md +49 -0
- package/api/doc/picoflow.flowresourceasync.fetch.md +27 -0
- package/api/doc/picoflow.flowresourceasync.get.md +23 -0
- package/api/doc/picoflow.flowresourceasync.md +100 -0
- package/api/doc/picoflow.flowsignal.dispose.md +42 -8
- package/api/doc/picoflow.flowsignal.disposed.md +2 -2
- package/api/doc/picoflow.flowsignal.md +8 -7
- package/api/doc/picoflow.flowsignal.trigger.md +3 -7
- package/api/doc/picoflow.flowstate.md +4 -52
- package/api/doc/picoflow.flowstate.set.md +5 -5
- package/api/doc/picoflow.flowstream._constructor_.md +3 -19
- package/api/doc/picoflow.flowstream.dispose.md +1 -1
- package/api/doc/picoflow.flowstream.get.md +4 -4
- package/api/doc/picoflow.flowstream.md +5 -5
- package/api/doc/picoflow.flowstreamasync._constructor_.md +54 -0
- package/api/doc/picoflow.flowstreamasync.dispose.md +21 -0
- package/api/doc/picoflow.flowstreamasync.get.md +23 -0
- package/api/doc/picoflow.flowstreamasync.md +100 -0
- package/api/doc/picoflow.flowstreamdisposer.md +13 -0
- package/api/doc/picoflow.flowstreamsetter.md +13 -0
- package/api/doc/picoflow.flowstreamupdater.md +19 -0
- package/api/doc/picoflow.flowwatcher.md +1 -1
- package/api/doc/picoflow.isdisposable.md +55 -0
- package/api/doc/picoflow.map.md +1 -1
- package/api/doc/picoflow.md +149 -13
- package/api/doc/picoflow.resource.md +2 -18
- package/api/doc/picoflow.resourceasync.md +55 -0
- package/api/doc/picoflow.signal.md +1 -1
- package/api/doc/picoflow.state.md +3 -3
- package/api/doc/picoflow.stream.md +2 -18
- package/api/doc/picoflow.streamasync.md +55 -0
- package/api/picoflow.public.api.md +192 -0
- package/api-extractor.json +2 -1
- package/dist/picoflow.js +513 -305
- package/dist/types/advanced/array.d.ts +116 -0
- package/dist/types/advanced/array.d.ts.map +1 -0
- package/dist/types/advanced/index.d.ts +9 -0
- package/dist/types/advanced/index.d.ts.map +1 -0
- package/dist/types/{map.d.ts → advanced/map.d.ts} +12 -12
- package/dist/types/advanced/map.d.ts.map +1 -0
- package/dist/types/advanced/resource.d.ts +39 -0
- package/dist/types/advanced/resource.d.ts.map +1 -0
- package/dist/types/{resource.d.ts → advanced/resourceAsync.d.ts} +6 -11
- package/dist/types/advanced/resourceAsync.d.ts.map +1 -0
- package/dist/types/advanced/stream.d.ts +59 -0
- package/dist/types/advanced/stream.d.ts.map +1 -0
- package/dist/types/advanced/streamAsync.d.ts +43 -0
- package/dist/types/advanced/streamAsync.d.ts.map +1 -0
- package/dist/types/basic/constant.d.ts +32 -0
- package/dist/types/basic/constant.d.ts.map +1 -0
- package/dist/types/basic/derivation.d.ts +40 -0
- package/dist/types/basic/derivation.d.ts.map +1 -0
- package/dist/types/basic/disposable.d.ts +23 -0
- package/dist/types/basic/disposable.d.ts.map +1 -0
- package/dist/types/basic/effect.d.ts +56 -0
- package/dist/types/basic/effect.d.ts.map +1 -0
- package/dist/types/basic/index.d.ts +11 -0
- package/dist/types/basic/index.d.ts.map +1 -0
- package/dist/types/basic/observable.d.ts +34 -0
- package/dist/types/basic/observable.d.ts.map +1 -0
- package/dist/types/basic/signal.d.ts +40 -0
- package/dist/types/basic/signal.d.ts.map +1 -0
- package/dist/types/basic/state.d.ts +26 -0
- package/dist/types/basic/state.d.ts.map +1 -0
- package/dist/types/creators.d.ts +38 -13
- package/dist/types/creators.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -9
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/advanced/array.ts +224 -0
- package/src/advanced/index.ts +12 -0
- package/src/{map.ts → advanced/map.ts} +14 -14
- package/src/advanced/resource.ts +56 -0
- package/src/{resource.ts → advanced/resourceAsync.ts} +9 -16
- package/src/advanced/stream.ts +87 -0
- package/src/advanced/streamAsync.ts +82 -0
- package/src/basic/constant.ts +64 -0
- package/src/basic/derivation.ts +86 -0
- package/src/basic/disposable.ts +27 -0
- package/src/basic/effect.ts +96 -0
- package/src/basic/index.ts +10 -0
- package/src/basic/observable.ts +51 -0
- package/src/basic/signal.ts +117 -0
- package/src/basic/state.ts +39 -0
- package/src/creators.ts +66 -15
- package/src/index.ts +26 -11
- package/test/array.test.ts +620 -0
- package/test/constant.test.ts +46 -0
- package/test/derivation.test.ts +30 -6
- package/test/effect.test.ts +29 -0
- package/test/map.test.ts +38 -0
- package/test/resource.test.ts +18 -16
- package/test/resourceAsync.test.ts +108 -0
- package/test/signal.test.ts +18 -1
- package/test/state.test.ts +107 -2
- package/test/stream.test.ts +38 -13
- package/test/streamAsync.test.ts +194 -0
- package/tsconfig.json +3 -1
- package/api/doc/picoflow.flowdisposer.md +0 -13
- package/api/doc/picoflow.flowsetter.md +0 -13
- package/api/doc/picoflow.flowstate._constructor_.md +0 -49
- package/api/doc/picoflow.flowstate.get.md +0 -23
- package/api/doc/picoflow.flowupdater.md +0 -19
- package/api/picoflow.api.md +0 -145
- package/dist/types/derivation.d.ts +0 -58
- package/dist/types/derivation.d.ts.map +0 -1
- package/dist/types/effect.d.ts +0 -108
- package/dist/types/effect.d.ts.map +0 -1
- package/dist/types/map.d.ts.map +0 -1
- package/dist/types/observable.d.ts +0 -40
- package/dist/types/observable.d.ts.map +0 -1
- package/dist/types/resource.d.ts.map +0 -1
- package/dist/types/signal.d.ts +0 -111
- package/dist/types/signal.d.ts.map +0 -1
- package/dist/types/state.d.ts +0 -39
- package/dist/types/state.d.ts.map +0 -1
- package/dist/types/stream.d.ts +0 -71
- package/dist/types/stream.d.ts.map +0 -1
- package/src/derivation.ts +0 -96
- package/src/effect.ts +0 -152
- package/src/observable.ts +0 -50
- package/src/signal.ts +0 -166
- package/src/state.ts +0 -52
- package/src/stream.ts +0 -99
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { FlowDisposable } from './disposable';
|
|
2
|
+
/**
|
|
3
|
+
* A function for watching a FlowSignal.
|
|
4
|
+
* @param signal - The FlowSignal that is being observed.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export type FlowWatcher = (signal: FlowSignal) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Represents a reactive signal.
|
|
10
|
+
*
|
|
11
|
+
* @remarks Use FlowSignal to create reactive streams that notify listeners and execute associated effects.
|
|
12
|
+
* Signals can be triggered and disposed. Once disposed, interactions with the signal will throw errors.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export declare class FlowSignal implements FlowDisposable {
|
|
16
|
+
/**
|
|
17
|
+
* Triggers the FlowSignal.
|
|
18
|
+
* Notifies all registered listeners and schedules execution of associated effects.
|
|
19
|
+
* @throws If the FlowSignal has already been disposed.
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
trigger(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Disposes the FlowSignal.
|
|
25
|
+
* Cleans up all registered effects, listeners, and dependencies.
|
|
26
|
+
* Once disposed, further usage of the signal will throw an error.
|
|
27
|
+
* @throws If the FlowSignal is already disposed.
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
dispose(options?: {
|
|
31
|
+
self: boolean;
|
|
32
|
+
}): void;
|
|
33
|
+
/**
|
|
34
|
+
* Indicates whether the FlowSignal has been disposed.
|
|
35
|
+
* @remarks Once disposed, the signal should not be used.
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
get disposed(): boolean;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=signal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signal.d.ts","sourceRoot":"","sources":["../../../src/basic/signal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGnD;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;AAEvD;;;;;;GAMG;AACH,qBAAa,UAAW,YAAW,cAAc;IAC7C;;;;;OAKG;IACI,OAAO,IAAI,IAAI;IAKtB;;;;;;OAMG;IACI,OAAO,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;IAqBjD;;;;OAIG;IACH,IAAW,QAAQ,IAAI,OAAO,CAE7B;CAoDJ"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { FlowConstant } from './constant';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a reactive state that holds a mutable value.
|
|
4
|
+
*
|
|
5
|
+
* @typeparam T - The type of the state value.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* FlowState extends FlowConstant, which provides the {@link FlowConstant.get} method to read
|
|
9
|
+
* the current state. Use the {@link FlowState.set} method to update the state. When the state is updated,
|
|
10
|
+
* subscribers are notified automatically. This class notifies subscribers only when the value changes.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export declare class FlowState<T> extends FlowConstant<T> {
|
|
15
|
+
/**
|
|
16
|
+
* Updates the state with a new value.
|
|
17
|
+
* @param value - A new value or a callback function that computes a new value based on the current state.
|
|
18
|
+
* @remarks
|
|
19
|
+
* If the computed new value is strictly equal to the current state value, no change is made and subscribers
|
|
20
|
+
* will not be notified. Otherwise, the state is updated and all subscribers are informed of the change.
|
|
21
|
+
* @throws Error if the state has been disposed.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
set(value: T | ((current: T) => T)): void;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/basic/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C;;;;;;;;;;;GAWG;AACH,qBAAa,SAAS,CAAC,CAAC,CAAE,SAAQ,YAAY,CAAC,CAAC,CAAC;IAC7C;;;;;;;;OAQG;IACH,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI;CAc5C"}
|
package/dist/types/creators.d.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { FlowGetter } from './
|
|
4
|
-
import { FlowResource } from './resource';
|
|
5
|
-
import { FlowSignal, FlowWatcher } from './signal';
|
|
6
|
-
import { FlowState } from './state';
|
|
7
|
-
import { FlowMap } from './map';
|
|
8
|
-
import { FlowStream } from './stream';
|
|
1
|
+
import { FlowMap, FlowResource, FlowResourceAsync, FlowStream, FlowStreamAsync } from './advanced/';
|
|
2
|
+
import { FlowArray } from './advanced/array';
|
|
3
|
+
import { FlowConstant, FlowDerivation, FlowEffect, FlowSignal, FlowState, FlowGetter, FlowWatcher } from './basic/';
|
|
9
4
|
/**
|
|
10
5
|
* Creates a new reactive signal.
|
|
11
6
|
* @returns A new instance of {@link FlowSignal}.
|
|
12
7
|
* @public
|
|
13
8
|
*/
|
|
14
9
|
export declare function signal(): FlowSignal;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new reactive constant.
|
|
12
|
+
* @param value - The value or a function that returns the value.
|
|
13
|
+
* @returns A new instance of {@link FlowConstant}.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export declare function constant<T>(value: T | (() => T)): FlowConstant<T>;
|
|
15
17
|
/**
|
|
16
18
|
* Creates a new reactive state holding a value.
|
|
17
19
|
* @typeparam T - The type of the state value.
|
|
@@ -19,26 +21,41 @@ export declare function signal(): FlowSignal;
|
|
|
19
21
|
* @returns A new instance of {@link FlowState}.
|
|
20
22
|
* @public
|
|
21
23
|
*/
|
|
22
|
-
export declare function state<T>(value: T): FlowState<T>;
|
|
24
|
+
export declare function state<T>(value: T | (() => T)): FlowState<T>;
|
|
23
25
|
/**
|
|
24
26
|
* Creates a new reactive resource that asynchronously fetches its value.
|
|
25
27
|
* @typeparam T - The type of the resource value.
|
|
26
28
|
* @param fn - An asynchronous function that fetches the resource value.
|
|
27
|
-
* @param initial - The initial value of the resource.
|
|
28
29
|
* @returns A new instance of {@link FlowResource}.
|
|
29
30
|
* @public
|
|
30
31
|
*/
|
|
31
|
-
export declare function resource<T>(fn: () => Promise<T
|
|
32
|
+
export declare function resource<T>(fn: () => Promise<T>): FlowResource<T>;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new reactive asynchronous resource that fetches its value.
|
|
35
|
+
* @typeparam T - The type of the resource value.
|
|
36
|
+
* @param fn - An asynchronous function that fetches the resource value.
|
|
37
|
+
* @returns A new instance of {@link FlowResourceAsync}.
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
export declare function resourceAsync<T>(fn: () => Promise<T>): FlowResourceAsync<T>;
|
|
32
41
|
/**
|
|
33
42
|
* Creates a new reactive stream.
|
|
34
43
|
* @typeparam T - The type of the stream value.
|
|
35
44
|
* @param updater - A function that receives a setter to update the stream's value.
|
|
36
45
|
* It should return a disposer function to clean up resources.
|
|
37
|
-
* @param initial - The initial value of the stream.
|
|
38
46
|
* @returns A new instance of {@link FlowStream}.
|
|
39
47
|
* @public
|
|
40
48
|
*/
|
|
41
|
-
export declare function stream<T>(updater: (set: (value: T) => void) => () => void
|
|
49
|
+
export declare function stream<T>(updater: (set: (value: T) => void) => () => void): FlowStream<T>;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a new reactive asynchronous stream.
|
|
52
|
+
* @typeparam T - The type of the stream value.
|
|
53
|
+
* @param updater - A function that receives a setter to update the stream's value.
|
|
54
|
+
* It should return a disposer function to clean up resources.
|
|
55
|
+
* @returns A new instance of {@link FlowStreamAsync}.
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
export declare function streamAsync<T>(updater: (set: (value: T) => void) => () => void): FlowStreamAsync<T>;
|
|
42
59
|
/**
|
|
43
60
|
* Creates a new reactive derivation whose value is computed based on other reactive signals.
|
|
44
61
|
* @typeparam T - The type of the derived value.
|
|
@@ -67,4 +84,12 @@ export declare function effect(fn: (get: FlowGetter, watch: FlowWatcher) => void
|
|
|
67
84
|
* @public
|
|
68
85
|
*/
|
|
69
86
|
export declare function map<K extends string | number | symbol, V>(initial?: Record<K, V>): FlowMap<K, V>;
|
|
87
|
+
/**
|
|
88
|
+
* Creates a new reactive array.
|
|
89
|
+
* @typeparam T - The type of the array elements.
|
|
90
|
+
* @param initial - An optional array of initial values.
|
|
91
|
+
* @returns A new instance of {@link FlowArray}.
|
|
92
|
+
* @public
|
|
93
|
+
*/
|
|
94
|
+
export declare function array<T>(initial?: T[]): FlowArray<T>;
|
|
70
95
|
//# sourceMappingURL=creators.d.ts.map
|
|
@@ -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,EACH,OAAO,EACP,YAAY,EACZ,iBAAiB,EACjB,UAAU,EACV,eAAe,EAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EACH,YAAY,EACZ,cAAc,EACd,UAAU,EACV,UAAU,EACV,SAAS,EACZ,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAExD;;;;GAIG;AACH,wBAAgB,MAAM,IAAI,UAAU,CAEnC;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAEjE;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAE3D;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAEjE;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAE3E;AAED;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,CAAC,EACpB,OAAO,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,KAAK,MAAM,IAAI,GACjD,UAAU,CAAC,CAAC,CAAC,CAEf;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,CAAC,EACzB,OAAO,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,KAAK,MAAM,IAAI,GACjD,eAAe,CAAC,CAAC,CAAC,CAEpB;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,CAAC,EACxB,EAAE,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,KAAK,CAAC,GAC/C,cAAc,CAAC,CAAC,CAAC,CAEnB;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAClB,EAAE,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,KAAK,IAAI,GAClD,UAAU,CAEZ;AAED;;;;;;;;;GASG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,EACrD,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GACvB,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAIf;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,CAEpD"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -6,13 +6,8 @@
|
|
|
6
6
|
* effects, and reactive maps.
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
|
-
export { signal, state, resource, stream, derivation, effect, map } from './creators';
|
|
10
|
-
export
|
|
11
|
-
export type { FlowEffect } from './
|
|
12
|
-
export type {
|
|
13
|
-
export type { FlowResource } from './resource';
|
|
14
|
-
export type { FlowSignal, FlowWatcher } from './signal';
|
|
15
|
-
export type { FlowState } from './state';
|
|
16
|
-
export type { FlowMap } from './map';
|
|
17
|
-
export type { FlowStream, FlowDisposer, FlowSetter, FlowUpdater } from './stream';
|
|
9
|
+
export { signal, state, constant, resource, stream, derivation, effect, map, array, streamAsync, resourceAsync, } from './creators';
|
|
10
|
+
export { isDisposable } from './basic';
|
|
11
|
+
export type { FlowDerivation, FlowEffect, FlowGetter, FlowObservable, FlowSignal, FlowWatcher, FlowState, FlowConstant, FlowDisposable, } from './basic/';
|
|
12
|
+
export type { FlowResource, FlowMap, FlowResourceAsync, FlowStreamAsync, FlowStream, FlowStreamDisposer, FlowStreamSetter, FlowStreamUpdater, FlowArray, FlowArrayAction, } from './advanced/';
|
|
18
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACH,MAAM,EACN,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,UAAU,EACV,MAAM,EACN,GAAG,EACH,KAAK,EACL,WAAW,EACX,aAAa,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,YAAY,EACR,cAAc,EACd,UAAU,EACV,UAAU,EACV,cAAc,EACd,UAAU,EACV,WAAW,EACX,SAAS,EACT,YAAY,EACZ,cAAc,GACjB,MAAM,UAAU,CAAC;AAClB,YAAY,EACR,YAAY,EACZ,OAAO,EACP,iBAAiB,EACjB,eAAe,EACf,UAAU,EACV,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,EACT,eAAe,GAClB,MAAM,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { FlowObservable, type FlowState } from "../basic";
|
|
2
|
+
import { isDisposable } from "../basic";
|
|
3
|
+
import { state } from "../creators";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Represents the actions that can be performed on a FlowArray.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export type FlowArrayAction<T> =
|
|
10
|
+
| {
|
|
11
|
+
type: "set";
|
|
12
|
+
items: T[];
|
|
13
|
+
}
|
|
14
|
+
| {
|
|
15
|
+
type: "setItem";
|
|
16
|
+
index: number;
|
|
17
|
+
item: T;
|
|
18
|
+
}
|
|
19
|
+
| {
|
|
20
|
+
type: "push";
|
|
21
|
+
item: T;
|
|
22
|
+
}
|
|
23
|
+
| {
|
|
24
|
+
type: "pop";
|
|
25
|
+
}
|
|
26
|
+
| {
|
|
27
|
+
type: "unshift";
|
|
28
|
+
item: T;
|
|
29
|
+
}
|
|
30
|
+
| {
|
|
31
|
+
type: "shift";
|
|
32
|
+
}
|
|
33
|
+
| {
|
|
34
|
+
type: "splice";
|
|
35
|
+
start: number;
|
|
36
|
+
deleteCount: number;
|
|
37
|
+
items: T[];
|
|
38
|
+
}
|
|
39
|
+
| {
|
|
40
|
+
type: "clear";
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Represents a reactive array.
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
export class FlowArray<T> extends FlowObservable<T[]> {
|
|
48
|
+
/**
|
|
49
|
+
* Last action performed on the FlowArray.
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
$lastAction: FlowState<FlowArrayAction<T>>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Creates an instance of FlowArray.
|
|
56
|
+
* @param value - Initial array value.
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
constructor(value: T[] = []) {
|
|
60
|
+
super();
|
|
61
|
+
this._value = value;
|
|
62
|
+
this.$lastAction = state<FlowArrayAction<T>>({
|
|
63
|
+
type: "set",
|
|
64
|
+
items: value,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Gets the current length of the array.
|
|
70
|
+
* @returns The length of the array.
|
|
71
|
+
* @public
|
|
72
|
+
*/
|
|
73
|
+
get length(): number {
|
|
74
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
75
|
+
return this._value.length;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Returns a copy of the internal array.
|
|
80
|
+
* @returns A copy of the array.
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
get(): T[] {
|
|
84
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
85
|
+
return [...this._value]; // Ensure nobody can modify the original array
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Replaces the entire array with new items.
|
|
90
|
+
* @param items - The new array of items.
|
|
91
|
+
* @public
|
|
92
|
+
*/
|
|
93
|
+
set(items: T[]): void {
|
|
94
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
95
|
+
this._value.forEach((item) => {
|
|
96
|
+
if (isDisposable(item)) item.dispose({ self: true });
|
|
97
|
+
});
|
|
98
|
+
this._value = items;
|
|
99
|
+
this._notify();
|
|
100
|
+
this.$lastAction.set({ type: "set", items: items });
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Replaces an item at a specific index.
|
|
105
|
+
* @param index - The index of the item to replace.
|
|
106
|
+
* @param item - The new item.
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
setItem(index: number, item: T): void {
|
|
110
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
111
|
+
if (index < 0 || index >= this._value.length) {
|
|
112
|
+
throw new Error("[PicoFlow] Index out of bounds");
|
|
113
|
+
}
|
|
114
|
+
this._value[index] = item;
|
|
115
|
+
this._notify();
|
|
116
|
+
this.$lastAction.set({ type: "setItem", index: index, item: item });
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Appends an item to the end of the array.
|
|
121
|
+
* @param item - The item to append.
|
|
122
|
+
* @public
|
|
123
|
+
*/
|
|
124
|
+
push(item: T): void {
|
|
125
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
126
|
+
this._value.push(item);
|
|
127
|
+
this._notify();
|
|
128
|
+
this.$lastAction.set({ type: "push", item: item });
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Removes the last item from the array.
|
|
133
|
+
* @public
|
|
134
|
+
*/
|
|
135
|
+
pop(): void {
|
|
136
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
137
|
+
const item = this._value.pop();
|
|
138
|
+
if (isDisposable(item)) {
|
|
139
|
+
item.dispose({ self: true });
|
|
140
|
+
}
|
|
141
|
+
this._notify();
|
|
142
|
+
this.$lastAction.set({ type: "pop" });
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Inserts an item at the beginning of the array.
|
|
147
|
+
* @param item - The item to insert.
|
|
148
|
+
* @public
|
|
149
|
+
*/
|
|
150
|
+
unshift(item: T): void {
|
|
151
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
152
|
+
this._value.unshift(item);
|
|
153
|
+
this._notify();
|
|
154
|
+
this.$lastAction.set({ type: "unshift", item: item });
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Removes the first item from the array.
|
|
159
|
+
* @public
|
|
160
|
+
*/
|
|
161
|
+
shift(): void {
|
|
162
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
163
|
+
const item = this._value.shift();
|
|
164
|
+
if (isDisposable(item)) {
|
|
165
|
+
item.dispose({ self: true });
|
|
166
|
+
}
|
|
167
|
+
this._notify();
|
|
168
|
+
this.$lastAction.set({ type: "shift" });
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Changes the content of the array.
|
|
173
|
+
* @param start - The starting index.
|
|
174
|
+
* @param deleteCount - Number of items to remove.
|
|
175
|
+
* @param newItems - New items to add.
|
|
176
|
+
* @public
|
|
177
|
+
*/
|
|
178
|
+
splice(start: number, deleteCount: number, ...newItems: T[]): void {
|
|
179
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
180
|
+
const items = this._value.splice(start, deleteCount, ...newItems);
|
|
181
|
+
items.forEach((item) => {
|
|
182
|
+
if (isDisposable(item)) item.dispose({ self: true });
|
|
183
|
+
});
|
|
184
|
+
this._notify();
|
|
185
|
+
this.$lastAction.set({
|
|
186
|
+
type: "splice",
|
|
187
|
+
start: start,
|
|
188
|
+
deleteCount: deleteCount,
|
|
189
|
+
items: newItems,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Clears all items from the array.
|
|
195
|
+
* @public
|
|
196
|
+
*/
|
|
197
|
+
clear(): void {
|
|
198
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
199
|
+
const items = [...this._value];
|
|
200
|
+
items.forEach((item) => {
|
|
201
|
+
if (isDisposable(item)) item.dispose({ self: true });
|
|
202
|
+
});
|
|
203
|
+
this._value = [];
|
|
204
|
+
this._notify();
|
|
205
|
+
this.$lastAction.set({ type: "clear" });
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Disposes the FlowArray and its items.
|
|
210
|
+
* @param options - Disposal options.
|
|
211
|
+
* @public
|
|
212
|
+
*/
|
|
213
|
+
override dispose(options?: { self: boolean }): void {
|
|
214
|
+
super.dispose(options);
|
|
215
|
+
this._value.forEach((item) => {
|
|
216
|
+
if (isDisposable(item)) item.dispose(options);
|
|
217
|
+
});
|
|
218
|
+
this._value = [];
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/* INTERNAL */
|
|
222
|
+
|
|
223
|
+
/*@internal*/ protected override _value: T[] = [];
|
|
224
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { FlowMap } from "./map";
|
|
2
|
+
export { FlowStream } from "./stream";
|
|
3
|
+
export { FlowStreamAsync } from "./streamAsync";
|
|
4
|
+
export { FlowResource } from "./resource";
|
|
5
|
+
export { FlowResourceAsync } from "./resourceAsync";
|
|
6
|
+
export type {
|
|
7
|
+
FlowStreamUpdater,
|
|
8
|
+
FlowStreamDisposer,
|
|
9
|
+
FlowStreamSetter,
|
|
10
|
+
} from "./stream";
|
|
11
|
+
export { FlowArray } from "./array";
|
|
12
|
+
export type { FlowArrayAction } from "./array";
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import { FlowState } from "
|
|
1
|
+
import { FlowState } from "../basic/";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Represents a reactive map of states
|
|
4
|
+
* Represents a reactive map of states extending {@link FlowState} for a Map of key/value pairs.
|
|
5
5
|
*
|
|
6
6
|
* @remarks
|
|
7
7
|
* FlowMap wraps a native Map and provides reactive signals for fine-grained tracking
|
|
8
8
|
* of updates to the map. In addition to the reactive capabilities inherited from FlowState,
|
|
9
|
-
* it exposes two
|
|
9
|
+
* it exposes two reactive signals:
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* • $lastSet: Holds the most recent key-value pair that was set.
|
|
12
|
+
* • $lastDeleted: Holds the most recent key-value pair that was deleted.
|
|
12
13
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* Use {@link FlowMap.setAt} to set a key-value pair and {@link FlowMap.delete} to remove a key.
|
|
14
|
+
* Use {@link FlowMap.setAt} to add or update a key-value pair and {@link FlowMap.delete} to remove a key.
|
|
16
15
|
*
|
|
17
16
|
* @typeparam K - The type of the map keys.
|
|
18
17
|
* @typeparam V - The type of the map values.
|
|
@@ -47,15 +46,16 @@ export class FlowMap<K, V> extends FlowState<Map<K, V>> {
|
|
|
47
46
|
*
|
|
48
47
|
* @param key - The key at which to set the value.
|
|
49
48
|
* @param value - The value to set.
|
|
49
|
+
* @throws If the FlowMap instance is disposed.
|
|
50
50
|
*
|
|
51
51
|
* @remarks
|
|
52
|
-
*
|
|
53
|
-
*
|
|
52
|
+
* Updates the internal map, emits the key-value pair via {@link FlowMap.$lastSet},
|
|
53
|
+
* and notifies all subscribers of the change.
|
|
54
54
|
*
|
|
55
55
|
* @public
|
|
56
56
|
*/
|
|
57
57
|
public setAt(key: K, value: V): void {
|
|
58
|
-
if (this._disposed) throw new Error("
|
|
58
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
59
59
|
this._value.set(key, value);
|
|
60
60
|
this.$lastSet.set({ key, value });
|
|
61
61
|
this._notify();
|
|
@@ -65,16 +65,16 @@ export class FlowMap<K, V> extends FlowState<Map<K, V>> {
|
|
|
65
65
|
* Deletes the value at the specified key from the underlying map.
|
|
66
66
|
*
|
|
67
67
|
* @param key - The key to delete.
|
|
68
|
+
* @throws If the FlowMap instance is disposed.
|
|
68
69
|
*
|
|
69
70
|
* @remarks
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* of the change.
|
|
71
|
+
* Removes the key from the internal map, emits the deleted key and its value via {@link FlowMap.$lastDeleted},
|
|
72
|
+
* and notifies all subscribers of the change.
|
|
73
73
|
*
|
|
74
74
|
* @public
|
|
75
75
|
*/
|
|
76
76
|
public delete(key: K): void {
|
|
77
|
-
if (this._disposed) throw new Error("
|
|
77
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
78
78
|
const value = this._value.get(key);
|
|
79
79
|
this._value.delete(key);
|
|
80
80
|
this.$lastDeleted.set({ key, value });
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { FlowObservable } from "../basic";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Represents a reactive resource that asynchronously fetches its value.
|
|
5
|
+
*
|
|
6
|
+
* @remarks A FlowResource extends FlowObservable and encapsulates an asynchronous fetch function.
|
|
7
|
+
* It is used to retrieve and update its value asynchronously. When the fetch is executed,
|
|
8
|
+
* if the new value differs from the current value, the resource is updated and its subscribers
|
|
9
|
+
* are notified.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export class FlowResource<T> extends FlowObservable<T | undefined> {
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new FlowResource.
|
|
16
|
+
* @param fetch - An asynchronous function that retrieves the resource's value.
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
constructor(fetch: () => Promise<T>) {
|
|
21
|
+
super();
|
|
22
|
+
this._fetch = fetch;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves the current resource value.
|
|
27
|
+
* @returns The current value, or undefined if the resource has not been fetched yet.
|
|
28
|
+
* @throws Error if the resource is disposed.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
public get(): T | undefined {
|
|
32
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
33
|
+
return this._value;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Asynchronously fetches a new value for the resource.
|
|
38
|
+
* @remarks
|
|
39
|
+
* Executes the internal fetch function. If the fetched value differs from the current one,
|
|
40
|
+
* updates the resource's value and notifies subscribers.
|
|
41
|
+
* @returns A Promise that resolves when the fetch operation is complete.
|
|
42
|
+
* @throws Error if the resource is disposed.
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
public async fetch(): Promise<void> {
|
|
46
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
47
|
+
const value = await this._fetch();
|
|
48
|
+
if (value === this._value) return;
|
|
49
|
+
this._value = value;
|
|
50
|
+
this._notify();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* INTERNAL ------------------------------------------------ */
|
|
54
|
+
|
|
55
|
+
private _fetch: () => Promise<T>;
|
|
56
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FlowObservable } from "
|
|
1
|
+
import { FlowObservable } from "../basic/";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Represents a reactive resource that asynchronously fetches its value.
|
|
@@ -13,27 +13,26 @@ import { FlowObservable } from "./observable";
|
|
|
13
13
|
*
|
|
14
14
|
* @public
|
|
15
15
|
*/
|
|
16
|
-
export class
|
|
16
|
+
export class FlowResourceAsync<T> extends FlowObservable<Promise<T>> {
|
|
17
17
|
/**
|
|
18
18
|
* Creates a new FlowResource.
|
|
19
19
|
* @param fetch - An asynchronous function that retrieves the resource's value.
|
|
20
|
-
* @param initial - The initial value of the resource.
|
|
21
20
|
* @public
|
|
22
21
|
*/
|
|
23
|
-
constructor(fetch: () => Promise<T
|
|
22
|
+
constructor(fetch: () => Promise<T>) {
|
|
24
23
|
super();
|
|
25
|
-
this._value = initial;
|
|
26
24
|
this._fetch = fetch;
|
|
27
25
|
}
|
|
28
26
|
|
|
29
27
|
/**
|
|
30
28
|
* Retrieves the current resource value.
|
|
31
|
-
* @returns The current value.
|
|
29
|
+
* @returns The current value, or undefined if the resource has not been fetched yet.
|
|
32
30
|
* @throws Error if the resource is disposed.
|
|
33
31
|
* @public
|
|
34
32
|
*/
|
|
35
|
-
public get(): T {
|
|
36
|
-
if (this._disposed) throw new Error("
|
|
33
|
+
public get(): Promise<T> {
|
|
34
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
35
|
+
if (!this._value) this._value = this._fetch();
|
|
37
36
|
return this._value;
|
|
38
37
|
}
|
|
39
38
|
|
|
@@ -47,18 +46,12 @@ export class FlowResource<T> extends FlowObservable<T> {
|
|
|
47
46
|
* @public
|
|
48
47
|
*/
|
|
49
48
|
public async fetch(): Promise<void> {
|
|
50
|
-
if (this._disposed) throw new Error("
|
|
51
|
-
|
|
52
|
-
if (value === this._value) return;
|
|
53
|
-
this._value = value;
|
|
49
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
50
|
+
this._value = this._fetch();
|
|
54
51
|
this._notify();
|
|
55
52
|
}
|
|
56
53
|
|
|
57
54
|
/* INTERNAL ------------------------------------------------ */
|
|
58
55
|
|
|
59
|
-
/**
|
|
60
|
-
* @internal
|
|
61
|
-
* The asynchronous function used to fetch the resource value.
|
|
62
|
-
*/
|
|
63
56
|
private _fetch: () => Promise<T>;
|
|
64
57
|
}
|