synstate 0.1.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 (268) hide show
  1. package/README.md +878 -0
  2. package/dist/core/class/child-observable-class.d.mts +37 -0
  3. package/dist/core/class/child-observable-class.d.mts.map +1 -0
  4. package/dist/core/class/child-observable-class.mjs +134 -0
  5. package/dist/core/class/child-observable-class.mjs.map +1 -0
  6. package/dist/core/class/index.d.mts +4 -0
  7. package/dist/core/class/index.d.mts.map +1 -0
  8. package/dist/core/class/index.mjs +4 -0
  9. package/dist/core/class/index.mjs.map +1 -0
  10. package/dist/core/class/observable-base-class.d.mts +28 -0
  11. package/dist/core/class/observable-base-class.d.mts.map +1 -0
  12. package/dist/core/class/observable-base-class.mjs +116 -0
  13. package/dist/core/class/observable-base-class.mjs.map +1 -0
  14. package/dist/core/class/root-observable-class.d.mts +12 -0
  15. package/dist/core/class/root-observable-class.d.mts.map +1 -0
  16. package/dist/core/class/root-observable-class.mjs +35 -0
  17. package/dist/core/class/root-observable-class.mjs.map +1 -0
  18. package/dist/core/combine/combine.d.mts +35 -0
  19. package/dist/core/combine/combine.d.mts.map +1 -0
  20. package/dist/core/combine/combine.mjs +94 -0
  21. package/dist/core/combine/combine.mjs.map +1 -0
  22. package/dist/core/combine/index.d.mts +4 -0
  23. package/dist/core/combine/index.d.mts.map +1 -0
  24. package/dist/core/combine/index.mjs +4 -0
  25. package/dist/core/combine/index.mjs.map +1 -0
  26. package/dist/core/combine/merge.d.mts +28 -0
  27. package/dist/core/combine/merge.d.mts.map +1 -0
  28. package/dist/core/combine/merge.mjs +52 -0
  29. package/dist/core/combine/merge.mjs.map +1 -0
  30. package/dist/core/combine/zip.d.mts +26 -0
  31. package/dist/core/combine/zip.d.mts.map +1 -0
  32. package/dist/core/combine/zip.mjs +63 -0
  33. package/dist/core/combine/zip.mjs.map +1 -0
  34. package/dist/core/create/from-array.d.mts +21 -0
  35. package/dist/core/create/from-array.d.mts.map +1 -0
  36. package/dist/core/create/from-array.mjs +47 -0
  37. package/dist/core/create/from-array.mjs.map +1 -0
  38. package/dist/core/create/from-promise.d.mts +25 -0
  39. package/dist/core/create/from-promise.d.mts.map +1 -0
  40. package/dist/core/create/from-promise.mjs +51 -0
  41. package/dist/core/create/from-promise.mjs.map +1 -0
  42. package/dist/core/create/from-subscribable.d.mts +3 -0
  43. package/dist/core/create/from-subscribable.d.mts.map +1 -0
  44. package/dist/core/create/from-subscribable.mjs +22 -0
  45. package/dist/core/create/from-subscribable.mjs.map +1 -0
  46. package/dist/core/create/index.d.mts +8 -0
  47. package/dist/core/create/index.d.mts.map +1 -0
  48. package/dist/core/create/index.mjs +8 -0
  49. package/dist/core/create/index.mjs.map +1 -0
  50. package/dist/core/create/interval.d.mts +21 -0
  51. package/dist/core/create/interval.d.mts.map +1 -0
  52. package/dist/core/create/interval.mjs +74 -0
  53. package/dist/core/create/interval.mjs.map +1 -0
  54. package/dist/core/create/of.d.mts +20 -0
  55. package/dist/core/create/of.d.mts.map +1 -0
  56. package/dist/core/create/of.mjs +44 -0
  57. package/dist/core/create/of.mjs.map +1 -0
  58. package/dist/core/create/source.d.mts +29 -0
  59. package/dist/core/create/source.d.mts.map +1 -0
  60. package/dist/core/create/source.mjs +29 -0
  61. package/dist/core/create/source.mjs.map +1 -0
  62. package/dist/core/create/timer.d.mts +20 -0
  63. package/dist/core/create/timer.d.mts.map +1 -0
  64. package/dist/core/create/timer.mjs +64 -0
  65. package/dist/core/create/timer.mjs.map +1 -0
  66. package/dist/core/index.d.mts +7 -0
  67. package/dist/core/index.d.mts.map +1 -0
  68. package/dist/core/index.mjs +37 -0
  69. package/dist/core/index.mjs.map +1 -0
  70. package/dist/core/operators/audit-time.d.mts +3 -0
  71. package/dist/core/operators/audit-time.d.mts.map +1 -0
  72. package/dist/core/operators/audit-time.mjs +50 -0
  73. package/dist/core/operators/audit-time.mjs.map +1 -0
  74. package/dist/core/operators/debounce-time.d.mts +31 -0
  75. package/dist/core/operators/debounce-time.d.mts.map +1 -0
  76. package/dist/core/operators/debounce-time.mjs +73 -0
  77. package/dist/core/operators/debounce-time.mjs.map +1 -0
  78. package/dist/core/operators/filter.d.mts +28 -0
  79. package/dist/core/operators/filter.d.mts.map +1 -0
  80. package/dist/core/operators/filter.mjs +38 -0
  81. package/dist/core/operators/filter.mjs.map +1 -0
  82. package/dist/core/operators/index.d.mts +18 -0
  83. package/dist/core/operators/index.d.mts.map +1 -0
  84. package/dist/core/operators/index.mjs +18 -0
  85. package/dist/core/operators/index.mjs.map +1 -0
  86. package/dist/core/operators/map-with-index.d.mts +39 -0
  87. package/dist/core/operators/map-with-index.d.mts.map +1 -0
  88. package/dist/core/operators/map-with-index.mjs +73 -0
  89. package/dist/core/operators/map-with-index.mjs.map +1 -0
  90. package/dist/core/operators/merge-map.d.mts +34 -0
  91. package/dist/core/operators/merge-map.d.mts.map +1 -0
  92. package/dist/core/operators/merge-map.mjs +75 -0
  93. package/dist/core/operators/merge-map.mjs.map +1 -0
  94. package/dist/core/operators/pairwise.d.mts +27 -0
  95. package/dist/core/operators/pairwise.d.mts.map +1 -0
  96. package/dist/core/operators/pairwise.mjs +59 -0
  97. package/dist/core/operators/pairwise.mjs.map +1 -0
  98. package/dist/core/operators/scan.d.mts +30 -0
  99. package/dist/core/operators/scan.d.mts.map +1 -0
  100. package/dist/core/operators/scan.mjs +56 -0
  101. package/dist/core/operators/scan.mjs.map +1 -0
  102. package/dist/core/operators/skip-if-no-change.d.mts +33 -0
  103. package/dist/core/operators/skip-if-no-change.d.mts.map +1 -0
  104. package/dist/core/operators/skip-if-no-change.mjs +68 -0
  105. package/dist/core/operators/skip-if-no-change.mjs.map +1 -0
  106. package/dist/core/operators/skip-until.d.mts +3 -0
  107. package/dist/core/operators/skip-until.d.mts.map +1 -0
  108. package/dist/core/operators/skip-until.mjs +33 -0
  109. package/dist/core/operators/skip-until.mjs.map +1 -0
  110. package/dist/core/operators/skip-while.d.mts +4 -0
  111. package/dist/core/operators/skip-while.d.mts.map +1 -0
  112. package/dist/core/operators/skip-while.mjs +40 -0
  113. package/dist/core/operators/skip-while.mjs.map +1 -0
  114. package/dist/core/operators/switch-map.d.mts +31 -0
  115. package/dist/core/operators/switch-map.d.mts.map +1 -0
  116. package/dist/core/operators/switch-map.mjs +70 -0
  117. package/dist/core/operators/switch-map.mjs.map +1 -0
  118. package/dist/core/operators/take-until.d.mts +32 -0
  119. package/dist/core/operators/take-until.d.mts.map +1 -0
  120. package/dist/core/operators/take-until.mjs +60 -0
  121. package/dist/core/operators/take-until.mjs.map +1 -0
  122. package/dist/core/operators/take-while.d.mts +4 -0
  123. package/dist/core/operators/take-while.d.mts.map +1 -0
  124. package/dist/core/operators/take-while.mjs +42 -0
  125. package/dist/core/operators/take-while.mjs.map +1 -0
  126. package/dist/core/operators/throttle-time.d.mts +23 -0
  127. package/dist/core/operators/throttle-time.d.mts.map +1 -0
  128. package/dist/core/operators/throttle-time.mjs +68 -0
  129. package/dist/core/operators/throttle-time.mjs.map +1 -0
  130. package/dist/core/operators/with-buffered-from.d.mts +4 -0
  131. package/dist/core/operators/with-buffered-from.d.mts.map +1 -0
  132. package/dist/core/operators/with-buffered-from.mjs +45 -0
  133. package/dist/core/operators/with-buffered-from.mjs.map +1 -0
  134. package/dist/core/operators/with-current-value-from.d.mts +4 -0
  135. package/dist/core/operators/with-current-value-from.d.mts.map +1 -0
  136. package/dist/core/operators/with-current-value-from.mjs +37 -0
  137. package/dist/core/operators/with-current-value-from.mjs.map +1 -0
  138. package/dist/core/operators/with-initial-value.d.mts +26 -0
  139. package/dist/core/operators/with-initial-value.d.mts.map +1 -0
  140. package/dist/core/operators/with-initial-value.mjs +47 -0
  141. package/dist/core/operators/with-initial-value.mjs.map +1 -0
  142. package/dist/core/types/id.d.mts +4 -0
  143. package/dist/core/types/id.d.mts.map +1 -0
  144. package/dist/core/types/id.mjs +2 -0
  145. package/dist/core/types/id.mjs.map +1 -0
  146. package/dist/core/types/index.d.mts +6 -0
  147. package/dist/core/types/index.d.mts.map +1 -0
  148. package/dist/core/types/index.mjs +3 -0
  149. package/dist/core/types/index.mjs.map +1 -0
  150. package/dist/core/types/observable-family.d.mts +68 -0
  151. package/dist/core/types/observable-family.d.mts.map +1 -0
  152. package/dist/core/types/observable-family.mjs +2 -0
  153. package/dist/core/types/observable-family.mjs.map +1 -0
  154. package/dist/core/types/observable-kind.d.mts +4 -0
  155. package/dist/core/types/observable-kind.d.mts.map +1 -0
  156. package/dist/core/types/observable-kind.mjs +2 -0
  157. package/dist/core/types/observable-kind.mjs.map +1 -0
  158. package/dist/core/types/observable.d.mts +83 -0
  159. package/dist/core/types/observable.d.mts.map +1 -0
  160. package/dist/core/types/observable.mjs +10 -0
  161. package/dist/core/types/observable.mjs.map +1 -0
  162. package/dist/core/types/types.d.mts +16 -0
  163. package/dist/core/types/types.d.mts.map +1 -0
  164. package/dist/core/types/types.mjs +2 -0
  165. package/dist/core/types/types.mjs.map +1 -0
  166. package/dist/core/utils/id-maker.d.mts +5 -0
  167. package/dist/core/utils/id-maker.d.mts.map +1 -0
  168. package/dist/core/utils/id-maker.mjs +17 -0
  169. package/dist/core/utils/id-maker.mjs.map +1 -0
  170. package/dist/core/utils/index.d.mts +5 -0
  171. package/dist/core/utils/index.d.mts.map +1 -0
  172. package/dist/core/utils/index.mjs +5 -0
  173. package/dist/core/utils/index.mjs.map +1 -0
  174. package/dist/core/utils/max-depth.d.mts +3 -0
  175. package/dist/core/utils/max-depth.d.mts.map +1 -0
  176. package/dist/core/utils/max-depth.mjs +8 -0
  177. package/dist/core/utils/max-depth.mjs.map +1 -0
  178. package/dist/core/utils/observable-utils.d.mts +3 -0
  179. package/dist/core/utils/observable-utils.d.mts.map +1 -0
  180. package/dist/core/utils/observable-utils.mjs +7 -0
  181. package/dist/core/utils/observable-utils.mjs.map +1 -0
  182. package/dist/core/utils/utils.d.mts +4 -0
  183. package/dist/core/utils/utils.d.mts.map +1 -0
  184. package/dist/core/utils/utils.mjs +38 -0
  185. package/dist/core/utils/utils.mjs.map +1 -0
  186. package/dist/entry-point.d.mts +2 -0
  187. package/dist/entry-point.d.mts.map +1 -0
  188. package/dist/entry-point.mjs +40 -0
  189. package/dist/entry-point.mjs.map +1 -0
  190. package/dist/globals.d.mts +4 -0
  191. package/dist/index.d.mts +3 -0
  192. package/dist/index.d.mts.map +1 -0
  193. package/dist/index.mjs +40 -0
  194. package/dist/index.mjs.map +1 -0
  195. package/dist/tsconfig.json +1 -0
  196. package/dist/types.d.mts +2 -0
  197. package/dist/utils/create-event-emitter.d.mts +39 -0
  198. package/dist/utils/create-event-emitter.d.mts.map +1 -0
  199. package/dist/utils/create-event-emitter.mjs +57 -0
  200. package/dist/utils/create-event-emitter.mjs.map +1 -0
  201. package/dist/utils/create-reducer.d.mts +34 -0
  202. package/dist/utils/create-reducer.d.mts.map +1 -0
  203. package/dist/utils/create-reducer.mjs +49 -0
  204. package/dist/utils/create-reducer.mjs.map +1 -0
  205. package/dist/utils/create-state.d.mts +61 -0
  206. package/dist/utils/create-state.d.mts.map +1 -0
  207. package/dist/utils/create-state.mjs +92 -0
  208. package/dist/utils/create-state.mjs.map +1 -0
  209. package/dist/utils/index.d.mts +4 -0
  210. package/dist/utils/index.d.mts.map +1 -0
  211. package/dist/utils/index.mjs +4 -0
  212. package/dist/utils/index.mjs.map +1 -0
  213. package/package.json +71 -0
  214. package/src/core/class/child-observable-class.mts +232 -0
  215. package/src/core/class/index.mts +3 -0
  216. package/src/core/class/observable-base-class.mts +186 -0
  217. package/src/core/class/observable.class.test.mts +89 -0
  218. package/src/core/class/root-observable-class.mts +68 -0
  219. package/src/core/combine/combine.mts +144 -0
  220. package/src/core/combine/index.mts +3 -0
  221. package/src/core/combine/merge.mts +84 -0
  222. package/src/core/combine/zip.mts +149 -0
  223. package/src/core/create/from-array.mts +58 -0
  224. package/src/core/create/from-promise.mts +58 -0
  225. package/src/core/create/from-subscribable.mts +37 -0
  226. package/src/core/create/index.mts +7 -0
  227. package/src/core/create/interval.mts +99 -0
  228. package/src/core/create/of.mts +54 -0
  229. package/src/core/create/source.mts +59 -0
  230. package/src/core/create/timer.mts +84 -0
  231. package/src/core/index.mts +6 -0
  232. package/src/core/operators/audit-time.mts +77 -0
  233. package/src/core/operators/debounce-time.mts +96 -0
  234. package/src/core/operators/filter.mts +125 -0
  235. package/src/core/operators/index.mts +17 -0
  236. package/src/core/operators/map-with-index.mts +168 -0
  237. package/src/core/operators/merge-map.mts +108 -0
  238. package/src/core/operators/pairwise.mts +77 -0
  239. package/src/core/operators/scan.mts +81 -0
  240. package/src/core/operators/skip-if-no-change.mts +91 -0
  241. package/src/core/operators/skip-until.mts +54 -0
  242. package/src/core/operators/skip-while.mts +77 -0
  243. package/src/core/operators/switch-map.mts +101 -0
  244. package/src/core/operators/take-until.mts +80 -0
  245. package/src/core/operators/take-while.mts +103 -0
  246. package/src/core/operators/throttle-time.mts +95 -0
  247. package/src/core/operators/with-buffered-from.mts +68 -0
  248. package/src/core/operators/with-current-value-from.mts +58 -0
  249. package/src/core/operators/with-initial-value.mts +76 -0
  250. package/src/core/types/id.mts +5 -0
  251. package/src/core/types/index.mts +5 -0
  252. package/src/core/types/observable-family.mts +259 -0
  253. package/src/core/types/observable-kind.mts +5 -0
  254. package/src/core/types/observable.mts +218 -0
  255. package/src/core/types/types.mts +40 -0
  256. package/src/core/utils/id-maker.mts +31 -0
  257. package/src/core/utils/index.mts +4 -0
  258. package/src/core/utils/max-depth.mts +7 -0
  259. package/src/core/utils/observable-utils.mts +10 -0
  260. package/src/core/utils/utils.mts +51 -0
  261. package/src/core/utils/utils.test.mts +88 -0
  262. package/src/entry-point.mts +1 -0
  263. package/src/globals.d.mts +4 -0
  264. package/src/index.mts +2 -0
  265. package/src/utils/create-event-emitter.mts +62 -0
  266. package/src/utils/create-reducer.mts +55 -0
  267. package/src/utils/create-state.mts +138 -0
  268. package/src/utils/index.mts +3 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timer.d.mts","sourceRoot":"","sources":["../../../src/core/create/timer.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,KAAK,GAChB,cAAc,MAAM,EACpB,gBAAe,OAAe,KAC7B,eAAwE,CAAC"}
@@ -0,0 +1,64 @@
1
+ import { Optional } from 'ts-data-forge';
2
+ import '../utils/id-maker.mjs';
3
+ import { RootObservableClass } from '../class/root-observable-class.mjs';
4
+
5
+ /**
6
+ * Creates an observable that emits 0 after a specified delay and then completes.
7
+ *
8
+ * @param milliSeconds - The delay in milliseconds before emission
9
+ * @param startManually - If true, waits for manual start (default: false)
10
+ * @returns An observable that emits after delay
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const delayed$ = timer(1000);
15
+ *
16
+ * delayed$.subscribe(() => {
17
+ * console.log('1 second passed');
18
+ * });
19
+ * // After 1 second, logs: 1 second passed
20
+ * ```
21
+ */
22
+ const timer = (milliSeconds, startManually = false) => new TimerObservableClass(milliSeconds, startManually);
23
+ class TimerObservableClass extends RootObservableClass {
24
+ #milliSeconds;
25
+ #mut_timerId;
26
+ #mut_isStarted;
27
+ constructor(milliSeconds, startManually) {
28
+ super({ initialValue: Optional.none });
29
+ this.#milliSeconds = milliSeconds;
30
+ this.#mut_timerId = undefined;
31
+ this.#mut_isStarted = false;
32
+ if (!startManually) {
33
+ this.start();
34
+ }
35
+ }
36
+ start() {
37
+ if (this.#mut_isStarted) {
38
+ console.warn('cannot start twice');
39
+ return this;
40
+ }
41
+ this.#mut_isStarted = true;
42
+ if (this.isCompleted) {
43
+ console.warn('cannot restart stopped TimerObservable');
44
+ return this;
45
+ }
46
+ this.#mut_timerId = setTimeout(() => {
47
+ this.startUpdate(0);
48
+ this.complete();
49
+ }, this.#milliSeconds);
50
+ return this;
51
+ }
52
+ #resetTimer() {
53
+ if (this.#mut_timerId !== undefined) {
54
+ clearTimeout(this.#mut_timerId);
55
+ }
56
+ }
57
+ complete() {
58
+ this.#resetTimer();
59
+ super.complete();
60
+ }
61
+ }
62
+
63
+ export { timer };
64
+ //# sourceMappingURL=timer.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timer.mjs","sources":["../../../src/core/create/timer.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAIA;;;;;;;;;;;;;;;;AAgBG;AACI,MAAM,KAAK,GAAG,CACnB,YAAoB,EACpB,aAAA,GAAyB,KAAK,KACV,IAAI,oBAAoB,CAAC,YAAY,EAAE,aAAa;AAE1E,MAAM,oBACJ,SAAQ,mBAAsB,CAAA;AAGrB,IAAA,aAAa;AACtB,IAAA,YAAY;AACZ,IAAA,cAAc;IAEd,WAAA,CAAY,YAAoB,EAAE,aAAsB,EAAA;QACtD,KAAK,CAAC,EAAE,YAAY,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;AAEtC,QAAA,IAAI,CAAC,aAAa,GAAG,YAAY;AAEjC,QAAA,IAAI,CAAC,YAAY,GAAG,SAAS;AAE7B,QAAA,IAAI,CAAC,cAAc,GAAG,KAAK;QAE3B,IAAI,CAAC,aAAa,EAAE;YAClB,IAAI,CAAC,KAAK,EAAE;QACd;IACF;IAEA,KAAK,GAAA;AACH,QAAA,IAAI,IAAI,CAAC,cAAc,EAAE;AACvB,YAAA,OAAO,CAAC,IAAI,CAAC,oBAAoB,CAAC;AAElC,YAAA,OAAO,IAAI;QACb;AAEA,QAAA,IAAI,CAAC,cAAc,GAAG,IAAI;AAE1B,QAAA,IAAI,IAAI,CAAC,WAAW,EAAE;AACpB,YAAA,OAAO,CAAC,IAAI,CAAC,wCAAwC,CAAC;AAEtD,YAAA,OAAO,IAAI;QACb;AAEA,QAAA,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,MAAK;AAClC,YAAA,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;YAEnB,IAAI,CAAC,QAAQ,EAAE;AACjB,QAAA,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC;AAEtB,QAAA,OAAO,IAAI;IACb;IAEA,WAAW,GAAA;AACT,QAAA,IAAI,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE;AACnC,YAAA,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC;QACjC;IACF;IAES,QAAQ,GAAA;QACf,IAAI,CAAC,WAAW,EAAE;QAElB,KAAK,CAAC,QAAQ,EAAE;IAClB;AACD;;;;"}
@@ -0,0 +1,7 @@
1
+ export * from './class/index.mjs';
2
+ export * from './combine/index.mjs';
3
+ export * from './create/index.mjs';
4
+ export * from './operators/index.mjs';
5
+ export * from './types/index.mjs';
6
+ export * from './utils/index.mjs';
7
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/core/index.mts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,37 @@
1
+ export { AsyncChildObservableClass, InitializedSyncChildObservableClass, SyncChildObservableClass } from './class/child-observable-class.mjs';
2
+ export { ObservableBaseClass } from './class/observable-base-class.mjs';
3
+ export { RootObservableClass } from './class/root-observable-class.mjs';
4
+ export { combine, combineLatest } from './combine/combine.mjs';
5
+ export { merge } from './combine/merge.mjs';
6
+ export { zip } from './combine/zip.mjs';
7
+ export { fromArray } from './create/from-array.mjs';
8
+ export { fromPromise } from './create/from-promise.mjs';
9
+ export { fromSubscribable } from './create/from-subscribable.mjs';
10
+ export { interval } from './create/interval.mjs';
11
+ export { of } from './create/of.mjs';
12
+ export { source, subject } from './create/source.mjs';
13
+ export { timer } from './create/timer.mjs';
14
+ export { auditTime } from './operators/audit-time.mjs';
15
+ export { debounceTime } from './operators/debounce-time.mjs';
16
+ export { filter } from './operators/filter.mjs';
17
+ export { attachIndex, getKey, map, mapOptional, mapResultErr, mapResultOk, mapTo, mapWithIndex, pluck, unwrapOptional, unwrapResultErr, unwrapResultOk, withIndex } from './operators/map-with-index.mjs';
18
+ export { flatMap, mergeMap } from './operators/merge-map.mjs';
19
+ export { pairwise } from './operators/pairwise.mjs';
20
+ export { scan } from './operators/scan.mjs';
21
+ export { distinctUntilChanged, skipIfNoChange } from './operators/skip-if-no-change.mjs';
22
+ export { skipUntil } from './operators/skip-until.mjs';
23
+ export { skip, skipWhile } from './operators/skip-while.mjs';
24
+ export { switchMap } from './operators/switch-map.mjs';
25
+ export { takeUntil } from './operators/take-until.mjs';
26
+ export { take, takeWhile } from './operators/take-while.mjs';
27
+ export { throttleTime } from './operators/throttle-time.mjs';
28
+ export { withBuffered, withBufferedFrom } from './operators/with-buffered-from.mjs';
29
+ export { withCurrentValueFrom, withLatestFrom } from './operators/with-current-value-from.mjs';
30
+ export { withInitialValue } from './operators/with-initial-value.mjs';
31
+ import 'ts-data-forge';
32
+ export { isChildObservable, isManagerObservable, isRootObservable } from './types/observable.mjs';
33
+ export { issueObservableId, issueSubscriberId, issueUpdaterSymbol } from './utils/id-maker.mjs';
34
+ export { maxDepth } from './utils/max-depth.mjs';
35
+ export { toSubscriber } from './utils/observable-utils.mjs';
36
+ export { binarySearch, halfInt } from './utils/utils.mjs';
37
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,3 @@
1
+ import { type KeepInitialValueOperator } from '../types/index.mjs';
2
+ export declare const auditTime: <A>(milliSeconds: number) => KeepInitialValueOperator<A, A>;
3
+ //# sourceMappingURL=audit-time.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-time.d.mts","sourceRoot":"","sources":["../../../src/core/operators/audit-time.mts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,wBAAwB,EAG9B,MAAM,oBAAoB,CAAC;AAE5B,eAAO,MAAM,SAAS,GAAI,CAAC,EACzB,cAAc,MAAM,KACnB,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAMQ,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { Optional } from 'ts-data-forge';
2
+ import { AsyncChildObservableClass } from '../class/child-observable-class.mjs';
3
+ import '../utils/id-maker.mjs';
4
+
5
+ const auditTime = (milliSeconds) =>
6
+ // eslint-disable-next-line total-functions/no-unsafe-type-assertion
7
+ ((parentObservable) => new AuditTimeObservableClass(parentObservable, milliSeconds));
8
+ class AuditTimeObservableClass extends AsyncChildObservableClass {
9
+ #milliSeconds;
10
+ #mut_timerId;
11
+ #mut_isSkipping;
12
+ constructor(parentObservable, milliSeconds) {
13
+ super({
14
+ parents: [parentObservable],
15
+ initialValue: parentObservable.getSnapshot(),
16
+ });
17
+ this.#mut_isSkipping = false;
18
+ this.#mut_timerId = undefined;
19
+ this.#milliSeconds = milliSeconds;
20
+ }
21
+ tryUpdate(updaterSymbol) {
22
+ const par = this.parents[0];
23
+ if (par.updaterSymbol !== updaterSymbol ||
24
+ Optional.isNone(par.getSnapshot()) ||
25
+ this.#mut_isSkipping) {
26
+ return; // skip update
27
+ }
28
+ // set timer
29
+ this.#mut_isSkipping = true;
30
+ this.#mut_timerId = setTimeout(() => {
31
+ const sn = par.getSnapshot();
32
+ if (Optional.isNone(sn))
33
+ return;
34
+ this.startUpdate(sn.value);
35
+ this.#mut_isSkipping = false;
36
+ }, this.#milliSeconds);
37
+ }
38
+ #resetTimer() {
39
+ if (this.#mut_timerId !== undefined) {
40
+ clearTimeout(this.#mut_timerId);
41
+ }
42
+ }
43
+ complete() {
44
+ this.#resetTimer();
45
+ super.complete();
46
+ }
47
+ }
48
+
49
+ export { auditTime };
50
+ //# sourceMappingURL=audit-time.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-time.mjs","sources":["../../../src/core/operators/audit-time.mts"],"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IAAI,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE;AACnC,YAAA,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC;QACjC;IACF;IAES,QAAQ,GAAA;QACf,IAAI,CAAC,WAAW,EAAE;QAElB,KAAK,CAAC,QAAQ,EAAE;IAClB;AACD;;;;"}
@@ -0,0 +1,31 @@
1
+ import { type KeepInitialValueOperator } from '../types/index.mjs';
2
+ /**
3
+ * Delays emissions from the source observable until a specified time has passed without another emission.
4
+ * Useful for handling user input events like typing or scrolling.
5
+ *
6
+ * @template A - The type of values from the source
7
+ * @param milliSeconds - The debounce duration in milliseconds
8
+ * @returns An operator that debounces the observable
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const input$ = source<string>();
13
+ *
14
+ * const debounced$ = input$.pipe(debounceTime(300));
15
+ *
16
+ * debounced$.subscribe((value) => {
17
+ * console.log(value);
18
+ * });
19
+ *
20
+ * input$.next('h');
21
+ *
22
+ * input$.next('he');
23
+ *
24
+ * input$.next('hel');
25
+ *
26
+ * input$.next('hello');
27
+ * // After 300ms of silence, logs: hello
28
+ * ```
29
+ */
30
+ export declare const debounceTime: <A>(milliSeconds: number) => KeepInitialValueOperator<A, A>;
31
+ //# sourceMappingURL=debounce-time.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debounce-time.d.mts","sourceRoot":"","sources":["../../../src/core/operators/debounce-time.mts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,wBAAwB,EAG9B,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,EAC5B,cAAc,MAAM,KACnB,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAMQ,CAAC"}
@@ -0,0 +1,73 @@
1
+ import { Optional } from 'ts-data-forge';
2
+ import { AsyncChildObservableClass } from '../class/child-observable-class.mjs';
3
+ import '../utils/id-maker.mjs';
4
+
5
+ /**
6
+ * Delays emissions from the source observable until a specified time has passed without another emission.
7
+ * Useful for handling user input events like typing or scrolling.
8
+ *
9
+ * @template A - The type of values from the source
10
+ * @param milliSeconds - The debounce duration in milliseconds
11
+ * @returns An operator that debounces the observable
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const input$ = source<string>();
16
+ *
17
+ * const debounced$ = input$.pipe(debounceTime(300));
18
+ *
19
+ * debounced$.subscribe((value) => {
20
+ * console.log(value);
21
+ * });
22
+ *
23
+ * input$.next('h');
24
+ *
25
+ * input$.next('he');
26
+ *
27
+ * input$.next('hel');
28
+ *
29
+ * input$.next('hello');
30
+ * // After 300ms of silence, logs: hello
31
+ * ```
32
+ */
33
+ const debounceTime = (milliSeconds) =>
34
+ // eslint-disable-next-line total-functions/no-unsafe-type-assertion
35
+ ((parentObservable) => new DebounceTimeObservableClass(parentObservable, milliSeconds));
36
+ class DebounceTimeObservableClass extends AsyncChildObservableClass {
37
+ #milliSeconds;
38
+ #mut_timerId;
39
+ constructor(parentObservable, milliSeconds) {
40
+ super({
41
+ parents: [parentObservable],
42
+ initialValue: parentObservable.getSnapshot(),
43
+ });
44
+ this.#mut_timerId = undefined;
45
+ this.#milliSeconds = milliSeconds;
46
+ }
47
+ tryUpdate(updaterSymbol) {
48
+ const par = this.parents[0];
49
+ const sn = par.getSnapshot();
50
+ if (par.updaterSymbol !== updaterSymbol || Optional.isNone(sn)) {
51
+ return; // skip update
52
+ }
53
+ this.#resetTimer();
54
+ // set timer
55
+ this.#mut_timerId = setTimeout(() => {
56
+ if (Optional.isNone(sn))
57
+ return;
58
+ this.startUpdate(sn.value);
59
+ }, this.#milliSeconds);
60
+ }
61
+ #resetTimer() {
62
+ if (this.#mut_timerId !== undefined) {
63
+ clearTimeout(this.#mut_timerId);
64
+ }
65
+ }
66
+ complete() {
67
+ this.#resetTimer();
68
+ super.complete();
69
+ }
70
+ }
71
+
72
+ export { debounceTime };
73
+ //# sourceMappingURL=debounce-time.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3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AAI,CAAC,YAAY,CAAC;QACjC;IACF;IAES,QAAQ,GAAA;QACf,IAAI,CAAC,WAAW,EAAE;QAElB,KAAK,CAAC,QAAQ,EAAE;IAClB;AACD;;;;"}
@@ -0,0 +1,28 @@
1
+ import { type DropInitialValueOperator } from '../types/index.mjs';
2
+ /**
3
+ * Filters values emitted by the source observable based on a predicate function.
4
+ * Only values that satisfy the predicate will be emitted by the resulting observable.
5
+ *
6
+ * @template A - The type of values from the source
7
+ * @template B - The narrowed type when using type guard
8
+ * @param predicate - A function that tests each value (receives value and index)
9
+ * @returns An operator that filters the observable
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const num$ = source<number>();
14
+ *
15
+ * const even$ = num$.pipe(filter((x) => x % 2 === 0));
16
+ *
17
+ * even$.subscribe((x) => {
18
+ * console.log(x);
19
+ * });
20
+ *
21
+ * num$.next(1); // nothing logged
22
+ *
23
+ * num$.next(2); // logs: 2
24
+ * ```
25
+ */
26
+ export declare function filter<A, B extends A>(predicate: (value: A, index: SafeUint | -1) => value is B): DropInitialValueOperator<A, B>;
27
+ export declare function filter<A>(predicate: (value: A, index: SafeUint | -1) => boolean): DropInitialValueOperator<A, A>;
28
+ //# sourceMappingURL=filter.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter.d.mts","sourceRoot":"","sources":["../../../src/core/operators/filter.mts"],"names":[],"mappings":"AASA,OAAO,EACL,KAAK,wBAAwB,EAK9B,MAAM,oBAAoB,CAAC;AAG5B;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,EACnC,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,GAAG,CAAC,CAAC,KAAK,KAAK,IAAI,CAAC,GACxD,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAElC,wBAAgB,MAAM,CAAC,CAAC,EACtB,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,GAAG,CAAC,CAAC,KAAK,OAAO,GACrD,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC"}
@@ -0,0 +1,38 @@
1
+ import { pipe, Optional, asSafeUint, SafeUint } from 'ts-data-forge';
2
+ import { SyncChildObservableClass } from '../class/child-observable-class.mjs';
3
+ import '../utils/id-maker.mjs';
4
+
5
+ function filter(predicate) {
6
+ return (parentObservable) => new FilterObservableClass(parentObservable, predicate);
7
+ }
8
+ class FilterObservableClass extends SyncChildObservableClass {
9
+ #predicate;
10
+ #mut_index;
11
+ constructor(parentObservable, predicate) {
12
+ super({
13
+ parents: [parentObservable],
14
+ initialValue: pipe(parentObservable.getSnapshot()).map((sn) => Optional.isNone(sn)
15
+ ? Optional.none
16
+ : predicate(sn.value, -1)
17
+ ? sn
18
+ : Optional.none).value,
19
+ });
20
+ this.#mut_index = -1;
21
+ this.#predicate = predicate;
22
+ }
23
+ tryUpdate(updaterSymbol) {
24
+ const par = this.parents[0];
25
+ const sn = par.getSnapshot();
26
+ if (par.updaterSymbol !== updaterSymbol || Optional.isNone(sn)) {
27
+ return; // skip update
28
+ }
29
+ this.#mut_index =
30
+ this.#mut_index === -1 ? asSafeUint(0) : SafeUint.add(1, this.#mut_index);
31
+ if (this.#predicate(sn.value, this.#mut_index)) {
32
+ this.setNext(sn.value, updaterSymbol);
33
+ }
34
+ }
35
+ }
36
+
37
+ export { filter };
38
+ //# sourceMappingURL=filter.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter.mjs","sources":["../../../src/core/operators/filter.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAkDM,SAAU,MAAM,CACpB,SAAsD,EAAA;AAEtD,IAAA,OAAO,CAAC,gBAAgB,KACtB,IAAI,qBAAqB,CAAC,gBAAgB,EAAE,SAAS,CAAC;AAC1D;AAEA,MAAM,qBACJ,SAAQ,wBAAyC,CAAA;AAGxC,IAAA,UAAU;AACnB,IAAA,UAAU;IAEV,WAAA,CACE,gBAA+B,EAC/B,SAAkD,EAAA;AAElD,QAAA,KAAK,CAAC;YACJ,OAAO,EAAE,CAAC,gBAAgB,CAAC;YAC3B,YAAY,EAAE,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,KACxD,QAAQ,CAAC,MAAM,CAAC,EAAE;kBACd,QAAQ,CAAC;kBACT,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE;AACtB,sBAAE;AACF,sBAAE,QAAQ,CAAC,IAAI,CACpB,CAAC,KAAK;AACR,SAAA,CAAC;AAEF,QAAA,IAAI,CAAC,UAAU,GAAG,EAAE;AAEpB,QAAA,IAAI,CAAC,UAAU,GAAG,SAAS;;AAGpB,IAAA,SAAS,CAAC,aAA4B,EAAA;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3B,QAAA,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE;AAE5B,QAAA,IAAI,GAAG,CAAC,aAAa,KAAK,aAAa,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;AAC9D,YAAA,OAAO;;AAGT,QAAA,IAAI,CAAC,UAAU;YACb,IAAI,CAAC,UAAU,KAAK,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC;AAE3E,QAAA,IAAI,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,EAAE;YAC9C,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC;;;AAG1C;;;;"}
@@ -0,0 +1,18 @@
1
+ export * from './audit-time.mjs';
2
+ export * from './debounce-time.mjs';
3
+ export * from './filter.mjs';
4
+ export * from './map-with-index.mjs';
5
+ export * from './merge-map.mjs';
6
+ export * from './pairwise.mjs';
7
+ export * from './scan.mjs';
8
+ export * from './skip-if-no-change.mjs';
9
+ export * from './skip-until.mjs';
10
+ export * from './skip-while.mjs';
11
+ export * from './switch-map.mjs';
12
+ export * from './take-until.mjs';
13
+ export * from './take-while.mjs';
14
+ export * from './throttle-time.mjs';
15
+ export * from './with-buffered-from.mjs';
16
+ export * from './with-current-value-from.mjs';
17
+ export * from './with-initial-value.mjs';
18
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/core/operators/index.mts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC"}
@@ -0,0 +1,18 @@
1
+ export { auditTime } from './audit-time.mjs';
2
+ export { debounceTime } from './debounce-time.mjs';
3
+ export { filter } from './filter.mjs';
4
+ export { attachIndex, getKey, map, mapOptional, mapResultErr, mapResultOk, mapTo, mapWithIndex, pluck, unwrapOptional, unwrapResultErr, unwrapResultOk, withIndex } from './map-with-index.mjs';
5
+ export { flatMap, mergeMap } from './merge-map.mjs';
6
+ export { pairwise } from './pairwise.mjs';
7
+ export { scan } from './scan.mjs';
8
+ export { distinctUntilChanged, skipIfNoChange } from './skip-if-no-change.mjs';
9
+ export { skipUntil } from './skip-until.mjs';
10
+ export { skip, skipWhile } from './skip-while.mjs';
11
+ export { switchMap } from './switch-map.mjs';
12
+ export { takeUntil } from './take-until.mjs';
13
+ export { take, takeWhile } from './take-while.mjs';
14
+ export { throttleTime } from './throttle-time.mjs';
15
+ export { withBuffered, withBufferedFrom } from './with-buffered-from.mjs';
16
+ export { withCurrentValueFrom, withLatestFrom } from './with-current-value-from.mjs';
17
+ export { withInitialValue } from './with-initial-value.mjs';
18
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;"}
@@ -0,0 +1,39 @@
1
+ import { Optional, Result } from 'ts-data-forge';
2
+ import { type KeepInitialValueOperator } from '../types/index.mjs';
3
+ /**
4
+ * Transforms each value emitted by the source using a mapping function that also receives the emission index.
5
+ *
6
+ * @template A - The type of values from the source
7
+ * @template B - The type of mapped values
8
+ * @param mapFn - A function that maps each value (receives value and index)
9
+ * @returns An operator that maps values with index
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const num$ = source<number>();
14
+ *
15
+ * const indexed$ = num$.pipe(mapWithIndex((x, i) => `${i}: ${x}`));
16
+ *
17
+ * indexed$.subscribe((s) => {
18
+ * console.log(s);
19
+ * });
20
+ *
21
+ * num$.next(10); // logs: 0: 10
22
+ *
23
+ * num$.next(20); // logs: 1: 20
24
+ * ```
25
+ */
26
+ export declare const mapWithIndex: <A, B>(mapFn: (x: A, index: SafeUint | -1) => B) => KeepInitialValueOperator<A, B>;
27
+ export declare const map: <A, B>(mapFn: (x: A) => B) => KeepInitialValueOperator<A, B>;
28
+ export declare const mapTo: <A, B>(value: B) => KeepInitialValueOperator<A, B>;
29
+ export declare const pluck: <A, K extends keyof A>(key: K) => KeepInitialValueOperator<A, A[K]>;
30
+ export declare const getKey: <A, K extends keyof A>(key: K) => KeepInitialValueOperator<A, A[K]>;
31
+ export declare const attachIndex: <A>() => KeepInitialValueOperator<A, readonly [SafeUint | -1, A]>;
32
+ export declare const withIndex: <A>() => KeepInitialValueOperator<A, readonly [SafeUint | -1, A]>;
33
+ export declare const unwrapOptional: <O extends UnknownOptional>() => KeepInitialValueOperator<O, Optional.Unwrap<O> | undefined>;
34
+ export declare const unwrapResultOk: <R extends UnknownResult>() => KeepInitialValueOperator<R, Result.UnwrapOk<R> | undefined>;
35
+ export declare const unwrapResultErr: <R extends UnknownResult>() => KeepInitialValueOperator<R, Result.UnwrapErr<R> | undefined>;
36
+ export declare const mapOptional: <O extends UnknownOptional, B>(mapFn: (x: Optional.Unwrap<O>) => B) => KeepInitialValueOperator<O, Optional<B>>;
37
+ export declare const mapResultOk: <R extends UnknownResult, S2>(mapFn: (x: Result.UnwrapOk<R>) => S2) => KeepInitialValueOperator<R, Result<S2, Result.UnwrapErr<R>>>;
38
+ export declare const mapResultErr: <R extends UnknownResult, E2>(mapFn: (x: Result.UnwrapErr<R>) => E2) => KeepInitialValueOperator<R, Result<Result.UnwrapOk<R>, E2>>;
39
+ //# sourceMappingURL=map-with-index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-with-index.d.mts","sourceRoot":"","sources":["../../../src/core/operators/map-with-index.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,MAAM,EAIP,MAAM,eAAe,CAAC;AAGvB,OAAO,EAEL,KAAK,wBAAwB,EAI9B,MAAM,oBAAoB,CAAC;AAG5B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,EAAE,CAAC,EAC/B,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,KACvC,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAMQ,CAAC;AAIzC,eAAO,MAAM,GAAG,GAAI,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAG,wBAAwB,CAAC,CAAC,EAAE,CAAC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AAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAClC,wBAAwB,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CACN,CAAC;AAErC,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,aAAa,EAAE,EAAE,EACrD,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,EAAE,KACnC,wBAAwB,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAC5B,CAAC;AAEnC,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,aAAa,EAAE,EAAE,EACtD,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,EAAE,KACpC,wBAAwB,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CACxB,CAAC"}
@@ -0,0 +1,73 @@
1
+ import { Optional, asSafeUint, SafeUint, Result } from 'ts-data-forge';
2
+ import { SyncChildObservableClass } from '../class/child-observable-class.mjs';
3
+ import '../utils/id-maker.mjs';
4
+
5
+ /**
6
+ * Transforms each value emitted by the source using a mapping function that also receives the emission index.
7
+ *
8
+ * @template A - The type of values from the source
9
+ * @template B - The type of mapped values
10
+ * @param mapFn - A function that maps each value (receives value and index)
11
+ * @returns An operator that maps values with index
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const num$ = source<number>();
16
+ *
17
+ * const indexed$ = num$.pipe(mapWithIndex((x, i) => `${i}: ${x}`));
18
+ *
19
+ * indexed$.subscribe((s) => {
20
+ * console.log(s);
21
+ * });
22
+ *
23
+ * num$.next(10); // logs: 0: 10
24
+ *
25
+ * num$.next(20); // logs: 1: 20
26
+ * ```
27
+ */
28
+ const mapWithIndex = (mapFn) =>
29
+ // eslint-disable-next-line total-functions/no-unsafe-type-assertion
30
+ ((parentObservable) => new MapWithIndexObservableClass(parentObservable, mapFn));
31
+ /* Specialized operators */
32
+ const map = (mapFn) => mapWithIndex(mapFn);
33
+ const mapTo = (value) => map(() => value);
34
+ const pluck = (key) => map((a) => a[key]);
35
+ const getKey = pluck; // alias
36
+ const attachIndex = () => mapWithIndex((a, i) => [i, a]);
37
+ const withIndex = attachIndex; // alias
38
+ const unwrapOptional = () =>
39
+ // eslint-disable-next-line total-functions/no-unsafe-type-assertion
40
+ map(Optional.unwrap);
41
+ const unwrapResultOk = () =>
42
+ // eslint-disable-next-line total-functions/no-unsafe-type-assertion
43
+ map(Result.unwrapOk);
44
+ const unwrapResultErr = () => map(Result.unwrapErr);
45
+ const mapOptional = (mapFn) => map((a) => Optional.map(a, mapFn));
46
+ const mapResultOk = (mapFn) => map((a) => Result.map(a, mapFn));
47
+ const mapResultErr = (mapFn) => map((a) => Result.mapErr(a, mapFn));
48
+ /* implementation */
49
+ class MapWithIndexObservableClass extends SyncChildObservableClass {
50
+ #mapFn;
51
+ #mut_index;
52
+ constructor(parentObservable, mapFn) {
53
+ super({
54
+ parents: [parentObservable],
55
+ initialValue: Optional.map(parentObservable.getSnapshot(), (x) => mapFn(x, -1)),
56
+ });
57
+ this.#mut_index = -1;
58
+ this.#mapFn = mapFn;
59
+ }
60
+ tryUpdate(updaterSymbol) {
61
+ const par = this.parents[0];
62
+ const sn = par.getSnapshot();
63
+ if (par.updaterSymbol !== updaterSymbol || Optional.isNone(sn)) {
64
+ return; // skip update
65
+ }
66
+ this.#mut_index =
67
+ this.#mut_index === -1 ? asSafeUint(0) : SafeUint.add(1, this.#mut_index);
68
+ this.setNext(this.#mapFn(sn.value, this.#mut_index), updaterSymbol);
69
+ }
70
+ }
71
+
72
+ export { attachIndex, getKey, map, mapOptional, mapResultErr, mapResultOk, mapTo, mapWithIndex, pluck, unwrapOptional, unwrapResultErr, unwrapResultOk, withIndex };
73
+ //# sourceMappingURL=map-with-index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-with-index.m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,MAAM;AACf,IAAA,UAAU;IAEV,WAAA,CACE,gBAA+B,EAC/B,KAAwC,EAAA;AAExC,QAAA,KAAK,CAAC;YACJ,OAAO,EAAE,CAAC,gBAAgB,CAAC;YAC3B,YAAY,EAAE,QAAQ,CAAC,GAAG,CAAC,gBAAgB,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,KAC3D,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CACb;AACF,SAAA,CAAC;AAEF,QAAA,IAAI,CAAC,UAAU,GAAG,EAAE;AAEpB,QAAA,IAAI,CAAC,MAAM,GAAG,KAAK;;AAGZ,IAAA,SAAS,CAAC,aAA4B,EAAA;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3B,QAAA,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE;AAE5B,QAAA,IAAI,GAAG,CAAC,aAAa,KAAK,aAAa,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;AAC9D,YAAA,OAAO;;AAGT,QAAA,IAAI,CAAC,UAAU;YACb,IAAI,CAAC,UAAU,KAAK,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC;AAE3E,QAAA,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC;;AAEtE;;;;"}
@@ -0,0 +1,34 @@
1
+ import { type DropInitialValueOperator, type Observable } from '../types/index.mjs';
2
+ /**
3
+ * Projects each source value to an observable and merges all inner observables.
4
+ * Unlike `switchMap`, does not cancel previous inner observables.
5
+ *
6
+ * @template A - The type of values from the source
7
+ * @template B - The type of values from the projected observable
8
+ * @param mapToObservable - A function that maps each source value to an observable
9
+ * @returns An operator that merges mapped observables
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const ids$ = source<number>();
14
+ *
15
+ * const users$ = ids$.pipe(mergeMap((id) => fromPromise(fetchUser(id))));
16
+ *
17
+ * users$.subscribe((user) => {
18
+ * console.log(user);
19
+ * });
20
+ * // All requests run in parallel, results merged as they arrive
21
+ *
22
+ * const fetchUser = async (id: number): Promise<unknown> => ({ id });
23
+ * ```
24
+ *
25
+ * @note To improve code readability, consider using `createState` instead of `mergeMap`,
26
+ * subscribing to `parentObservable` and calling `setState` within it.
27
+ */
28
+ export declare const mergeMap: <A, B>(mapToObservable: (curr: A) => Observable<B>) => DropInitialValueOperator<A, B>;
29
+ /**
30
+ * Alias for `mergeMap()`.
31
+ * @see mergeMap
32
+ */
33
+ export declare const flatMap: <A, B>(mapToObservable: (curr: A) => Observable<B>) => DropInitialValueOperator<A, B>;
34
+ //# sourceMappingURL=merge-map.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-map.d.mts","sourceRoot":"","sources":["../../../src/core/operators/merge-map.mts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,wBAAwB,EAE7B,KAAK,UAAU,EAGhB,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,QAAQ,GAClB,CAAC,EAAE,CAAC,EACH,iBAAiB,CAAC,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,KAC1C,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAEgC,CAAC;AAEnE;;;GAGG;AACH,eAAO,MAAM,OAAO,GAVjB,CAAC,EAAE,CAAC,mBACc,CAAC,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,KAC1C,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAQH,CAAC"}