@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.
Files changed (169) hide show
  1. package/api/doc/index.md +1 -1
  2. package/api/doc/picoflow.array.md +55 -0
  3. package/api/doc/picoflow.constant.md +55 -0
  4. package/api/doc/picoflow.derivation.md +1 -1
  5. package/api/doc/picoflow.effect.md +1 -1
  6. package/api/doc/picoflow.flowarray._constructor_.md +49 -0
  7. package/api/doc/picoflow.flowarray._lastaction.md +13 -0
  8. package/api/doc/picoflow.flowarray.clear.md +17 -0
  9. package/api/doc/picoflow.flowarray.dispose.md +55 -0
  10. package/api/doc/picoflow.flowarray.get.md +19 -0
  11. package/api/doc/picoflow.flowarray.length.md +13 -0
  12. package/api/doc/picoflow.flowarray.md +273 -0
  13. package/api/doc/picoflow.flowarray.pop.md +17 -0
  14. package/api/doc/picoflow.flowarray.push.md +53 -0
  15. package/api/doc/picoflow.flowarray.set.md +53 -0
  16. package/api/doc/picoflow.flowarray.setitem.md +69 -0
  17. package/api/doc/picoflow.flowarray.shift.md +17 -0
  18. package/api/doc/picoflow.flowarray.splice.md +85 -0
  19. package/api/doc/picoflow.flowarray.unshift.md +53 -0
  20. package/api/doc/picoflow.flowarrayaction.md +37 -0
  21. package/api/doc/picoflow.flowconstant._constructor_.md +49 -0
  22. package/api/doc/picoflow.flowconstant.get.md +25 -0
  23. package/api/doc/picoflow.flowconstant.md +88 -0
  24. package/api/doc/picoflow.flowderivation._constructor_.md +2 -2
  25. package/api/doc/picoflow.flowderivation.get.md +2 -2
  26. package/api/doc/picoflow.flowderivation.md +2 -2
  27. package/api/doc/picoflow.flowdisposable.dispose.md +55 -0
  28. package/api/doc/picoflow.flowdisposable.md +43 -0
  29. package/api/doc/picoflow.floweffect._constructor_.md +7 -2
  30. package/api/doc/picoflow.floweffect.dispose.md +3 -3
  31. package/api/doc/picoflow.floweffect.disposed.md +1 -1
  32. package/api/doc/picoflow.floweffect.md +4 -4
  33. package/api/doc/picoflow.flowgetter.md +2 -2
  34. package/api/doc/picoflow.flowmap._lastdeleted.md +1 -1
  35. package/api/doc/picoflow.flowmap._lastset.md +1 -1
  36. package/api/doc/picoflow.flowmap.delete.md +6 -2
  37. package/api/doc/picoflow.flowmap.md +5 -7
  38. package/api/doc/picoflow.flowmap.setat.md +6 -2
  39. package/api/doc/picoflow.flowobservable.get.md +3 -3
  40. package/api/doc/picoflow.flowobservable.md +18 -4
  41. package/api/doc/picoflow.flowobservable.subscribe.md +55 -0
  42. package/api/doc/picoflow.flowresource._constructor_.md +2 -18
  43. package/api/doc/picoflow.flowresource.fetch.md +1 -1
  44. package/api/doc/picoflow.flowresource.get.md +4 -4
  45. package/api/doc/picoflow.flowresource.md +4 -4
  46. package/api/doc/picoflow.flowresourceasync._constructor_.md +49 -0
  47. package/api/doc/picoflow.flowresourceasync.fetch.md +27 -0
  48. package/api/doc/picoflow.flowresourceasync.get.md +23 -0
  49. package/api/doc/picoflow.flowresourceasync.md +100 -0
  50. package/api/doc/picoflow.flowsignal.dispose.md +42 -8
  51. package/api/doc/picoflow.flowsignal.disposed.md +2 -2
  52. package/api/doc/picoflow.flowsignal.md +8 -7
  53. package/api/doc/picoflow.flowsignal.trigger.md +3 -7
  54. package/api/doc/picoflow.flowstate.md +4 -52
  55. package/api/doc/picoflow.flowstate.set.md +5 -5
  56. package/api/doc/picoflow.flowstream._constructor_.md +3 -19
  57. package/api/doc/picoflow.flowstream.dispose.md +1 -1
  58. package/api/doc/picoflow.flowstream.get.md +4 -4
  59. package/api/doc/picoflow.flowstream.md +5 -5
  60. package/api/doc/picoflow.flowstreamasync._constructor_.md +54 -0
  61. package/api/doc/picoflow.flowstreamasync.dispose.md +21 -0
  62. package/api/doc/picoflow.flowstreamasync.get.md +23 -0
  63. package/api/doc/picoflow.flowstreamasync.md +100 -0
  64. package/api/doc/picoflow.flowstreamdisposer.md +13 -0
  65. package/api/doc/picoflow.flowstreamsetter.md +13 -0
  66. package/api/doc/picoflow.flowstreamupdater.md +19 -0
  67. package/api/doc/picoflow.flowwatcher.md +1 -1
  68. package/api/doc/picoflow.isdisposable.md +55 -0
  69. package/api/doc/picoflow.map.md +1 -1
  70. package/api/doc/picoflow.md +149 -13
  71. package/api/doc/picoflow.resource.md +2 -18
  72. package/api/doc/picoflow.resourceasync.md +55 -0
  73. package/api/doc/picoflow.signal.md +1 -1
  74. package/api/doc/picoflow.state.md +3 -3
  75. package/api/doc/picoflow.stream.md +2 -18
  76. package/api/doc/picoflow.streamasync.md +55 -0
  77. package/api/picoflow.public.api.md +192 -0
  78. package/api-extractor.json +2 -1
  79. package/dist/picoflow.js +513 -305
  80. package/dist/types/advanced/array.d.ts +116 -0
  81. package/dist/types/advanced/array.d.ts.map +1 -0
  82. package/dist/types/advanced/index.d.ts +9 -0
  83. package/dist/types/advanced/index.d.ts.map +1 -0
  84. package/dist/types/{map.d.ts → advanced/map.d.ts} +12 -12
  85. package/dist/types/advanced/map.d.ts.map +1 -0
  86. package/dist/types/advanced/resource.d.ts +39 -0
  87. package/dist/types/advanced/resource.d.ts.map +1 -0
  88. package/dist/types/{resource.d.ts → advanced/resourceAsync.d.ts} +6 -11
  89. package/dist/types/advanced/resourceAsync.d.ts.map +1 -0
  90. package/dist/types/advanced/stream.d.ts +59 -0
  91. package/dist/types/advanced/stream.d.ts.map +1 -0
  92. package/dist/types/advanced/streamAsync.d.ts +43 -0
  93. package/dist/types/advanced/streamAsync.d.ts.map +1 -0
  94. package/dist/types/basic/constant.d.ts +32 -0
  95. package/dist/types/basic/constant.d.ts.map +1 -0
  96. package/dist/types/basic/derivation.d.ts +40 -0
  97. package/dist/types/basic/derivation.d.ts.map +1 -0
  98. package/dist/types/basic/disposable.d.ts +23 -0
  99. package/dist/types/basic/disposable.d.ts.map +1 -0
  100. package/dist/types/basic/effect.d.ts +56 -0
  101. package/dist/types/basic/effect.d.ts.map +1 -0
  102. package/dist/types/basic/index.d.ts +11 -0
  103. package/dist/types/basic/index.d.ts.map +1 -0
  104. package/dist/types/basic/observable.d.ts +34 -0
  105. package/dist/types/basic/observable.d.ts.map +1 -0
  106. package/dist/types/basic/signal.d.ts +40 -0
  107. package/dist/types/basic/signal.d.ts.map +1 -0
  108. package/dist/types/basic/state.d.ts +26 -0
  109. package/dist/types/basic/state.d.ts.map +1 -0
  110. package/dist/types/creators.d.ts +38 -13
  111. package/dist/types/creators.d.ts.map +1 -1
  112. package/dist/types/index.d.ts +4 -9
  113. package/dist/types/index.d.ts.map +1 -1
  114. package/package.json +1 -1
  115. package/src/advanced/array.ts +224 -0
  116. package/src/advanced/index.ts +12 -0
  117. package/src/{map.ts → advanced/map.ts} +14 -14
  118. package/src/advanced/resource.ts +56 -0
  119. package/src/{resource.ts → advanced/resourceAsync.ts} +9 -16
  120. package/src/advanced/stream.ts +87 -0
  121. package/src/advanced/streamAsync.ts +82 -0
  122. package/src/basic/constant.ts +64 -0
  123. package/src/basic/derivation.ts +86 -0
  124. package/src/basic/disposable.ts +27 -0
  125. package/src/basic/effect.ts +96 -0
  126. package/src/basic/index.ts +10 -0
  127. package/src/basic/observable.ts +51 -0
  128. package/src/basic/signal.ts +117 -0
  129. package/src/basic/state.ts +39 -0
  130. package/src/creators.ts +66 -15
  131. package/src/index.ts +26 -11
  132. package/test/array.test.ts +620 -0
  133. package/test/constant.test.ts +46 -0
  134. package/test/derivation.test.ts +30 -6
  135. package/test/effect.test.ts +29 -0
  136. package/test/map.test.ts +38 -0
  137. package/test/resource.test.ts +18 -16
  138. package/test/resourceAsync.test.ts +108 -0
  139. package/test/signal.test.ts +18 -1
  140. package/test/state.test.ts +107 -2
  141. package/test/stream.test.ts +38 -13
  142. package/test/streamAsync.test.ts +194 -0
  143. package/tsconfig.json +3 -1
  144. package/api/doc/picoflow.flowdisposer.md +0 -13
  145. package/api/doc/picoflow.flowsetter.md +0 -13
  146. package/api/doc/picoflow.flowstate._constructor_.md +0 -49
  147. package/api/doc/picoflow.flowstate.get.md +0 -23
  148. package/api/doc/picoflow.flowupdater.md +0 -19
  149. package/api/picoflow.api.md +0 -145
  150. package/dist/types/derivation.d.ts +0 -58
  151. package/dist/types/derivation.d.ts.map +0 -1
  152. package/dist/types/effect.d.ts +0 -108
  153. package/dist/types/effect.d.ts.map +0 -1
  154. package/dist/types/map.d.ts.map +0 -1
  155. package/dist/types/observable.d.ts +0 -40
  156. package/dist/types/observable.d.ts.map +0 -1
  157. package/dist/types/resource.d.ts.map +0 -1
  158. package/dist/types/signal.d.ts +0 -111
  159. package/dist/types/signal.d.ts.map +0 -1
  160. package/dist/types/state.d.ts +0 -39
  161. package/dist/types/state.d.ts.map +0 -1
  162. package/dist/types/stream.d.ts +0 -71
  163. package/dist/types/stream.d.ts.map +0 -1
  164. package/src/derivation.ts +0 -96
  165. package/src/effect.ts +0 -152
  166. package/src/observable.ts +0 -50
  167. package/src/signal.ts +0 -166
  168. package/src/state.ts +0 -52
  169. package/src/stream.ts +0 -99
@@ -1 +0,0 @@
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"}
@@ -1 +0,0 @@
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"}
@@ -1,111 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,39 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,71 +0,0 @@
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
@@ -1 +0,0 @@
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/src/derivation.ts DELETED
@@ -1,96 +0,0 @@
1
- import { type FlowGetter, FlowObservable } from "./observable";
2
- import type { FlowWatcher } from "./signal";
3
-
4
- /**
5
- * Represents a reactive derivation whose value is computed based on other reactive signals.
6
- * @remarks
7
- * A FlowDerivation automatically tracks its dependencies and recomputes its value when needed.
8
- * @typeparam T - The type of the computed value.
9
- * @public
10
- */
11
- export class FlowDerivation<T> extends FlowObservable<T> {
12
- /**
13
- * Creates a new FlowDerivation.
14
- * @param compute - A function that computes the derived value. It is provided with a getter
15
- * and a watcher function to access observables and signals dependencies.
16
- * @public
17
- */
18
- constructor(compute: (get: FlowGetter, watch: FlowWatcher) => T) {
19
- super();
20
- this._trackedExec = () => compute(this._trackedGet, this._trackedWatch);
21
- this._untrackedExec = () =>
22
- compute(this._untrackedGet, this._untrackedWatch);
23
- }
24
-
25
- /**
26
- * Gets the current derived value.
27
- * @returns The current computed value.
28
- * @remarks
29
- * This method ensures that the derivation is up-to-date before returning the value.
30
- * @public
31
- */
32
- public get(): T {
33
- this._exec();
34
- return this._value;
35
- }
36
-
37
- /* INTERNAL MEMBERS AND METHODS */
38
-
39
- /** @internal */
40
- private _initialized = false;
41
-
42
- /** @internal */
43
- private _dirty = true;
44
-
45
- /** @internal */
46
- private _trackedGet: FlowGetter = (observable) => observable._getFrom(this);
47
-
48
- /** @internal */
49
- private _trackedWatch: FlowWatcher = (signal) => signal._watchFrom(this);
50
-
51
- /** @internal */
52
- private _untrackedGet: FlowGetter = (observable) => observable.get();
53
-
54
- /** @internal */
55
- private _untrackedWatch: FlowWatcher = (signal) => signal._watch();
56
-
57
- /** @internal */
58
- private _trackedExec: () => T;
59
-
60
- /** @internal */
61
- private _untrackedExec: () => T;
62
-
63
- /**
64
- * @internal
65
- * Executes the compute function if necessary to update the derived value.
66
- */
67
- _exec(): void {
68
- if (this._disposed) throw new Error("Effect is disposed");
69
-
70
- if (this._dirty) {
71
- if (this._initialized) this._value = this._untrackedExec();
72
- else {
73
- this._value = this._trackedExec();
74
- this._initialized = true;
75
- }
76
- this._dirty = false;
77
- }
78
- }
79
-
80
- /**
81
- * @internal
82
- * Marks the derivation as dirty and notifies downstream dependencies.
83
- */
84
- override _notify(): void {
85
- this._dirty = true;
86
- super._notify();
87
- }
88
-
89
- /**
90
- * @internal
91
- * Ensures that the derivation is up-to-date when it is watched.
92
- */
93
- override _watch(): void {
94
- this._exec();
95
- }
96
- }
package/src/effect.ts DELETED
@@ -1,152 +0,0 @@
1
- import type { FlowGetter } from "./observable";
2
- import type { FlowSignal, FlowWatcher } from "./signal";
3
-
4
- /**
5
- * Represents a reactive effect that executes a side‐effect function
6
- * based on its tracked dependencies.
7
- *
8
- * @remarks
9
- * A FlowEffect runs an apply function to perform side effects. The apply function
10
- * is executed in two modes:
11
- * Initially, in a tracked mode to register dependencies.
12
- * Subsequently, in an untracked mode to only re-execute the effect .
13
- *
14
- * @public
15
- */
16
- export class FlowEffect {
17
- /* API --------------------------------------------------- */
18
-
19
- /**
20
- * Creates a new FlowEffect.
21
- *
22
- * @param apply - A function that performs the side effect. It receives a getter and a watcher
23
- * function to access and register dependencies on reactive observables and signals.
24
- *
25
- * @public
26
- */
27
- constructor(apply: (get: FlowGetter, watch: FlowWatcher) => void) {
28
- this._trackedExec = () => apply(this._trackedGet, this._trackedWatch);
29
- this._untrackedExec = () =>
30
- apply(this._untrackedGet, this._untrackedWatch);
31
- this._exec();
32
- }
33
-
34
- /**
35
- * Disposes the effect, unregistering all its dependencies.
36
- *
37
- * @remarks
38
- * After disposal, the effect should no longer be used. Calling this method on an already
39
- * disposed effect will throw an error.
40
- *
41
- * @public
42
- */
43
- public dispose(): void {
44
- if (this._disposed) throw new Error("Effect is disposed");
45
- Array.from(this._dependencies).forEach((dependency) => {
46
- this._unregisterDependency(dependency);
47
- });
48
- this._disposed = true;
49
- }
50
-
51
- /**
52
- * Indicates whether this effect has been disposed.
53
- *
54
- * @returns A boolean value indicating if the effect is disposed.
55
- *
56
- * @public
57
- */
58
- public get disposed(): boolean {
59
- return this._disposed;
60
- }
61
-
62
- /* INTERNAL ------------------------------------------------------------ */
63
-
64
- /**
65
- * @internal
66
- */
67
- private _disposed = false;
68
-
69
- /**
70
- * @internal
71
- */
72
- private _initialized = false;
73
-
74
- /**
75
- * @internal
76
- */
77
- private _dependencies = new Set<FlowSignal>();
78
-
79
- /**
80
- * @internal
81
- * A tracked getter that registers a dependency when accessing an observable.
82
- */
83
- private _trackedGet: FlowGetter = (observable) => observable._getFrom(this);
84
-
85
- /**
86
- * @internal
87
- * A tracked watcher that registers a dependency when watching a signal.
88
- */
89
- private _trackedWatch: FlowWatcher = (signal) => signal._watchFrom(this);
90
-
91
- /**
92
- * @internal
93
- * An untracked getter that simply retrieves the current value from an observable.
94
- */
95
- private _untrackedGet: FlowGetter = (observable) => observable.get();
96
-
97
- /**
98
- * @internal
99
- * An untracked watcher that calls the default watch on a signal.
100
- */
101
- private _untrackedWatch: FlowWatcher = (signal) => signal._watch();
102
-
103
- /**
104
- * @internal
105
- * Execution function used during initialization (tracked mode).
106
- */
107
- private _trackedExec: () => void;
108
-
109
- /**
110
- * @internal
111
- * Execution function used after initialization (untracked mode).
112
- */
113
- private _untrackedExec: () => void;
114
-
115
- /**
116
- * @internal
117
- * Executes the effect. If the effect has not been initialized, it runs in tracked mode;
118
- * otherwise, it runs in untracked mode.
119
- *
120
- * @throws Error if the effect has been disposed.
121
- */
122
- _exec(): void {
123
- if (this._disposed) throw new Error("Effect is disposed");
124
- if (this._initialized) this._untrackedExec();
125
- else {
126
- this._trackedExec();
127
- this._initialized = true;
128
- }
129
- }
130
-
131
- /**
132
- * @internal
133
- * Registers a dependency on the given signal.
134
- *
135
- * @param dependency - The FlowSignal to register as a dependency.
136
- */
137
- _registerDependency(dependency: FlowSignal): void {
138
- this._dependencies.add(dependency);
139
- dependency._registerEffect(this);
140
- }
141
-
142
- /**
143
- * @internal
144
- * Unregisters the given dependency.
145
- *
146
- * @param dependency - The FlowSignal to unregister.
147
- */
148
- _unregisterDependency(dependency: FlowSignal): void {
149
- this._dependencies.delete(dependency);
150
- dependency._unregisterEffect(this);
151
- }
152
- }
package/src/observable.ts DELETED
@@ -1,50 +0,0 @@
1
- import type { FlowEffect } from "./effect";
2
- import { FlowSignal } from "./signal";
3
-
4
- /**
5
- * A function for retrieving the current value from a FlowObservable.
6
- * @typeparam T - The type of the value held by the observable.
7
- * @param atom - The FlowObservable from which to get the value.
8
- * @returns The current value of the observable.
9
- * @public
10
- */
11
- export type FlowGetter = <T>(observable: FlowObservable<T>) => T;
12
-
13
- /**
14
- * Represents a reactive observable that carries a value.
15
- * @typeparam T - The type of the value held by the observable.
16
- * @remarks
17
- * A FlowObservable extends the basic FlowSignal to store a value. Subclasses must
18
- * implement the abstract {@link FlowObservable.get} method to return the current value.
19
- * @public
20
- */
21
- export abstract class FlowObservable<T> extends FlowSignal {
22
- /* API ----------------------------------------------- */
23
-
24
- /**
25
- * Retrieves the current value of the observable.
26
- * @returns The current value.
27
- * @public
28
- */
29
- abstract get(): T;
30
-
31
- /* INTERNAL -------------------------------------------*/
32
-
33
- /**
34
- * @internal
35
- * Internal storage for the observable's value.
36
- */
37
- protected _value!: T;
38
-
39
- /**
40
- * @internal
41
- * Retrieves the current value from the observable and registers a dependency
42
- * from the provided listener.
43
- * @param listener - The FlowObservable or FlowEffect that is accessing this observable.
44
- * @returns The current value, as returned by {@link FlowObservable.get}.
45
- */
46
- _getFrom(listener: FlowObservable<unknown> | FlowEffect): T {
47
- listener._registerDependency(this);
48
- return this.get();
49
- }
50
- }