@ersbeth/picoflow 0.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.
Files changed (90) hide show
  1. package/.vscode/settings.json +5 -0
  2. package/README.md +151 -0
  3. package/api/doc/index.md +31 -0
  4. package/api/doc/picoflow.derivation.md +55 -0
  5. package/api/doc/picoflow.effect.md +55 -0
  6. package/api/doc/picoflow.flowderivation._constructor_.md +49 -0
  7. package/api/doc/picoflow.flowderivation.get.md +23 -0
  8. package/api/doc/picoflow.flowderivation.md +86 -0
  9. package/api/doc/picoflow.flowdisposer.md +13 -0
  10. package/api/doc/picoflow.floweffect._constructor_.md +49 -0
  11. package/api/doc/picoflow.floweffect.dispose.md +21 -0
  12. package/api/doc/picoflow.floweffect.disposed.md +13 -0
  13. package/api/doc/picoflow.floweffect.md +131 -0
  14. package/api/doc/picoflow.flowgetter.md +15 -0
  15. package/api/doc/picoflow.flowmap._lastdeleted.md +21 -0
  16. package/api/doc/picoflow.flowmap._lastset.md +21 -0
  17. package/api/doc/picoflow.flowmap.delete.md +57 -0
  18. package/api/doc/picoflow.flowmap.md +135 -0
  19. package/api/doc/picoflow.flowmap.setat.md +73 -0
  20. package/api/doc/picoflow.flowobservable.get.md +19 -0
  21. package/api/doc/picoflow.flowobservable.md +54 -0
  22. package/api/doc/picoflow.flowresource._constructor_.md +65 -0
  23. package/api/doc/picoflow.flowresource.fetch.md +27 -0
  24. package/api/doc/picoflow.flowresource.get.md +23 -0
  25. package/api/doc/picoflow.flowresource.md +100 -0
  26. package/api/doc/picoflow.flowsetter.md +13 -0
  27. package/api/doc/picoflow.flowsignal.dispose.md +25 -0
  28. package/api/doc/picoflow.flowsignal.disposed.md +18 -0
  29. package/api/doc/picoflow.flowsignal.md +111 -0
  30. package/api/doc/picoflow.flowsignal.trigger.md +25 -0
  31. package/api/doc/picoflow.flowstate._constructor_.md +49 -0
  32. package/api/doc/picoflow.flowstate.get.md +23 -0
  33. package/api/doc/picoflow.flowstate.md +100 -0
  34. package/api/doc/picoflow.flowstate.set.md +61 -0
  35. package/api/doc/picoflow.flowstream._constructor_.md +65 -0
  36. package/api/doc/picoflow.flowstream.dispose.md +21 -0
  37. package/api/doc/picoflow.flowstream.get.md +23 -0
  38. package/api/doc/picoflow.flowstream.md +100 -0
  39. package/api/doc/picoflow.flowupdater.md +19 -0
  40. package/api/doc/picoflow.flowwatcher.md +15 -0
  41. package/api/doc/picoflow.map.md +59 -0
  42. package/api/doc/picoflow.md +287 -0
  43. package/api/doc/picoflow.resource.md +71 -0
  44. package/api/doc/picoflow.signal.md +19 -0
  45. package/api/doc/picoflow.state.md +55 -0
  46. package/api/doc/picoflow.stream.md +71 -0
  47. package/api/picoflow.api.md +145 -0
  48. package/api-extractor.json +60 -0
  49. package/biome.json +34 -0
  50. package/dist/picoflow.js +572 -0
  51. package/dist/types/creators.d.ts +70 -0
  52. package/dist/types/creators.d.ts.map +1 -0
  53. package/dist/types/derivation.d.ts +58 -0
  54. package/dist/types/derivation.d.ts.map +1 -0
  55. package/dist/types/effect.d.ts +108 -0
  56. package/dist/types/effect.d.ts.map +1 -0
  57. package/dist/types/index.d.ts +18 -0
  58. package/dist/types/index.d.ts.map +1 -0
  59. package/dist/types/map.d.ts +75 -0
  60. package/dist/types/map.d.ts.map +1 -0
  61. package/dist/types/observable.d.ts +40 -0
  62. package/dist/types/observable.d.ts.map +1 -0
  63. package/dist/types/resource.d.ts +46 -0
  64. package/dist/types/resource.d.ts.map +1 -0
  65. package/dist/types/signal.d.ts +111 -0
  66. package/dist/types/signal.d.ts.map +1 -0
  67. package/dist/types/state.d.ts +39 -0
  68. package/dist/types/state.d.ts.map +1 -0
  69. package/dist/types/stream.d.ts +71 -0
  70. package/dist/types/stream.d.ts.map +1 -0
  71. package/package.json +40 -0
  72. package/src/creators.ts +101 -0
  73. package/src/derivation.ts +96 -0
  74. package/src/effect.ts +152 -0
  75. package/src/index.ts +30 -0
  76. package/src/map.ts +83 -0
  77. package/src/observable.ts +50 -0
  78. package/src/resource.ts +64 -0
  79. package/src/signal.ts +166 -0
  80. package/src/state.ts +52 -0
  81. package/src/stream.ts +99 -0
  82. package/test/derivation.test.ts +422 -0
  83. package/test/map.test.ts +106 -0
  84. package/test/resource.test.ts +127 -0
  85. package/test/signal.test.ts +59 -0
  86. package/test/state.test.ts +89 -0
  87. package/test/stream.test.ts +171 -0
  88. package/tsconfig.json +22 -0
  89. package/vite.config.ts +26 -0
  90. package/vitest.config.ts +11 -0
@@ -0,0 +1,58 @@
1
+ import { FlowGetter, FlowObservable } from './observable';
2
+ import { FlowWatcher } from './signal';
3
+ /**
4
+ * Represents a reactive derivation whose value is computed based on other reactive signals.
5
+ * @remarks
6
+ * A FlowDerivation automatically tracks its dependencies and recomputes its value when needed.
7
+ * @typeparam T - The type of the computed value.
8
+ * @public
9
+ */
10
+ export declare class FlowDerivation<T> extends FlowObservable<T> {
11
+ /**
12
+ * Creates a new FlowDerivation.
13
+ * @param compute - A function that computes the derived value. It is provided with a getter
14
+ * and a watcher function to access observables and signals dependencies.
15
+ * @public
16
+ */
17
+ constructor(compute: (get: FlowGetter, watch: FlowWatcher) => T);
18
+ /**
19
+ * Gets the current derived value.
20
+ * @returns The current computed value.
21
+ * @remarks
22
+ * This method ensures that the derivation is up-to-date before returning the value.
23
+ * @public
24
+ */
25
+ get(): T;
26
+ /** @internal */
27
+ private _initialized;
28
+ /** @internal */
29
+ private _dirty;
30
+ /** @internal */
31
+ private _trackedGet;
32
+ /** @internal */
33
+ private _trackedWatch;
34
+ /** @internal */
35
+ private _untrackedGet;
36
+ /** @internal */
37
+ private _untrackedWatch;
38
+ /** @internal */
39
+ private _trackedExec;
40
+ /** @internal */
41
+ private _untrackedExec;
42
+ /**
43
+ * @internal
44
+ * Executes the compute function if necessary to update the derived value.
45
+ */
46
+ _exec(): void;
47
+ /**
48
+ * @internal
49
+ * Marks the derivation as dirty and notifies downstream dependencies.
50
+ */
51
+ _notify(): void;
52
+ /**
53
+ * @internal
54
+ * Ensures that the derivation is up-to-date when it is watched.
55
+ */
56
+ _watch(): void;
57
+ }
58
+ //# sourceMappingURL=derivation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"derivation.d.ts","sourceRoot":"","sources":["../../src/derivation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C;;;;;;GAMG;AACH,qBAAa,cAAc,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;IAEpD;;;;;OAKG;gBACS,OAAO,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,KAAK,CAAC;IAM/D;;;;;;OAMG;IACI,GAAG,IAAI,CAAC;IAOf,gBAAgB;IAChB,OAAO,CAAC,YAAY,CAAS;IAE7B,gBAAgB;IAChB,OAAO,CAAC,MAAM,CAAQ;IAEtB,gBAAgB;IAChB,OAAO,CAAC,WAAW,CAAyD;IAE5E,gBAAgB;IAChB,OAAO,CAAC,aAAa,CAAoD;IAEzE,gBAAgB;IAChB,OAAO,CAAC,aAAa,CAAgD;IAErE,gBAAgB;IAChB,OAAO,CAAC,eAAe,CAA4C;IAEnE,gBAAgB;IAChB,OAAO,CAAC,YAAY,CAAU;IAE9B,gBAAgB;IAChB,OAAO,CAAC,cAAc,CAAU;IAEhC;;;OAGG;IACH,KAAK,IAAI,IAAI;IAab;;;OAGG;IACM,OAAO,IAAI,IAAI;IAKxB;;;OAGG;IACM,MAAM,IAAI,IAAI;CAG1B"}
@@ -0,0 +1,108 @@
1
+ import { FlowGetter } from './observable';
2
+ import { FlowSignal, FlowWatcher } from './signal';
3
+ /**
4
+ * Represents a reactive effect that executes a side‐effect function
5
+ * based on its tracked dependencies.
6
+ *
7
+ * @remarks
8
+ * A FlowEffect runs an apply function to perform side effects. The apply function
9
+ * is executed in two modes:
10
+ * Initially, in a tracked mode to register dependencies.
11
+ * Subsequently, in an untracked mode to only re-execute the effect .
12
+ *
13
+ * @public
14
+ */
15
+ export declare class FlowEffect {
16
+ /**
17
+ * Creates a new FlowEffect.
18
+ *
19
+ * @param apply - A function that performs the side effect. It receives a getter and a watcher
20
+ * function to access and register dependencies on reactive observables and signals.
21
+ *
22
+ * @public
23
+ */
24
+ constructor(apply: (get: FlowGetter, watch: FlowWatcher) => void);
25
+ /**
26
+ * Disposes the effect, unregistering all its dependencies.
27
+ *
28
+ * @remarks
29
+ * After disposal, the effect should no longer be used. Calling this method on an already
30
+ * disposed effect will throw an error.
31
+ *
32
+ * @public
33
+ */
34
+ dispose(): void;
35
+ /**
36
+ * Indicates whether this effect has been disposed.
37
+ *
38
+ * @returns A boolean value indicating if the effect is disposed.
39
+ *
40
+ * @public
41
+ */
42
+ get disposed(): boolean;
43
+ /**
44
+ * @internal
45
+ */
46
+ private _disposed;
47
+ /**
48
+ * @internal
49
+ */
50
+ private _initialized;
51
+ /**
52
+ * @internal
53
+ */
54
+ private _dependencies;
55
+ /**
56
+ * @internal
57
+ * A tracked getter that registers a dependency when accessing an observable.
58
+ */
59
+ private _trackedGet;
60
+ /**
61
+ * @internal
62
+ * A tracked watcher that registers a dependency when watching a signal.
63
+ */
64
+ private _trackedWatch;
65
+ /**
66
+ * @internal
67
+ * An untracked getter that simply retrieves the current value from an observable.
68
+ */
69
+ private _untrackedGet;
70
+ /**
71
+ * @internal
72
+ * An untracked watcher that calls the default watch on a signal.
73
+ */
74
+ private _untrackedWatch;
75
+ /**
76
+ * @internal
77
+ * Execution function used during initialization (tracked mode).
78
+ */
79
+ private _trackedExec;
80
+ /**
81
+ * @internal
82
+ * Execution function used after initialization (untracked mode).
83
+ */
84
+ private _untrackedExec;
85
+ /**
86
+ * @internal
87
+ * Executes the effect. If the effect has not been initialized, it runs in tracked mode;
88
+ * otherwise, it runs in untracked mode.
89
+ *
90
+ * @throws Error if the effect has been disposed.
91
+ */
92
+ _exec(): void;
93
+ /**
94
+ * @internal
95
+ * Registers a dependency on the given signal.
96
+ *
97
+ * @param dependency - The FlowSignal to register as a dependency.
98
+ */
99
+ _registerDependency(dependency: FlowSignal): void;
100
+ /**
101
+ * @internal
102
+ * Unregisters the given dependency.
103
+ *
104
+ * @param dependency - The FlowSignal to unregister.
105
+ */
106
+ _unregisterDependency(dependency: FlowSignal): void;
107
+ }
108
+ //# sourceMappingURL=effect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effect.d.ts","sourceRoot":"","sources":["../../src/effect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAExD;;;;;;;;;;;GAWG;AACH,qBAAa,UAAU;IAGnB;;;;;;;OAOG;gBACS,KAAK,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,KAAK,IAAI;IAMhE;;;;;;;;OAQG;IACI,OAAO,IAAI,IAAI;IAQtB;;;;;;OAMG;IACH,IAAW,QAAQ,IAAI,OAAO,CAE7B;IAID;;OAEG;IACH,OAAO,CAAC,SAAS,CAAS;IAE1B;;OAEG;IACH,OAAO,CAAC,YAAY,CAAS;IAE7B;;OAEG;IACH,OAAO,CAAC,aAAa,CAAyB;IAE9C;;;OAGG;IACH,OAAO,CAAC,WAAW,CAAyD;IAE5E;;;OAGG;IACH,OAAO,CAAC,aAAa,CAAoD;IAEzE;;;OAGG;IACH,OAAO,CAAC,aAAa,CAAgD;IAErE;;;OAGG;IACH,OAAO,CAAC,eAAe,CAA4C;IAEnE;;;OAGG;IACH,OAAO,CAAC,YAAY,CAAa;IAEjC;;;OAGG;IACH,OAAO,CAAC,cAAc,CAAa;IAEnC;;;;;;OAMG;IACH,KAAK,IAAI,IAAI;IASb;;;;;OAKG;IACH,mBAAmB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAKjD;;;;;OAKG;IACH,qBAAqB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;CAItD"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * PicoFlow is a lightweight reactive dataflow library that provides a set of
5
+ * reactive primitives such as signals, state, resources, streams, derivations,
6
+ * effects, and reactive maps.
7
+ *
8
+ */
9
+ export { signal, state, resource, stream, derivation, effect, map } from './creators';
10
+ export type { FlowDerivation } from './derivation';
11
+ export type { FlowEffect } from './effect';
12
+ export type { FlowGetter, FlowObservable } from './observable';
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';
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACtF,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC/D,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACxD,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzC,YAAY,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACrC,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,75 @@
1
+ import { FlowState } from './state';
2
+ /**
3
+ * Represents a reactive map of states that extends {@link FlowState} for a Map of key/value pairs.
4
+ *
5
+ * @remarks
6
+ * FlowMap wraps a native Map and provides reactive signals for fine-grained tracking
7
+ * of updates to the map. In addition to the reactive capabilities inherited from FlowState,
8
+ * it exposes two public signals:
9
+ *
10
+ * **$lastSet**: A FlowState that holds the most recent key-value pair that was set.
11
+ *
12
+ * **$lastDeleted**: A FlowState that holds the most recent key-value pair that was deleted.
13
+ *
14
+ * Use {@link FlowMap.setAt} to set a key-value pair and {@link FlowMap.delete} to remove a key.
15
+ *
16
+ * @typeparam K - The type of the map keys.
17
+ * @typeparam V - The type of the map values.
18
+ *
19
+ * @public
20
+ */
21
+ export declare class FlowMap<K, V> extends FlowState<Map<K, V>> {
22
+ /**
23
+ * A reactive state that holds the most recent key and value that were set.
24
+ *
25
+ * @remarks
26
+ * When a key is set via {@link FlowMap.setAt}, this state is updated with
27
+ * the corresponding key and value.
28
+ *
29
+ * @public
30
+ */
31
+ $lastSet: FlowState<{
32
+ key?: K;
33
+ value?: V;
34
+ }>;
35
+ /**
36
+ * A reactive state that holds the most recent key and value that were deleted.
37
+ *
38
+ * @remarks
39
+ * When a key is deleted via {@link FlowMap.delete}, this state is updated with
40
+ * the corresponding key and its last known value.
41
+ *
42
+ * @public
43
+ */
44
+ $lastDeleted: FlowState<{
45
+ key?: K;
46
+ value?: V;
47
+ }>;
48
+ /**
49
+ * Sets a value at the specified key in the underlying map.
50
+ *
51
+ * @param key - The key at which to set the value.
52
+ * @param value - The value to set.
53
+ *
54
+ * @remarks
55
+ * This method updates the internal map with the given key and value, emits the new
56
+ * key-value pair via {@link FlowMap.$lastSet}, and notifies subscribers of the change.
57
+ *
58
+ * @public
59
+ */
60
+ setAt(key: K, value: V): void;
61
+ /**
62
+ * Deletes the value at the specified key from the underlying map.
63
+ *
64
+ * @param key - The key to delete.
65
+ *
66
+ * @remarks
67
+ * This method removes the key from the internal map, emits the deleted key and its
68
+ * corresponding value via {@link FlowMap.$lastDeleted}, and notifies subscribers
69
+ * of the change.
70
+ *
71
+ * @public
72
+ */
73
+ delete(key: K): void;
74
+ }
75
+ //# sourceMappingURL=map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,OAAO,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAEnD;;;;;;;;OAQG;IACI,QAAQ,EAAE,SAAS,CAAC;QAAE,GAAG,CAAC,EAAE,CAAC,CAAC;QAAC,KAAK,CAAC,EAAE,CAAC,CAAA;KAAE,CAAC,CAAqB;IAEvE;;;;;;;;OAQG;IACI,YAAY,EAAE,SAAS,CAAC;QAAE,GAAG,CAAC,EAAE,CAAC,CAAC;QAAC,KAAK,CAAC,EAAE,CAAC,CAAA;KAAE,CAAC,CAAqB;IAE3E;;;;;;;;;;;OAWG;IACI,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAOpC;;;;;;;;;;;OAWG;IACI,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI;CAO9B"}
@@ -0,0 +1,40 @@
1
+ import { FlowEffect } from './effect';
2
+ import { FlowSignal } from './signal';
3
+ /**
4
+ * A function for retrieving the current value from a FlowObservable.
5
+ * @typeparam T - The type of the value held by the observable.
6
+ * @param atom - The FlowObservable from which to get the value.
7
+ * @returns The current value of the observable.
8
+ * @public
9
+ */
10
+ export type FlowGetter = <T>(observable: FlowObservable<T>) => T;
11
+ /**
12
+ * Represents a reactive observable that carries a value.
13
+ * @typeparam T - The type of the value held by the observable.
14
+ * @remarks
15
+ * A FlowObservable extends the basic FlowSignal to store a value. Subclasses must
16
+ * implement the abstract {@link FlowObservable.get} method to return the current value.
17
+ * @public
18
+ */
19
+ export declare abstract class FlowObservable<T> extends FlowSignal {
20
+ /**
21
+ * Retrieves the current value of the observable.
22
+ * @returns The current value.
23
+ * @public
24
+ */
25
+ abstract get(): T;
26
+ /**
27
+ * @internal
28
+ * Internal storage for the observable's value.
29
+ */
30
+ protected _value: T;
31
+ /**
32
+ * @internal
33
+ * Retrieves the current value from the observable and registers a dependency
34
+ * from the provided listener.
35
+ * @param listener - The FlowObservable or FlowEffect that is accessing this observable.
36
+ * @returns The current value, as returned by {@link FlowObservable.get}.
37
+ */
38
+ _getFrom(listener: FlowObservable<unknown> | FlowEffect): T;
39
+ }
40
+ //# sourceMappingURL=observable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observable.d.ts","sourceRoot":"","sources":["../../src/observable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAEjE;;;;;;;GAOG;AACH,8BAAsB,cAAc,CAAC,CAAC,CAAE,SAAQ,UAAU;IAGtD;;;;OAIG;IACH,QAAQ,CAAC,GAAG,IAAI,CAAC;IAIjB;;;OAGG;IACH,SAAS,CAAC,MAAM,EAAG,CAAC,CAAC;IAErB;;;;;;OAMG;IACH,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG,UAAU,GAAG,CAAC;CAI9D"}
@@ -0,0 +1,46 @@
1
+ import { FlowObservable } from './observable';
2
+ /**
3
+ * Represents a reactive resource that asynchronously fetches its value.
4
+ *
5
+ * @remarks
6
+ * 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
+ * @typeparam T - The type of the resource value.
12
+ *
13
+ * @public
14
+ */
15
+ export declare class FlowResource<T> extends FlowObservable<T> {
16
+ /**
17
+ * Creates a new FlowResource.
18
+ * @param fetch - An asynchronous function that retrieves the resource's value.
19
+ * @param initial - The initial value of the resource.
20
+ * @public
21
+ */
22
+ constructor(fetch: () => Promise<T>, initial: T);
23
+ /**
24
+ * Retrieves the current resource value.
25
+ * @returns The current value.
26
+ * @throws Error if the resource is disposed.
27
+ * @public
28
+ */
29
+ get(): T;
30
+ /**
31
+ * Asynchronously fetches a new value for the resource.
32
+ * @remarks
33
+ * Executes the internal fetch function. If the fetched value differs from the current one,
34
+ * updates the resource's value and notifies subscribers.
35
+ * @returns A Promise that resolves when the fetch operation is complete.
36
+ * @throws Error if the resource is disposed.
37
+ * @public
38
+ */
39
+ fetch(): Promise<void>;
40
+ /**
41
+ * @internal
42
+ * The asynchronous function used to fetch the resource value.
43
+ */
44
+ private _fetch;
45
+ }
46
+ //# sourceMappingURL=resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C;;;;;;;;;;;;GAYG;AACH,qBAAa,YAAY,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;IAElD;;;;;OAKG;gBACS,KAAK,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC;IAM/C;;;;;OAKG;IACI,GAAG,IAAI,CAAC;IAKf;;;;;;;;OAQG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAUnC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAmB;CACpC"}
@@ -0,0 +1,111 @@
1
+ import { FlowEffect } from './effect';
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
+ * @remarks
11
+ * A FlowSignal allows you to trigger notifications via {@link FlowSignal.trigger}
12
+ * and to dispose the signal and all its registered dependencies, listeners, and effects via {@link FlowSignal.dispose}.
13
+ * @public
14
+ */
15
+ export declare class FlowSignal {
16
+ /**
17
+ * Triggers the signal.
18
+ * @remarks
19
+ * This method notifies all registered listeners and causes associated effects to execute.
20
+ * @throws Error if the signal is disposed.
21
+ * @public
22
+ */
23
+ trigger(): void;
24
+ /**
25
+ * Disposes the signal.
26
+ * @remarks
27
+ * Disposing a signal will dispose all registered effects and listeners,
28
+ * and unregister all dependencies. Once disposed, any further calls to the signal
29
+ * will throw an error.
30
+ * @throws Error if the signal is already disposed.
31
+ * @public
32
+ */
33
+ dispose(): void;
34
+ /**
35
+ * Indicates whether the signal has been disposed.
36
+ * @remarks
37
+ * Once disposed, the signal should not be used.
38
+ * @public
39
+ */
40
+ get disposed(): boolean;
41
+ /**
42
+ * @internal
43
+ */
44
+ protected _disposed: boolean;
45
+ /**
46
+ * @internal
47
+ */
48
+ protected _dependencies: Set<FlowSignal>;
49
+ /**
50
+ * @internal
51
+ */
52
+ protected _listeners: Set<FlowSignal>;
53
+ /**
54
+ * @internal
55
+ */
56
+ protected _effects: Set<FlowEffect>;
57
+ /**
58
+ * @internal
59
+ * Internal method to watch the signal.
60
+ * @throws Error if the signal is disposed.
61
+ */
62
+ _watch(): void;
63
+ /**
64
+ * @internal
65
+ * Notifies all listeners and executes all registered effects.
66
+ */
67
+ _notify(): void;
68
+ /**
69
+ * @internal
70
+ * Registers a dependency from the given listener and watches the signal.
71
+ * @param listener - A FlowSignal or FlowEffect that will depend on this signal.
72
+ */
73
+ _watchFrom(listener: FlowSignal | FlowEffect): void;
74
+ /**
75
+ * @internal
76
+ * Registers a dependency with the given FlowSignal.
77
+ * @param dependency - The FlowSignal to register as a dependency.
78
+ */
79
+ _registerDependency(dependency: FlowSignal): void;
80
+ /**
81
+ * @internal
82
+ * Unregisters the given dependency.
83
+ * @param dependency - The FlowSignal to unregister.
84
+ */
85
+ _unregisterDependency(dependency: FlowSignal): void;
86
+ /**
87
+ * @internal
88
+ * Registers a listener (another FlowSignal) to this signal.
89
+ * @param signal - The FlowSignal to register as a listener.
90
+ */
91
+ _registerListener(signal: FlowSignal): void;
92
+ /**
93
+ * @internal
94
+ * Unregisters the given listener.
95
+ * @param signal - The FlowSignal to unregister.
96
+ */
97
+ _unregisterListener(signal: FlowSignal): void;
98
+ /**
99
+ * @internal
100
+ * Registers a FlowEffect to this signal.
101
+ * @param effect - The FlowEffect to register.
102
+ */
103
+ _registerEffect(effect: FlowEffect): void;
104
+ /**
105
+ * @internal
106
+ * Unregisters the given FlowEffect.
107
+ * @param effect - The FlowEffect to unregister.
108
+ */
109
+ _unregisterEffect(effect: FlowEffect): void;
110
+ }
111
+ //# sourceMappingURL=signal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signal.d.ts","sourceRoot":"","sources":["../../src/signal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;AAEvD;;;;;;GAMG;AACH,qBAAa,UAAU;IAGnB;;;;;;OAMG;IACI,OAAO,IAAI,IAAI;IAKtB;;;;;;;;OAQG;IACI,OAAO,IAAI,IAAI;IAUtB;;;;;OAKG;IACH,IAAW,QAAQ,IAAI,OAAO,CAE7B;IAID;;OAEG;IACH,SAAS,CAAC,SAAS,UAAS;IAE5B;;OAEG;IACH,SAAS,CAAC,aAAa,kBAAyB;IAEhD;;OAEG;IACH,SAAS,CAAC,UAAU,kBAAyB;IAE7C;;OAEG;IACH,SAAS,CAAC,QAAQ,kBAAyB;IAE3C;;;;OAIG;IACH,MAAM,IAAI,IAAI;IAId;;;OAGG;IACH,OAAO,IAAI,IAAI;IAKf;;;;OAIG;IACH,UAAU,CAAC,QAAQ,EAAE,UAAU,GAAG,UAAU,GAAG,IAAI;IAKnD;;;;OAIG;IACH,mBAAmB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAKjD;;;;OAIG;IACH,qBAAqB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAKnD;;;;OAIG;IACH,iBAAiB,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAI3C;;;;OAIG;IACH,mBAAmB,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAI7C;;;;OAIG;IACH,eAAe,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAIzC;;;;OAIG;IACH,iBAAiB,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;CAG9C"}
@@ -0,0 +1,39 @@
1
+ import { FlowObservable } from './observable';
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 FlowObservable to provide a simple reactive state primitive.
9
+ * Use the {@link FlowState.get} method to read the current state and {@link FlowState.set} to update it.
10
+ * When the state is updated, subscribers are notified automatically.
11
+ *
12
+ * @public
13
+ */
14
+ export declare class FlowState<T> extends FlowObservable<T> {
15
+ /**
16
+ * Creates a new FlowState with the given initial value.
17
+ * @param value - The initial value for the state.
18
+ * @public
19
+ */
20
+ constructor(value: T);
21
+ /**
22
+ * Retrieves the current state value.
23
+ * @returns The current value of the state.
24
+ * @throws Error if the state has been disposed.
25
+ * @public
26
+ */
27
+ get(): T;
28
+ /**
29
+ * Updates the state with a new value.
30
+ * @param value - The new value to set.
31
+ * @remarks
32
+ * If the new value is identical to the current value, no update or notification occurs.
33
+ * Otherwise, the state is updated and all subscribers are notified.
34
+ * @throws Error if the state has been disposed.
35
+ * @public
36
+ */
37
+ set(value: T): void;
38
+ }
39
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C;;;;;;;;;;;GAWG;AACH,qBAAa,SAAS,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;IAE/C;;;;OAIG;gBACS,KAAK,EAAE,CAAC;IAKpB;;;;;OAKG;IACH,GAAG,IAAI,CAAC;IAKR;;;;;;;;OAQG;IACH,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;CAMtB"}
@@ -0,0 +1,71 @@
1
+ import { FlowObservable } from './observable';
2
+ /**
3
+ * A function that sets a new value.
4
+ * @typeparam T - The type of the value.
5
+ * @public
6
+ */
7
+ export type FlowSetter<T> = (value: T) => void;
8
+ /**
9
+ * A function that disposes of a resource.
10
+ * @public
11
+ */
12
+ export type FlowDisposer = () => void;
13
+ /**
14
+ * A function that performs updates on a stream.
15
+ * @remarks
16
+ * The updater receives a setter function that can be used to update the stream's value.
17
+ * It should return a disposer function to clean up any resources or subscriptions.
18
+ * @typeparam T - The type of the stream value.
19
+ * @public
20
+ */
21
+ export type FlowUpdater<T> = (set: FlowSetter<T>) => FlowDisposer;
22
+ /**
23
+ * Represents a reactive stream that updates its value based on an updater function.
24
+ *
25
+ * @remarks
26
+ * A FlowStream extends FlowObservable and encapsulates a mechanism for updating its value
27
+ * via an external updater function. The updater is invoked during construction with a setter,
28
+ * and it returns a disposer to be called when the stream is disposed.
29
+ *
30
+ * @typeparam T - The type of the stream's value.
31
+ *
32
+ * @public
33
+ */
34
+ export declare class FlowStream<T> extends FlowObservable<T> {
35
+ /**
36
+ * Creates a new FlowStream.
37
+ * @param updater - A function that receives a setter to update the stream's value.
38
+ * It should return a disposer function that will be called upon disposal.
39
+ * @param initial - The initial value of the stream.
40
+ * @public
41
+ */
42
+ constructor(updater: FlowUpdater<T>, initial: T);
43
+ /**
44
+ * Retrieves the current value of the stream.
45
+ * @returns The current value.
46
+ * @throws Error if the stream is disposed.
47
+ * @public
48
+ */
49
+ get(): T;
50
+ /**
51
+ * Disposes the stream, releasing all resources.
52
+ * @remarks
53
+ * In addition to disposing the underlying observable, this method calls the disposer
54
+ * returned by the updater.
55
+ * @public
56
+ */
57
+ dispose(): void;
58
+ /**
59
+ * @internal
60
+ * The disposer function returned by the updater.
61
+ */
62
+ private _disposer;
63
+ /**
64
+ * @internal
65
+ * Updates the stream's value and notifies subscribers if the value changes.
66
+ * @param value - The new value to set.
67
+ * @internal
68
+ */
69
+ private _set;
70
+ }
71
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C;;;;GAIG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AAE/C;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC;AAEtC;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,YAAY,CAAC;AAElE;;;;;;;;;;;GAWG;AACH,qBAAa,UAAU,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;IAIhD;;;;;;OAMG;gBACS,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC;IAQ/C;;;;;OAKG;IACI,GAAG,IAAI,CAAC;IAKf;;;;;;OAMG;IACa,OAAO,IAAI,IAAI;IAO/B;;;OAGG;IACH,OAAO,CAAC,SAAS,CAAe;IAEhC;;;;;OAKG;IACH,OAAO,CAAC,IAAI;CAMf"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@ersbeth/picoflow",
3
+ "version": "0.0.1",
4
+ "description": "Minimal Dataflow librairy for TypeScript",
5
+ "type": "module",
6
+ "exports": {
7
+ "types": "./dist/types/index.d.ts",
8
+ "default": "./dist/picoflow.js"
9
+ },
10
+ "imports": {
11
+ "#package": "./src/index.ts"
12
+ },
13
+ "scripts": {
14
+ "build": "npx vite build --config vite.config.ts",
15
+ "format": "npx biome check --fix",
16
+ "test": "npx vitest",
17
+ "lint": "npx biome ci",
18
+ "api:extract": "api-extractor run --local",
19
+ "api:generate": "api-documenter markdown -i ./api/temp -o ./api/doc",
20
+ "api:clean": "rm ./api/temp/*",
21
+ "api": "npm run api:extract && npm run api:generate && npm run api:clean"
22
+ },
23
+ "devDependencies": {
24
+ "@biomejs/biome": "^1.9.4",
25
+ "@vitest/coverage-v8": "^3.0.9",
26
+ "vite": "^6.2.3",
27
+ "vite-plugin-dts": "^4.5.3",
28
+ "vitest": "^3.0.9"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+ssh://git@gitlab.com/ersbeth-web/picoflow.git"
33
+ },
34
+ "author": "Elisabeth Rousset",
35
+ "license": "MIT",
36
+ "bugs": {
37
+ "url": "https://gitlab.com/ersbeth-web/picoflow/issues"
38
+ },
39
+ "homepage": "https://gitlab.com/ersbeth-web/picoflow#readme"
40
+ }