synstate 3.0.0 → 3.0.2

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 (148) hide show
  1. package/README.md +1 -1
  2. package/dist/core/base/create-child-observable.d.mts.map +1 -1
  3. package/dist/core/base/create-child-observable.mjs +169 -140
  4. package/dist/core/base/create-child-observable.mjs.map +1 -1
  5. package/dist/core/base/create-observable-base.d.mts.map +1 -1
  6. package/dist/core/base/create-observable-base.mjs +155 -152
  7. package/dist/core/base/create-observable-base.mjs.map +1 -1
  8. package/dist/core/base/create-root-observable.mjs +48 -34
  9. package/dist/core/base/create-root-observable.mjs.map +1 -1
  10. package/dist/core/base/index.mjs +3 -3
  11. package/dist/core/base/index.mjs.map +1 -1
  12. package/dist/core/combine/combine.mjs +129 -37
  13. package/dist/core/combine/combine.mjs.map +1 -1
  14. package/dist/core/combine/index.mjs +4 -4
  15. package/dist/core/combine/index.mjs.map +1 -1
  16. package/dist/core/combine/merge.mjs +75 -24
  17. package/dist/core/combine/merge.mjs.map +1 -1
  18. package/dist/core/combine/zip.mjs +120 -39
  19. package/dist/core/combine/zip.mjs.map +1 -1
  20. package/dist/core/create/counter.mjs +81 -45
  21. package/dist/core/create/counter.mjs.map +1 -1
  22. package/dist/core/create/from-abortable-promise.mjs +63 -38
  23. package/dist/core/create/from-abortable-promise.mjs.map +1 -1
  24. package/dist/core/create/from-promise.mjs +67 -25
  25. package/dist/core/create/from-promise.mjs.map +1 -1
  26. package/dist/core/create/from-subscribable.mjs +70 -26
  27. package/dist/core/create/from-subscribable.mjs.map +1 -1
  28. package/dist/core/create/index.mjs +8 -8
  29. package/dist/core/create/index.mjs.map +1 -1
  30. package/dist/core/create/just.mjs +36 -13
  31. package/dist/core/create/just.mjs.map +1 -1
  32. package/dist/core/create/source.mjs +15 -19
  33. package/dist/core/create/source.mjs.map +1 -1
  34. package/dist/core/create/timer.mjs +66 -37
  35. package/dist/core/create/timer.mjs.map +1 -1
  36. package/dist/core/index.mjs +6 -41
  37. package/dist/core/index.mjs.map +1 -1
  38. package/dist/core/operators/audit.mjs +126 -39
  39. package/dist/core/operators/audit.mjs.map +1 -1
  40. package/dist/core/operators/debounce.mjs +114 -37
  41. package/dist/core/operators/debounce.mjs.map +1 -1
  42. package/dist/core/operators/filter.mjs +39 -24
  43. package/dist/core/operators/filter.mjs.map +1 -1
  44. package/dist/core/operators/index.mjs +18 -18
  45. package/dist/core/operators/index.mjs.map +1 -1
  46. package/dist/core/operators/map.mjs +74 -26
  47. package/dist/core/operators/map.mjs.map +1 -1
  48. package/dist/core/operators/merge-map.mjs +128 -35
  49. package/dist/core/operators/merge-map.mjs.map +1 -1
  50. package/dist/core/operators/pairwise.mjs +73 -23
  51. package/dist/core/operators/pairwise.mjs.map +1 -1
  52. package/dist/core/operators/scan.mjs +59 -15
  53. package/dist/core/operators/scan.mjs.map +1 -1
  54. package/dist/core/operators/skip-if-no-change.mjs +89 -31
  55. package/dist/core/operators/skip-if-no-change.mjs.map +1 -1
  56. package/dist/core/operators/skip-until.mjs +71 -29
  57. package/dist/core/operators/skip-until.mjs.map +1 -1
  58. package/dist/core/operators/skip-while.mjs +79 -27
  59. package/dist/core/operators/skip-while.mjs.map +1 -1
  60. package/dist/core/operators/switch-map.mjs +118 -31
  61. package/dist/core/operators/switch-map.mjs.map +1 -1
  62. package/dist/core/operators/take-until.mjs +70 -35
  63. package/dist/core/operators/take-until.mjs.map +1 -1
  64. package/dist/core/operators/take-while.mjs +97 -25
  65. package/dist/core/operators/take-while.mjs.map +1 -1
  66. package/dist/core/operators/throttle.mjs +108 -38
  67. package/dist/core/operators/throttle.mjs.map +1 -1
  68. package/dist/core/operators/with-buffered-from.mjs +94 -47
  69. package/dist/core/operators/with-buffered-from.mjs.map +1 -1
  70. package/dist/core/operators/with-current-value-from.mjs +78 -23
  71. package/dist/core/operators/with-current-value-from.mjs.map +1 -1
  72. package/dist/core/operators/with-initial-value.mjs +64 -14
  73. package/dist/core/operators/with-initial-value.mjs.map +1 -1
  74. package/dist/core/predefined/index.mjs +2 -12
  75. package/dist/core/predefined/index.mjs.map +1 -1
  76. package/dist/core/predefined/operators/attach-index.mjs +55 -7
  77. package/dist/core/predefined/operators/attach-index.mjs.map +1 -1
  78. package/dist/core/predefined/operators/index.mjs +12 -12
  79. package/dist/core/predefined/operators/index.mjs.map +1 -1
  80. package/dist/core/predefined/operators/map-optional.mjs +48 -5
  81. package/dist/core/predefined/operators/map-optional.mjs.map +1 -1
  82. package/dist/core/predefined/operators/map-result-err.mjs +48 -5
  83. package/dist/core/predefined/operators/map-result-err.mjs.map +1 -1
  84. package/dist/core/predefined/operators/map-result-ok.mjs +48 -5
  85. package/dist/core/predefined/operators/map-result-ok.mjs.map +1 -1
  86. package/dist/core/predefined/operators/map-to.mjs +41 -6
  87. package/dist/core/predefined/operators/map-to.mjs.map +1 -1
  88. package/dist/core/predefined/operators/pluck.mjs +45 -7
  89. package/dist/core/predefined/operators/pluck.mjs.map +1 -1
  90. package/dist/core/predefined/operators/skip.mjs +49 -6
  91. package/dist/core/predefined/operators/skip.mjs.map +1 -1
  92. package/dist/core/predefined/operators/take.mjs +42 -6
  93. package/dist/core/predefined/operators/take.mjs.map +1 -1
  94. package/dist/core/predefined/operators/unwrap-optional.mjs +43 -8
  95. package/dist/core/predefined/operators/unwrap-optional.mjs.map +1 -1
  96. package/dist/core/predefined/operators/unwrap-result-err.mjs +41 -5
  97. package/dist/core/predefined/operators/unwrap-result-err.mjs.map +1 -1
  98. package/dist/core/predefined/operators/unwrap-result-ok.mjs +43 -8
  99. package/dist/core/predefined/operators/unwrap-result-ok.mjs.map +1 -1
  100. package/dist/core/types/id.mjs +2 -2
  101. package/dist/core/types/id.mjs.map +1 -1
  102. package/dist/core/types/index.mjs +7 -3
  103. package/dist/core/types/index.mjs.map +1 -1
  104. package/dist/core/types/observable-family.d.mts +2 -2
  105. package/dist/core/types/observable-family.d.mts.map +1 -1
  106. package/dist/core/types/observable-family.mjs +10 -2
  107. package/dist/core/types/observable-family.mjs.map +1 -1
  108. package/dist/core/types/observable-kind.mjs +2 -2
  109. package/dist/core/types/observable-kind.mjs.map +1 -1
  110. package/dist/core/types/observable.mjs +14 -6
  111. package/dist/core/types/observable.mjs.map +1 -1
  112. package/dist/core/types/timer.d.mts +11 -1
  113. package/dist/core/types/timer.d.mts.map +1 -1
  114. package/dist/core/types/timer.mjs +2 -2
  115. package/dist/core/types/timer.mjs.map +1 -1
  116. package/dist/core/types/types.mjs +9 -2
  117. package/dist/core/types/types.mjs.map +1 -1
  118. package/dist/core/utils/id-maker.mjs +10 -11
  119. package/dist/core/utils/id-maker.mjs.map +1 -1
  120. package/dist/core/utils/index.mjs +5 -5
  121. package/dist/core/utils/index.mjs.map +1 -1
  122. package/dist/core/utils/max-depth.mjs +7 -4
  123. package/dist/core/utils/max-depth.mjs.map +1 -1
  124. package/dist/core/utils/observable-utils.mjs +4 -7
  125. package/dist/core/utils/observable-utils.mjs.map +1 -1
  126. package/dist/core/utils/utils.mjs +32 -28
  127. package/dist/core/utils/utils.mjs.map +1 -1
  128. package/dist/entry-point.mjs +2 -46
  129. package/dist/entry-point.mjs.map +1 -1
  130. package/dist/index.mjs +3 -46
  131. package/dist/index.mjs.map +1 -1
  132. package/dist/utils/collect-to-array.mjs +8 -13
  133. package/dist/utils/collect-to-array.mjs.map +1 -1
  134. package/dist/utils/create-boolean-state.mjs +47 -22
  135. package/dist/utils/create-boolean-state.mjs.map +1 -1
  136. package/dist/utils/create-event-emitter.mjs +67 -19
  137. package/dist/utils/create-event-emitter.mjs.map +1 -1
  138. package/dist/utils/create-reducer.mjs +54 -16
  139. package/dist/utils/create-reducer.mjs.map +1 -1
  140. package/dist/utils/create-state.mjs +54 -27
  141. package/dist/utils/create-state.mjs.map +1 -1
  142. package/dist/utils/index.mjs +6 -6
  143. package/dist/utils/index.mjs.map +1 -1
  144. package/package.json +14 -12
  145. package/src/core/base/create-child-observable.mts +6 -1
  146. package/src/core/base/create-observable-base.mts +8 -1
  147. package/src/core/types/observable-family.mts +53 -34
  148. package/src/core/types/timer.mts +11 -2
@@ -1,41 +1,111 @@
1
1
  import { Optional } from 'ts-data-forge';
2
- import { createSyncChildObservable } from '../base/create-child-observable.mjs';
3
- import '../utils/id-maker.mjs';
4
-
5
- const throttle = (milliSeconds) => (
6
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
7
- ((parentObservable) => createThrottleObservable(
8
- parentObservable,
9
- milliSeconds
10
- ))
11
- );
2
+ import { createSyncChildObservable } from '../base/index.mjs';
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+ export const throttle = (milliSeconds) =>
82
+
83
+ ((parentObservable) => createThrottleObservable(parentObservable, milliSeconds));
12
84
  const createThrottleObservable = (parentObservable, milliSeconds) => {
13
- let mut_timerId = void 0;
14
- let mut_isSkipping = false;
15
- const resetTimer = () => {
16
- if (mut_timerId !== void 0) {
17
- clearTimeout(mut_timerId);
18
- }
19
- };
20
- return createSyncChildObservable(
21
- {
22
- parents: [parentObservable],
23
- initialValue: parentObservable.getSnapshot(),
24
- onComplete: resetTimer
25
- },
26
- ({ setNext }) => (updateToken) => {
27
- const sn = parentObservable.getSnapshot();
28
- if (mut_isSkipping || parentObservable.updateToken !== updateToken || Optional.isNone(sn)) {
29
- return;
30
- }
31
- setNext(sn.value, updateToken);
32
- mut_isSkipping = true;
33
- mut_timerId = setTimeout(() => {
34
- mut_isSkipping = false;
35
- }, milliSeconds);
36
- }
37
- );
38
- };
85
+ let mut_timerId = undefined;
86
+ let mut_isSkipping = false;
87
+ const resetTimer = () => {
88
+ if (mut_timerId !== undefined) {
89
+ clearTimeout(mut_timerId);
90
+ }
91
+ };
92
+ return createSyncChildObservable({
93
+ parents: [parentObservable],
94
+ initialValue: parentObservable.getSnapshot(),
95
+ onComplete: resetTimer,
96
+ }, ({ setNext }) => (updateToken) => {
97
+ const sn = parentObservable.getSnapshot();
98
+ if (mut_isSkipping ||
99
+ parentObservable.updateToken !== updateToken ||
100
+ Optional.isNone(sn)) {
101
+ return;
102
+ }
103
+ setNext(sn.value, updateToken);
104
+ mut_isSkipping = true;
39
105
 
40
- export { throttle };
41
- //# sourceMappingURL=throttle.mjs.map
106
+ mut_timerId = setTimeout(() => {
107
+ mut_isSkipping = false;
108
+ }, milliSeconds);
109
+ });
110
+ };
111
+ //# sourceMappingURL=throttle.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"throttle.mjs","sources":["../../../src/core/operators/throttle.mts"],"sourcesContent":["import { Optional } from 'ts-data-forge';\nimport { createSyncChildObservable } from '../base/index.mjs';\nimport {\n type KeepInitialValueOperator,\n type Observable,\n type ThrottleOperatorObservable,\n type TimerId,\n} from '../types/index.mjs';\n\n/**\n * Emits the first value, then ignores subsequent values for a specified duration.\n * After the duration, the next emission is allowed through.\n *\n * @template A - The type of values from the source\n * @param milliSeconds - The throttle duration in milliseconds\n * @returns An operator that throttles emissions\n *\n * @example\n * ```ts\n * // Timeline (250ms throttle):\n * //\n * // Time(x50ms) 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0\n * //\n * // input$ 0 2 3 9 10 11 12 13 14\n * // |- 250ms -> |- 250ms -> |- 250ms -> |- 250ms ->\n * // throttled$ 0 3 9 12 (emitted at start of window)\n * //\n * // Explanation:\n * // - throttle emits the FIRST value received, then ignores subsequent values\n * // for the specified duration (250ms)\n * // - Unlike audit (which emits the LAST value), throttle emits the FIRST\n * // - Useful for rate-limiting scroll/resize events\n *\n * const input$ = source<number>();\n *\n * const throttled$ = input$.pipe(throttle(250));\n *\n * const valueHistory: number[] = [];\n *\n * throttled$.subscribe((value) => {\n * valueHistory.push(value);\n * });\n *\n * const sleep = (ms: number): Promise<void> =>\n * new Promise((resolve) => {\n * setTimeout(resolve, ms);\n * });\n *\n * input$.next(0);\n *\n * assert.deepStrictEqual(valueHistory, [0]);\n *\n * await sleep(200);\n *\n * input$.next(2);\n *\n * assert.deepStrictEqual(valueHistory, [0]);\n *\n * await sleep(100);\n *\n * input$.next(3);\n *\n * assert.deepStrictEqual(valueHistory, [0, 3]);\n *\n * await sleep(300);\n *\n * input$.next(9);\n *\n * assert.deepStrictEqual(valueHistory, [0, 3, 9]);\n *\n * await sleep(100);\n *\n * input$.next(10);\n *\n * await sleep(100);\n *\n * input$.next(11);\n *\n * assert.deepStrictEqual(valueHistory, [0, 3, 9]);\n *\n * await sleep(100);\n *\n * input$.next(12);\n *\n * assert.deepStrictEqual(valueHistory, [0, 3, 9, 12]);\n * ```\n */\nexport const throttle = <A,>(\n milliSeconds: number,\n): KeepInitialValueOperator<A, A> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n ((parentObservable) =>\n createThrottleObservable(\n parentObservable,\n milliSeconds,\n )) as KeepInitialValueOperator<A, A>;\n\nconst createThrottleObservable = <A,>(\n parentObservable: Observable<A>,\n milliSeconds: number,\n): ThrottleOperatorObservable<A> => {\n let mut_timerId: TimerId | undefined = undefined;\n\n let mut_isSkipping = false;\n\n const resetTimer = (): void => {\n if (mut_timerId !== undefined) {\n clearTimeout(mut_timerId);\n }\n };\n\n return createSyncChildObservable(\n {\n parents: [parentObservable],\n initialValue: parentObservable.getSnapshot(),\n onComplete: resetTimer,\n },\n ({ setNext }) =>\n (updateToken) => {\n const sn = parentObservable.getSnapshot();\n\n if (\n mut_isSkipping ||\n parentObservable.updateToken !== updateToken ||\n Optional.isNone(sn)\n ) {\n return; // skip update\n }\n\n setNext(sn.value, updateToken);\n\n mut_isSkipping = true;\n\n // set timer\n mut_timerId = setTimeout(() => {\n mut_isSkipping = false;\n }, milliSeconds);\n },\n );\n};\n"],"names":[],"mappings":";;;;AAuFO,MAAM,WAAW,CACtB,YAAA;AAAA;AAAA,GAGC,CAAC,gBAAA,KACA,wBAAA;AAAA,IACE,gBAAA;AAAA,IACA;AAAA,GACF;AAAA;AAEJ,MAAM,wBAAA,GAA2B,CAC/B,gBAAA,EACA,YAAA,KACkC;AAClC,EAAA,IAAI,WAAA,GAAmC,MAAA;AAEvC,EAAA,IAAI,cAAA,GAAiB,KAAA;AAErB,EAAA,MAAM,aAAa,MAAY;AAC7B,IAAA,IAAI,gBAAgB,MAAA,EAAW;AAC7B,MAAA,YAAA,CAAa,WAAW,CAAA;AAAA,IAC1B;AAAA,EACF,CAAA;AAEA,EAAA,OAAO,yBAAA;AAAA,IACL;AAAA,MACE,OAAA,EAAS,CAAC,gBAAgB,CAAA;AAAA,MAC1B,YAAA,EAAc,iBAAiB,WAAA,EAAY;AAAA,MAC3C,UAAA,EAAY;AAAA,KACd;AAAA,IACA,CAAC,EAAE,OAAA,EAAQ,KACT,CAAC,WAAA,KAAgB;AACf,MAAA,MAAM,EAAA,GAAK,iBAAiB,WAAA,EAAY;AAExC,MAAA,IACE,kBACA,gBAAA,CAAiB,WAAA,KAAgB,eACjC,QAAA,CAAS,MAAA,CAAO,EAAE,CAAA,EAClB;AACA,QAAA;AAAA,MACF;AAEA,MAAA,OAAA,CAAQ,EAAA,CAAG,OAAO,WAAW,CAAA;AAE7B,MAAA,cAAA,GAAiB,IAAA;AAGjB,MAAA,WAAA,GAAc,WAAW,MAAM;AAC7B,QAAA,cAAA,GAAiB,KAAA;AAAA,MACnB,GAAG,YAAY,CAAA;AAAA,IACjB;AAAA,GACJ;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"throttle.mjs","sourceRoot":"","sources":["../../../src/core/operators/throttle.mts"],"names":[],"m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AAE;YAC5B,cAAc,GAAG,KAAK,CAAC;QACzB,CAAC,EAAE,YAAY,CAAC,CAAC;IACnB,CAAC,CACJ,CAAC;AACJ,CAAC,CAAC"}
@@ -1,49 +1,96 @@
1
- import { Optional, pipe, Arr } from 'ts-data-forge';
2
- import { createSyncChildObservable } from '../base/create-child-observable.mjs';
3
- import '../utils/id-maker.mjs';
4
- import { maxDepth } from '../utils/max-depth.mjs';
5
-
6
- const withBufferedFrom = (observable) => (
7
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
8
- ((parentObservable) => createWithBufferedFromObservable(
9
- parentObservable,
10
- observable
11
- ))
12
- );
13
- const withBuffered = withBufferedFrom;
1
+ import { Arr, Optional, pipe } from 'ts-data-forge';
2
+ import { createSyncChildObservable } from '../base/index.mjs';
3
+ import { maxDepth } from '../utils/index.mjs';
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+ export const withBufferedFrom = (observable) =>
58
+
59
+ ((parentObservable) => createWithBufferedFromObservable(parentObservable, observable));
60
+
61
+
62
+
63
+
64
+ export const withBuffered = withBufferedFrom;
14
65
  const createWithBufferedFromObservable = (parentObservable, observable) => {
15
- let mut_bufferedValues = [];
16
- const clearBuffer = () => {
17
- mut_bufferedValues = [];
18
- };
19
- const result = createSyncChildObservable(
20
- {
21
- parents: [parentObservable],
22
- depth: 1 + maxDepth([parentObservable, observable]),
23
- initialValue: pipe({
24
- par: parentObservable.getSnapshot(),
25
- me: observable.getSnapshot()
26
- }).map(
27
- ({ par, me }) => Optional.isNone(par) ? Optional.none : Optional.some([
28
- par.value,
29
- Optional.isNone(me) ? [] : [me.value]
30
- ])
31
- ).value
32
- },
33
- ({ setNext }) => (updateToken) => {
34
- const sn = parentObservable.getSnapshot();
35
- if (parentObservable.updateToken !== updateToken || Optional.isNone(sn)) {
36
- return;
37
- }
38
- setNext([sn.value, mut_bufferedValues], updateToken);
39
- clearBuffer();
40
- }
41
- );
42
- observable.subscribe((value) => {
43
- mut_bufferedValues = Arr.toPushed(mut_bufferedValues, value);
44
- });
45
- return result;
66
+ let mut_bufferedValues = [];
67
+ const clearBuffer = () => {
68
+ mut_bufferedValues = [];
69
+ };
70
+ const result = createSyncChildObservable({
71
+ parents: [parentObservable],
72
+ depth: 1 + maxDepth([parentObservable, observable]),
73
+ initialValue: pipe({
74
+ par: parentObservable.getSnapshot(),
75
+ me: observable.getSnapshot(),
76
+ }).map(({ par, me }) => Optional.isNone(par)
77
+ ? Optional.none
78
+ : Optional.some([
79
+ par.value,
80
+ Optional.isNone(me) ? [] : [me.value],
81
+ ])).value,
82
+ }, ({ setNext }) => (updateToken) => {
83
+ const sn = parentObservable.getSnapshot();
84
+ if (parentObservable.updateToken !== updateToken ||
85
+ Optional.isNone(sn)) {
86
+ return;
87
+ }
88
+ setNext([sn.value, mut_bufferedValues], updateToken);
89
+ clearBuffer();
90
+ });
91
+ observable.subscribe((value) => {
92
+ mut_bufferedValues = Arr.toPushed(mut_bufferedValues, value);
93
+ });
94
+ return result;
46
95
  };
47
-
48
- export { withBuffered, withBufferedFrom };
49
- //# sourceMappingURL=with-buffered-from.mjs.map
96
+ //# sourceMappingURL=with-buffered-from.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"with-buffered-from.mjs","sources":["../../../src/core/operators/with-buffered-from.mts"],"sourcesContent":["import { Arr, Optional, pipe } from 'ts-data-forge';\nimport { createSyncChildObservable } from '../base/index.mjs';\nimport {\n type KeepInitialValueOperator,\n type Observable,\n type WithBufferedFromOperatorObservable,\n} from '../types/index.mjs';\nimport { maxDepth } from '../utils/index.mjs';\n\n/**\n * Buffers values from the source observable and emits them along with the parent value\n * when the parent emits. The buffer is cleared after each emission.\n *\n * @template A - The type of values from the parent observable\n * @template B - The type of values from the source observable\n * @param observable - The observable whose values will be buffered\n * @returns An operator that emits tuples of [parentValue, bufferedValues]\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // data$ d1 d2 d3 d4 d5 d6 d7 d8\n * // trigger$ T1 T2 T3\n * // result$ [T1,[d1,d2,d3]] [T2,[d4,d5,d6]] [T3,[d7,d8]]\n * //\n * // Explanation:\n * // - withBufferedFrom collects values from the source observable\n * // - When the trigger emits, it emits a tuple of [triggerValue, bufferedValues]\n * // - Buffer is cleared after each emission\n * // - Useful for batching data collection triggered by events\n *\n * const data$ = source<string>();\n *\n * const trigger$ = source<number>();\n *\n * const result$ = trigger$.pipe(withBufferedFrom(data$));\n *\n * const valueHistory: (readonly [number, readonly string[]])[] = [];\n *\n * result$.subscribe(([triggerValue, bufferedData]) => {\n * valueHistory.push([triggerValue, bufferedData]);\n * });\n *\n * data$.next('A');\n *\n * data$.next('B');\n *\n * trigger$.next(1);\n *\n * assert.deepStrictEqual(valueHistory, [[1, ['A', 'B']]]);\n *\n * data$.next('C');\n *\n * trigger$.next(2);\n *\n * assert.deepStrictEqual(valueHistory, [\n * [1, ['A', 'B']],\n * [2, ['C']],\n * ]);\n * ```\n */\nexport const withBufferedFrom = <A, B>(\n observable: Observable<B>,\n): KeepInitialValueOperator<A, readonly [A, readonly B[]]> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n ((parentObservable) =>\n createWithBufferedFromObservable(\n parentObservable,\n observable,\n )) as KeepInitialValueOperator<A, readonly [A, readonly B[]]>;\n\n/**\n * Alias for `withBufferedFrom`.\n * @see withBufferedFrom\n */\nexport const withBuffered = withBufferedFrom;\n\nconst createWithBufferedFromObservable = <A, B>(\n parentObservable: Observable<A>,\n observable: Observable<B>,\n): WithBufferedFromOperatorObservable<A, B> => {\n let mut_bufferedValues: readonly B[] = [];\n\n const clearBuffer = (): void => {\n mut_bufferedValues = [];\n };\n\n const result = createSyncChildObservable<\n readonly [A, readonly B[]],\n readonly [A]\n >(\n {\n parents: [parentObservable],\n depth: 1 + maxDepth([parentObservable, observable]),\n initialValue: pipe({\n par: parentObservable.getSnapshot(),\n me: observable.getSnapshot(),\n }).map(({ par, me }) =>\n Optional.isNone(par)\n ? Optional.none\n : Optional.some([\n par.value,\n Optional.isNone(me) ? [] : [me.value],\n ] as const),\n ).value,\n },\n ({ setNext }) =>\n (updateToken) => {\n const sn = parentObservable.getSnapshot();\n\n if (\n parentObservable.updateToken !== updateToken ||\n Optional.isNone(sn)\n ) {\n return; // skip update\n }\n\n setNext([sn.value, mut_bufferedValues], updateToken);\n\n clearBuffer();\n },\n );\n\n observable.subscribe((value) => {\n mut_bufferedValues = Arr.toPushed(mut_bufferedValues, value);\n });\n\n return result;\n};\n"],"names":[],"mappings":";;;;;AA8DO,MAAM,mBAAmB,CAC9B,UAAA;AAAA;AAAA,GAGC,CAAC,gBAAA,KACA,gCAAA;AAAA,IACE,gBAAA;AAAA,IACA;AAAA,GACF;AAAA;AAMG,MAAM,YAAA,GAAe;AAE5B,MAAM,gCAAA,GAAmC,CACvC,gBAAA,EACA,UAAA,KAC6C;AAC7C,EAAA,IAAI,qBAAmC,EAAC;AAExC,EAAA,MAAM,cAAc,MAAY;AAC9B,IAAA,kBAAA,GAAqB,EAAC;AAAA,EACxB,CAAA;AAEA,EAAA,MAAM,MAAA,GAAS,yBAAA;AAAA,IAIb;AAAA,MACE,OAAA,EAAS,CAAC,gBAAgB,CAAA;AAAA,MAC1B,OAAO,CAAA,GAAI,QAAA,CAAS,CAAC,gBAAA,EAAkB,UAAU,CAAC,CAAA;AAAA,MAClD,cAAc,IAAA,CAAK;AAAA,QACjB,GAAA,EAAK,iBAAiB,WAAA,EAAY;AAAA,QAClC,EAAA,EAAI,WAAW,WAAA;AAAY,OAC5B,CAAA,CAAE,GAAA;AAAA,QAAI,CAAC,EAAE,GAAA,EAAK,EAAA,EAAG,KAChB,QAAA,CAAS,M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;QACxB,CAAC;QAED,OAAO,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,CAAC,EAAE,WAAW,CAAC,CAAC;QAErD,WAAW,EAAE,CAAC;IAChB,CAAC,CACJ,CAAC;IAEF,UAAU,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;QAC7B,kBAAkB,GAAG,GAAG,CAAC,QAAQ,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
@@ -1,31 +1,86 @@
1
1
  import { Optional, pipe } from 'ts-data-forge';
2
- import { createSyncChildObservable } from '../base/create-child-observable.mjs';
3
- import '../utils/id-maker.mjs';
4
- import { maxDepth } from '../utils/max-depth.mjs';
5
-
6
- const withCurrentValueFrom = (observable) => (parentObservable) => createWithCurrentValueFromObservable(parentObservable, observable);
7
- const withLatestFrom = withCurrentValueFrom;
8
- const createWithCurrentValueFromObservable = (parentObservable, observable) => createSyncChildObservable(
9
- {
2
+ import { createSyncChildObservable } from '../base/index.mjs';
3
+ import { maxDepth } from '../utils/index.mjs';
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+ export const withCurrentValueFrom = (observable) => (parentObservable) => createWithCurrentValueFromObservable(parentObservable, observable);
61
+
62
+
63
+
64
+
65
+ export const withLatestFrom = withCurrentValueFrom;
66
+ const createWithCurrentValueFromObservable = (parentObservable, observable) => createSyncChildObservable({
10
67
  parents: [parentObservable],
11
68
  depth: 1 + maxDepth([parentObservable, observable]),
12
69
  initialValue: pipe({
13
- par: parentObservable.getSnapshot(),
14
- me: observable.getSnapshot()
15
- }).map(
16
- ({ me, par }) => Optional.isNone(par) || Optional.isNone(me) ? Optional.none : Optional.some([par.value, me.value])
17
- ).value
18
- },
19
- ({ setNext }) => (updateToken) => {
70
+ par: parentObservable.getSnapshot(),
71
+ me: observable.getSnapshot(),
72
+ }).map(({ me, par }) => Optional.isNone(par) || Optional.isNone(me)
73
+ ? Optional.none
74
+ : Optional.some([par.value, me.value])).value,
75
+ }, ({ setNext }) => (updateToken) => {
20
76
  const ps = parentObservable.getSnapshot();
21
- if (parentObservable.updateToken !== updateToken || Optional.isNone(ps)) {
22
- return;
77
+ if (parentObservable.updateToken !== updateToken ||
78
+ Optional.isNone(ps)) {
79
+ return;
23
80
  }
24
81
  const curr = observable.getSnapshot();
25
- if (Optional.isNone(curr)) return;
82
+ if (Optional.isNone(curr))
83
+ return;
26
84
  setNext([ps.value, curr.value], updateToken);
27
- }
28
- );
29
-
30
- export { withCurrentValueFrom, withLatestFrom };
31
- //# sourceMappingURL=with-current-value-from.mjs.map
85
+ });
86
+ //# sourceMappingURL=with-current-value-from.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"with-current-value-from.mjs","sources":["../../../src/core/operators/with-current-value-from.mts"],"sourcesContent":["import { Optional, pipe } from 'ts-data-forge';\nimport { createSyncChildObservable } from '../base/index.mjs';\nimport {\n type DropInitialValueOperator,\n type Observable,\n type WithCurrentValueFromOperatorObservable,\n} from '../types/index.mjs';\nimport { maxDepth } from '../utils/index.mjs';\n\n/**\n * Samples the current value from another observable each time the source emits.\n * Emits a tuple of [sourceValue, sampledValue].\n *\n * @template A - The type of values from the source observable\n * @template B - The type of values from the sampled observable\n * @param observable - The observable to sample from\n * @returns An operator that emits tuples of source and sampled values\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // name$ \"Alice\" \"Bob\" \"Charlie\"\n * // age$ 25 30\n * // result$ (skip) [\"Bob\",25] [\"Charlie\",30]\n * //\n * // Explanation:\n * // - withCurrentValueFrom samples the current value from another observable\n * // - Emits a tuple [sourceValue, sampledValue] each time the SOURCE emits\n * // - Does NOT emit when the sampled observable (age$) emits\n * // - Does not emit until both observables have emitted at least once\n * // - \"Alice\" is skipped because age$ hasn't emitted yet\n *\n * const name$ = source<string>();\n *\n * const age$ = source<number>();\n *\n * const result$ = name$.pipe(withCurrentValueFrom(age$));\n *\n * const valueHistory: (readonly [string, number])[] = [];\n *\n * result$.subscribe(([name_, currentAge]) => {\n * valueHistory.push([name_, currentAge]);\n * });\n *\n * name$.next('Alice'); // nothing logged (age$ hasn't emitted)\n *\n * assert.deepStrictEqual(valueHistory, []);\n *\n * age$.next(25);\n *\n * name$.next('Bob'); // logs: Bob is 25 years old\n *\n * assert.deepStrictEqual(valueHistory, [['Bob', 25]]);\n *\n * age$.next(30);\n *\n * name$.next('Charlie'); // logs: Charlie is 30 years old\n *\n * assert.deepStrictEqual(valueHistory, [\n * ['Bob', 25],\n * ['Charlie', 30],\n * ]);\n * ```\n */\nexport const withCurrentValueFrom =\n <A, B>(\n observable: Observable<B>,\n ): DropInitialValueOperator<A, readonly [A, B]> =>\n (parentObservable) =>\n createWithCurrentValueFromObservable(parentObservable, observable);\n\n/**\n * Alias for `withCurrentValueFrom`.\n * @see withCurrentValueFrom\n */\nexport const withLatestFrom = withCurrentValueFrom;\n\nconst createWithCurrentValueFromObservable = <A, B>(\n parentObservable: Observable<A>,\n observable: Observable<B>,\n): WithCurrentValueFromOperatorObservable<A, B> =>\n createSyncChildObservable<readonly [A, B], readonly [A]>(\n {\n parents: [parentObservable],\n depth: 1 + maxDepth([parentObservable, observable]),\n initialValue: pipe({\n par: parentObservable.getSnapshot(),\n me: observable.getSnapshot(),\n }).map(({ me, par }) =>\n Optional.isNone(par) || Optional.isNone(me)\n ? Optional.none\n : Optional.some([par.value, me.value] as const),\n ).value,\n },\n ({ setNext }) =>\n (updateToken) => {\n const ps = parentObservable.getSnapshot();\n\n if (\n parentObservable.updateToken !== updateToken ||\n Optional.isNone(ps)\n ) {\n return; // skip update\n }\n\n const curr = observable.getSnapshot();\n\n if (Optional.isNone(curr)) return; // skip update\n\n setNext([ps.value, curr.value], updateToken);\n },\n );\n"],"names":[],"mappings":";;;;;AAiEO,MAAM,uBACX,CACE,UAAA,KAEF,CAAC,gBAAA,KACC,oCAAA,CAAqC,kBAAkB,UAAU;AAM9D,MAAM,cAAA,GAAiB;AAE9B,MAAM,oCAAA,GAAuC,CAC3C,gBAAA,EACA,UAAA,KAEA,yBAAA;AAAA,EACE;AAAA,IACE,OAAA,EAAS,CAAC,gBAAgB,CAAA;AAAA,IAC1B,OAAO,CAAA,GAAI,QAAA,CAAS,CAAC,gBAAA,EAAkB,UAAU,CAAC,CAAA;AAAA,IAClD,cAAc,IAAA,CAAK;AAAA,MACjB,GAAA,EAAK,iBAAiB,WAAA,EAAY;AAAA,MAClC,EAAA,EAAI,WAAW,WAAA;AAAY,KAC5B,CAAA,CAAE,GAAA;AAAA,MAAI,CAAC,EAAE,EAAA,EAAI,GAAA,OACZ,QAAA,CAAS,MAAA,CAAO,GAAG,CAAA,IAAK,QAAA,CAAS,MAAA,CAAO,EAAE,CAAA,GACtC,QAAA,CAAS,OACT,QAAA,CAAS,IAAA,CAAK,CAAC,GAAA,CAAI,KAAA,EAAO,EAAA,CAAG,KAAK,CAAU;AAAA,KAClD,CAAE;AAAA,GACJ;AAAA,EACA,CAAC,EAAE,OAAA,EAAQ,KACT,CAAC,WAAA,KAAgB;AACf,IAAA,MAAM,EAAA,GAAK,iBAAiB,WAAA,EAAY;AAExC,IAAA,IACE,iBAAiB,WAAA,KAAgB,WAAA,IACjC,QAAA,CAAS,MAAA,CAAO,EAAE,CAAA,EAClB;AACA,MAAA;AAAA,IACF;AAEA,IAAA,MAAM,IAAA,GAAO,WAAW,WAAA,EAAY;AAEpC,IAAA,IAAI,QAAA,CAAS,MAAA,CAAO,IAAI,CAAA,EAAG;AAE3B,IAAA,OAAA,CAAQ,CAAC,EAAA,CAAG,KAAA,EAAO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KAAK,CAAU,CAAC,CAClD,CAAC,KAAK;CACR,EACD,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CACd,CAAC,WAAW,EAAE,EAAE;IACd,MAAM,EAAE,GAAG,gBAAgB,CAAC,WAAW,EAAE,CAAC;IAE1C,IACE,gBAAgB,CAAC,WAAW,KAAK,WAAW;QAC5C,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EACnB,CAAC;QACD,OAAO,CAAC,cAAc;IACxB,CAAC;IAED,MAAM,IAAI,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;IAEtC,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;QAAE,OAAO,CAAC,cAAc;IAEjD,OAAO,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC,CAAC;AAC/C,CAAC,CACJ,CAAC"}
@@ -1,21 +1,71 @@
1
1
  import { Optional } from 'ts-data-forge';
2
- import { createInitializedSyncChildObservable } from '../base/create-child-observable.mjs';
3
- import '../utils/id-maker.mjs';
2
+ import { createInitializedSyncChildObservable } from '../base/index.mjs';
4
3
 
5
- const withInitialValue = (initialValue) => (parentObservable) => createWithInitialValueObservable(parentObservable, initialValue);
6
- const createWithInitialValueObservable = (parentObservable, initialValue) => createInitializedSyncChildObservable(
7
- {
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+ export const withInitialValue = (initialValue) => (parentObservable) => createWithInitialValueObservable(parentObservable, initialValue);
50
+ const createWithInitialValueObservable = (parentObservable, initialValue) => createInitializedSyncChildObservable({
8
51
  parents: [parentObservable],
9
- initialValue: Optional.some(initialValue)
10
- },
11
- ({ setNext }) => (updateToken) => {
52
+ initialValue: Optional.some(initialValue),
53
+ }, ({ setNext }) => (updateToken) => {
12
54
  const sn = parentObservable.getSnapshot();
13
- if (parentObservable.updateToken !== updateToken || Optional.isNone(sn)) {
14
- return;
55
+ if (parentObservable.updateToken !== updateToken ||
56
+ Optional.isNone(sn)) {
57
+ return;
15
58
  }
16
59
  setNext(sn.value, updateToken);
17
- }
18
- );
60
+ });
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
19
70
 
20
- export { withInitialValue };
21
- //# sourceMappingURL=with-initial-value.mjs.map
71
+ //# sourceMappingURL=with-initial-value.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"with-initial-value.mjs","sources":["../../../src/core/operators/with-initial-value.mts"],"sourcesContent":["import { expectType, Optional } from 'ts-data-forge';\nimport { createInitializedSyncChildObservable } from '../base/index.mjs';\nimport { source } from '../create/index.mjs';\nimport {\n type InitializedObservable,\n type Observable,\n type WithInitialValueOperator,\n type WithInitialValueOperatorObservable,\n} from '../types/index.mjs';\n\n/**\n * Provides an initial value for an observable that doesn't have one.\n * The resulting observable will immediately emit the initial value upon subscription,\n * and then emit all subsequent values from the source.\n *\n * @template A - The type of values from the source\n * @template I - The type of the initial value (defaults to A)\n * @param initialValue - The initial value to emit\n * @returns An operator that sets the initial value\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // num$ 1 2 3\n * // withInitial$ 0 1 2 3\n * // ^\n * // initial value\n * //\n * // Explanation:\n * // - withInitialValue provides an initial value before the source emits\n * // - Converts an uninitialized observable to an initialized one\n * // - Useful when you need a default value immediately\n *\n * const num$ = source<number>();\n *\n * const initialized$ = num$.pipe(withInitialValue(0));\n *\n * const valueHistory: number[] = [];\n *\n * initialized$.subscribe((x) => {\n * valueHistory.push(x);\n * });\n *\n * assert.deepStrictEqual(valueHistory, [0]);\n *\n * num$.next(1); // logs: 1\n *\n * assert.deepStrictEqual(valueHistory, [0, 1]);\n *\n * num$.next(2); // logs: 2\n *\n * assert.deepStrictEqual(valueHistory, [0, 1, 2]);\n * ```\n */\nexport const withInitialValue =\n <A, I = A>(initialValue: I): WithInitialValueOperator<A, A | I> =>\n (parentObservable) =>\n createWithInitialValueObservable(parentObservable, initialValue);\n\nconst createWithInitialValueObservable = <A, I>(\n parentObservable: Observable<A>,\n initialValue: I,\n): WithInitialValueOperatorObservable<A, I> =>\n createInitializedSyncChildObservable<A | I, readonly [A]>(\n {\n parents: [parentObservable],\n initialValue: Optional.some(initialValue),\n },\n ({ setNext }) =>\n (updateToken) => {\n const sn = parentObservable.getSnapshot();\n\n if (\n parentObservable.updateToken !== updateToken ||\n Optional.isNone(sn)\n ) {\n return; // skip update\n }\n\n setNext(sn.value, updateToken);\n },\n );\n\nif (import.meta.vitest !== undefined) {\n test('type test', () => {\n expect(1).toBe(1); // dummy\n });\n\n {\n const s = source<number>();\n\n const _d: InitializedObservable<number> = s.pipe(withInitialValue(0));\n\n expectType<typeof _d, InitializedObservable<number>>('=');\n }\n}\n"],"names":[],"mappings":";;;;AAuDO,MAAM,mBACX,CAAW,YAAA,KACX,CAAC,gBAAA,KACC,gCAAA,CAAiC,kBAAkB,YAAY;AAEnE,MAAM,gCAAA,GAAmC,CACvC,gBAAA,EACA,YAAA,KAEA,oCAAA;AAAA,EACE;AAAA,IACE,OAAA,EAAS,CAAC,gBAAgB,CAAA;AAAA,IAC1B,YAAA,EAAc,QAAA,CAAS,IAAA,CAAK,YAAY;AAAA,GAC1C;AAAA,EACA,CAAC,EAAE,OAAA,EAAQ,KACT,CAAC,WAAA,KAAgB;AACf,IAAA,MAAM,EAAA,GAAK,iBAAiB,WAAA,EAAY;AAExC,IAAA,IACE,iBAAiB,WAAA,KAAgB,WAAA,IACjC,QAAA,CAAS,MAAA,CAAO,EAAE,CAAA,EAClB;AACA,MAAA;AAAA,IAAA;AAGF,IAAA,OAAA,CAAQ,EAAA,CAAG,OAAO,WAAW,CAAA;AAAA,EAAA;AAEnC,CAAA;;;;"}
1
+ {"version":3,"file":"with-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AU,CAAC;QAE3B,MAAM,EAAE,GAAkC,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;QAEtE,UAAU,CAA2C,GAAG,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC"}
@@ -1,12 +1,2 @@
1
- export { attachIndex, withIndex } from './operators/attach-index.mjs';
2
- export { mapOptional } from './operators/map-optional.mjs';
3
- export { mapResultErr } from './operators/map-result-err.mjs';
4
- export { mapResultOk } from './operators/map-result-ok.mjs';
5
- export { mapTo } from './operators/map-to.mjs';
6
- export { getKey, pluck } from './operators/pluck.mjs';
7
- export { skip } from './operators/skip.mjs';
8
- export { take } from './operators/take.mjs';
9
- export { unwrapOptional } from './operators/unwrap-optional.mjs';
10
- export { unwrapResultErr } from './operators/unwrap-result-err.mjs';
11
- export { unwrapResultOk } from './operators/unwrap-result-ok.mjs';
12
- //# sourceMappingURL=index.mjs.map
1
+ export * from './operators/index.mjs';
2
+ //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/core/predefined/index.mts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}