@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
package/src/creators.ts CHANGED
@@ -1,11 +1,19 @@
1
- import { FlowDerivation } from "./derivation";
2
- import { FlowEffect } from "./effect";
3
- import { FlowMap } from "./map";
4
- import type { FlowGetter } from "./observable";
5
- import { FlowResource } from "./resource";
6
- import { FlowSignal, type FlowWatcher } from "./signal";
7
- import { FlowState } from "./state";
8
- import { FlowStream } from "./stream";
1
+ import {
2
+ FlowMap,
3
+ FlowResource,
4
+ FlowResourceAsync,
5
+ FlowStream,
6
+ FlowStreamAsync,
7
+ } from "./advanced/";
8
+ import { FlowArray } from "./advanced/array";
9
+ import {
10
+ FlowConstant,
11
+ FlowDerivation,
12
+ FlowEffect,
13
+ FlowSignal,
14
+ FlowState,
15
+ } from "./basic/";
16
+ import type { FlowGetter, FlowWatcher } from "./basic/";
9
17
 
10
18
  /**
11
19
  * Creates a new reactive signal.
@@ -16,6 +24,16 @@ export function signal(): FlowSignal {
16
24
  return new FlowSignal();
17
25
  }
18
26
 
27
+ /**
28
+ * Creates a new reactive constant.
29
+ * @param value - The value or a function that returns the value.
30
+ * @returns A new instance of {@link FlowConstant}.
31
+ * @public
32
+ */
33
+ export function constant<T>(value: T | (() => T)): FlowConstant<T> {
34
+ return new FlowConstant<T>(value);
35
+ }
36
+
19
37
  /**
20
38
  * Creates a new reactive state holding a value.
21
39
  * @typeparam T - The type of the state value.
@@ -23,7 +41,7 @@ export function signal(): FlowSignal {
23
41
  * @returns A new instance of {@link FlowState}.
24
42
  * @public
25
43
  */
26
- export function state<T>(value: T): FlowState<T> {
44
+ export function state<T>(value: T | (() => T)): FlowState<T> {
27
45
  return new FlowState(value);
28
46
  }
29
47
 
@@ -31,12 +49,22 @@ export function state<T>(value: T): FlowState<T> {
31
49
  * Creates a new reactive resource that asynchronously fetches its value.
32
50
  * @typeparam T - The type of the resource value.
33
51
  * @param fn - An asynchronous function that fetches the resource value.
34
- * @param initial - The initial value of the resource.
35
52
  * @returns A new instance of {@link FlowResource}.
36
53
  * @public
37
54
  */
38
- export function resource<T>(fn: () => Promise<T>, initial: T): FlowResource<T> {
39
- return new FlowResource(fn, initial);
55
+ export function resource<T>(fn: () => Promise<T>): FlowResource<T> {
56
+ return new FlowResource(fn);
57
+ }
58
+
59
+ /**
60
+ * Creates a new reactive asynchronous resource that fetches its value.
61
+ * @typeparam T - The type of the resource value.
62
+ * @param fn - An asynchronous function that fetches the resource value.
63
+ * @returns A new instance of {@link FlowResourceAsync}.
64
+ * @public
65
+ */
66
+ export function resourceAsync<T>(fn: () => Promise<T>): FlowResourceAsync<T> {
67
+ return new FlowResourceAsync(fn);
40
68
  }
41
69
 
42
70
  /**
@@ -44,15 +72,27 @@ export function resource<T>(fn: () => Promise<T>, initial: T): FlowResource<T> {
44
72
  * @typeparam T - The type of the stream value.
45
73
  * @param updater - A function that receives a setter to update the stream's value.
46
74
  * It should return a disposer function to clean up resources.
47
- * @param initial - The initial value of the stream.
48
75
  * @returns A new instance of {@link FlowStream}.
49
76
  * @public
50
77
  */
51
78
  export function stream<T>(
52
79
  updater: (set: (value: T) => void) => () => void,
53
- initial: T,
54
80
  ): FlowStream<T> {
55
- return new FlowStream(updater, initial);
81
+ return new FlowStream(updater);
82
+ }
83
+
84
+ /**
85
+ * Creates a new reactive asynchronous stream.
86
+ * @typeparam T - The type of the stream value.
87
+ * @param updater - A function that receives a setter to update the stream's value.
88
+ * It should return a disposer function to clean up resources.
89
+ * @returns A new instance of {@link FlowStreamAsync}.
90
+ * @public
91
+ */
92
+ export function streamAsync<T>(
93
+ updater: (set: (value: T) => void) => () => void,
94
+ ): FlowStreamAsync<T> {
95
+ return new FlowStreamAsync(updater);
56
96
  }
57
97
 
58
98
  /**
@@ -99,3 +139,14 @@ export function map<K extends string | number | symbol, V>(
99
139
  new Map<K, V>(initial ? (Object.entries(initial) as [K, V][]) : []),
100
140
  );
101
141
  }
142
+
143
+ /**
144
+ * Creates a new reactive array.
145
+ * @typeparam T - The type of the array elements.
146
+ * @param initial - An optional array of initial values.
147
+ * @returns A new instance of {@link FlowArray}.
148
+ * @public
149
+ */
150
+ export function array<T>(initial?: T[]): FlowArray<T> {
151
+ return new FlowArray<T>(initial);
152
+ }
package/src/index.ts CHANGED
@@ -9,22 +9,37 @@
9
9
  export {
10
10
  signal,
11
11
  state,
12
+ constant,
12
13
  resource,
13
14
  stream,
14
15
  derivation,
15
16
  effect,
16
17
  map,
18
+ array,
19
+ streamAsync,
20
+ resourceAsync,
17
21
  } from "./creators";
18
- export type { FlowDerivation } from "./derivation";
19
- export type { FlowEffect } from "./effect";
20
- export type { FlowGetter, FlowObservable } from "./observable";
21
- export type { FlowResource } from "./resource";
22
- export type { FlowSignal, FlowWatcher } from "./signal";
23
- export type { FlowState } from "./state";
24
- export type { FlowMap } from "./map";
22
+ export { isDisposable } from "./basic";
25
23
  export type {
24
+ FlowDerivation,
25
+ FlowEffect,
26
+ FlowGetter,
27
+ FlowObservable,
28
+ FlowSignal,
29
+ FlowWatcher,
30
+ FlowState,
31
+ FlowConstant,
32
+ FlowDisposable,
33
+ } from "./basic/";
34
+ export type {
35
+ FlowResource,
36
+ FlowMap,
37
+ FlowResourceAsync,
38
+ FlowStreamAsync,
26
39
  FlowStream,
27
- FlowDisposer,
28
- FlowSetter,
29
- FlowUpdater,
30
- } from "./stream";
40
+ FlowStreamDisposer,
41
+ FlowStreamSetter,
42
+ FlowStreamUpdater,
43
+ FlowArray,
44
+ FlowArrayAction,
45
+ } from "./advanced/";