@ringcentral/juno 2.40.1 → 2.41.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 (178) hide show
  1. package/components/Downshift/SuggestionList/SuggestionList.d.ts +3 -3
  2. package/components/Downshift/utils/useDownshift.d.ts +1 -1
  3. package/components/Virtuoso/index.d.ts +1 -1
  4. package/components/Virtuoso/index.js +1 -1
  5. package/components/Virtuoso/react-virtuoso/AATree.d.ts +1 -1
  6. package/components/Virtuoso/react-virtuoso/AATree.js +60 -48
  7. package/components/Virtuoso/react-virtuoso/TableVirtuoso.d.ts +5 -0
  8. package/components/Virtuoso/react-virtuoso/TableVirtuoso.js +217 -0
  9. package/components/Virtuoso/react-virtuoso/Virtuoso.d.ts +7696 -0
  10. package/components/Virtuoso/react-virtuoso/Virtuoso.js +317 -0
  11. package/components/Virtuoso/react-virtuoso/{Grid.d.ts → VirtuosoGrid.d.ts} +170 -72
  12. package/components/Virtuoso/react-virtuoso/VirtuosoGrid.js +199 -0
  13. package/components/Virtuoso/react-virtuoso/alignToBottomSystem.d.ts +119 -65
  14. package/components/Virtuoso/react-virtuoso/alignToBottomSystem.js +3 -3
  15. package/components/Virtuoso/react-virtuoso/comparators.d.ts +1 -1
  16. package/components/Virtuoso/react-virtuoso/comparators.js +1 -3
  17. package/components/Virtuoso/react-virtuoso/component-interfaces/TableVirtuoso.d.ts +194 -0
  18. package/components/Virtuoso/react-virtuoso/component-interfaces/TableVirtuoso.js +2 -0
  19. package/components/Virtuoso/react-virtuoso/component-interfaces/Virtuoso.d.ts +274 -0
  20. package/components/Virtuoso/react-virtuoso/component-interfaces/Virtuoso.js +2 -0
  21. package/components/Virtuoso/react-virtuoso/component-interfaces/VirtuosoGrid.d.ts +125 -0
  22. package/components/Virtuoso/react-virtuoso/component-interfaces/VirtuosoGrid.js +2 -0
  23. package/components/Virtuoso/react-virtuoso/domIOSystem.d.ts +3 -2
  24. package/components/Virtuoso/react-virtuoso/domIOSystem.js +5 -3
  25. package/components/Virtuoso/react-virtuoso/followOutputSystem.d.ts +80 -43
  26. package/components/Virtuoso/react-virtuoso/followOutputSystem.js +21 -19
  27. package/components/Virtuoso/react-virtuoso/gridSystem.d.ts +57 -31
  28. package/components/Virtuoso/react-virtuoso/gridSystem.js +173 -86
  29. package/components/Virtuoso/react-virtuoso/groupedListSystem.d.ts +76 -67
  30. package/components/Virtuoso/react-virtuoso/groupedListSystem.js +12 -12
  31. package/components/Virtuoso/react-virtuoso/hooks/useChangedChildSizes.d.ts +6 -3
  32. package/components/Virtuoso/react-virtuoso/hooks/useChangedChildSizes.js +36 -17
  33. package/components/Virtuoso/react-virtuoso/hooks/useIsomorphicLayoutEffect.d.ts +2 -2
  34. package/components/Virtuoso/react-virtuoso/hooks/useIsomorphicLayoutEffect.js +3 -2
  35. package/components/Virtuoso/react-virtuoso/hooks/useRcPortalWindowContext.d.ts +2 -0
  36. package/components/Virtuoso/react-virtuoso/hooks/useRcPortalWindowContext.js +5 -0
  37. package/components/Virtuoso/react-virtuoso/hooks/useScrollTop.d.ts +2 -3
  38. package/components/Virtuoso/react-virtuoso/hooks/useScrollTop.js +36 -51
  39. package/components/Virtuoso/react-virtuoso/hooks/useSize.d.ts +2 -3
  40. package/components/Virtuoso/react-virtuoso/hooks/useSize.js +13 -13
  41. package/components/Virtuoso/react-virtuoso/hooks/useWindowViewportRect.js +17 -15
  42. package/components/Virtuoso/react-virtuoso/index.d.ts +7 -1
  43. package/components/Virtuoso/react-virtuoso/index.js +8 -1
  44. package/components/Virtuoso/react-virtuoso/initialItemCountSystem.d.ts +304 -68
  45. package/components/Virtuoso/react-virtuoso/initialItemCountSystem.js +9 -31
  46. package/components/Virtuoso/react-virtuoso/initialScrollTopSystem.d.ts +127 -109
  47. package/components/Virtuoso/react-virtuoso/initialScrollTopSystem.js +7 -7
  48. package/components/Virtuoso/react-virtuoso/initialTopMostItemIndexSystem.d.ts +38 -22
  49. package/components/Virtuoso/react-virtuoso/initialTopMostItemIndexSystem.js +13 -20
  50. package/components/Virtuoso/react-virtuoso/interfaces.d.ts +150 -51
  51. package/components/Virtuoso/react-virtuoso/listStateSystem.d.ts +109 -59
  52. package/components/Virtuoso/react-virtuoso/listStateSystem.js +100 -52
  53. package/components/Virtuoso/react-virtuoso/listSystem.d.ts +1691 -693
  54. package/components/Virtuoso/react-virtuoso/listSystem.js +15 -16
  55. package/components/Virtuoso/react-virtuoso/loggerSystem.d.ts +1 -1
  56. package/components/Virtuoso/react-virtuoso/loggerSystem.js +2 -4
  57. package/components/Virtuoso/react-virtuoso/propsReadySystem.d.ts +1 -1
  58. package/components/Virtuoso/react-virtuoso/propsReadySystem.js +3 -4
  59. package/components/Virtuoso/react-virtuoso/react-urx/index.d.ts +110 -0
  60. package/components/Virtuoso/react-virtuoso/react-urx/index.js +200 -0
  61. package/components/Virtuoso/react-virtuoso/react-urx/package.json +5 -0
  62. package/components/Virtuoso/react-virtuoso/recalcSystem.d.ts +4 -0
  63. package/components/Virtuoso/react-virtuoso/recalcSystem.js +8 -0
  64. package/components/Virtuoso/react-virtuoso/scrollIntoViewSystem.d.ts +144 -78
  65. package/components/Virtuoso/react-virtuoso/scrollIntoViewSystem.js +33 -21
  66. package/components/Virtuoso/react-virtuoso/scrollSeekSystem.d.ts +12 -7
  67. package/components/Virtuoso/react-virtuoso/scrollSeekSystem.js +7 -10
  68. package/components/Virtuoso/react-virtuoso/scrollToIndexSystem.d.ts +19 -11
  69. package/components/Virtuoso/react-virtuoso/scrollToIndexSystem.js +11 -23
  70. package/components/Virtuoso/react-virtuoso/sizeRangeSystem.d.ts +7 -6
  71. package/components/Virtuoso/react-virtuoso/sizeRangeSystem.js +15 -27
  72. package/components/Virtuoso/react-virtuoso/sizeSystem.d.ts +20 -11
  73. package/components/Virtuoso/react-virtuoso/sizeSystem.js +182 -52
  74. package/components/Virtuoso/react-virtuoso/stateFlagsSystem.d.ts +8 -5
  75. package/components/Virtuoso/react-virtuoso/stateFlagsSystem.js +32 -23
  76. package/components/Virtuoso/react-virtuoso/stateLoadSystem.d.ts +318 -0
  77. package/components/Virtuoso/react-virtuoso/stateLoadSystem.js +41 -0
  78. package/components/Virtuoso/react-virtuoso/topItemCountSystem.d.ts +518 -467
  79. package/components/Virtuoso/react-virtuoso/topItemCountSystem.js +5 -5
  80. package/components/Virtuoso/react-virtuoso/totalListHeightSystem.d.ts +115 -63
  81. package/components/Virtuoso/react-virtuoso/totalListHeightSystem.js +6 -13
  82. package/components/Virtuoso/react-virtuoso/upwardScrollFixSystem.d.ts +139 -73
  83. package/components/Virtuoso/react-virtuoso/upwardScrollFixSystem.js +74 -31
  84. package/components/Virtuoso/react-virtuoso/urx/actions.d.ts +127 -0
  85. package/components/Virtuoso/react-virtuoso/urx/actions.js +98 -0
  86. package/components/Virtuoso/react-virtuoso/urx/constants.d.ts +8 -0
  87. package/components/Virtuoso/react-virtuoso/urx/constants.js +6 -0
  88. package/components/Virtuoso/react-virtuoso/urx/index.d.ts +6 -0
  89. package/components/Virtuoso/react-virtuoso/urx/index.js +9 -0
  90. package/components/Virtuoso/react-virtuoso/urx/package.json +5 -0
  91. package/components/Virtuoso/react-virtuoso/urx/pipe.d.ts +220 -0
  92. package/components/Virtuoso/react-virtuoso/urx/pipe.js +279 -0
  93. package/components/Virtuoso/react-virtuoso/urx/streams.d.ts +143 -0
  94. package/components/Virtuoso/react-virtuoso/urx/streams.js +227 -0
  95. package/components/Virtuoso/react-virtuoso/urx/system.d.ts +148 -0
  96. package/components/Virtuoso/react-virtuoso/urx/system.js +106 -0
  97. package/components/Virtuoso/react-virtuoso/urx/transformers.d.ts +71 -0
  98. package/components/Virtuoso/react-virtuoso/urx/transformers.js +106 -0
  99. package/components/Virtuoso/react-virtuoso/urx/utils.d.ts +57 -0
  100. package/components/Virtuoso/react-virtuoso/urx/utils.js +102 -0
  101. package/components/Virtuoso/react-virtuoso/utils/approximatelyEqual.d.ts +1 -0
  102. package/components/Virtuoso/react-virtuoso/utils/approximatelyEqual.js +6 -0
  103. package/components/Virtuoso/react-virtuoso/utils/context.d.ts +13 -0
  104. package/components/Virtuoso/react-virtuoso/utils/context.js +6 -0
  105. package/components/Virtuoso/react-virtuoso/utils/skipFrames.d.ts +1 -0
  106. package/components/Virtuoso/react-virtuoso/utils/skipFrames.js +11 -0
  107. package/components/Virtuoso/react-virtuoso/windowScrollerSystem.d.ts +6 -4
  108. package/components/Virtuoso/react-virtuoso/windowScrollerSystem.js +1 -1
  109. package/components/Virtuoso/utils/isOutOfRange.d.ts +1 -1
  110. package/components/Virtuoso/utils/useHighlightScroll.d.ts +2 -2
  111. package/es6/components/Virtuoso/index.js +1 -1
  112. package/es6/components/Virtuoso/react-virtuoso/AATree.js +60 -48
  113. package/es6/components/Virtuoso/react-virtuoso/{Table.js → TableVirtuoso.js} +73 -52
  114. package/es6/components/Virtuoso/react-virtuoso/{List.js → Virtuoso.js} +85 -161
  115. package/es6/components/Virtuoso/react-virtuoso/VirtuosoGrid.js +198 -0
  116. package/es6/components/Virtuoso/react-virtuoso/alignToBottomSystem.js +3 -3
  117. package/es6/components/Virtuoso/react-virtuoso/comparators.js +1 -3
  118. package/es6/components/Virtuoso/react-virtuoso/component-interfaces/TableVirtuoso.js +0 -0
  119. package/es6/components/Virtuoso/react-virtuoso/component-interfaces/Virtuoso.js +0 -0
  120. package/es6/components/Virtuoso/react-virtuoso/component-interfaces/VirtuosoGrid.js +0 -0
  121. package/es6/components/Virtuoso/react-virtuoso/domIOSystem.js +5 -3
  122. package/es6/components/Virtuoso/react-virtuoso/followOutputSystem.js +21 -19
  123. package/es6/components/Virtuoso/react-virtuoso/gridSystem.js +173 -87
  124. package/es6/components/Virtuoso/react-virtuoso/groupedListSystem.js +13 -13
  125. package/es6/components/Virtuoso/react-virtuoso/hooks/useChangedChildSizes.js +35 -16
  126. package/es6/components/Virtuoso/react-virtuoso/hooks/useIsomorphicLayoutEffect.js +2 -2
  127. package/es6/components/Virtuoso/react-virtuoso/hooks/useRcPortalWindowContext.js +2 -0
  128. package/es6/components/Virtuoso/react-virtuoso/hooks/useScrollTop.js +35 -50
  129. package/es6/components/Virtuoso/react-virtuoso/hooks/useSize.js +11 -12
  130. package/es6/components/Virtuoso/react-virtuoso/hooks/useWindowViewportRect.js +15 -14
  131. package/es6/components/Virtuoso/react-virtuoso/index.js +4 -1
  132. package/es6/components/Virtuoso/react-virtuoso/initialItemCountSystem.js +11 -33
  133. package/es6/components/Virtuoso/react-virtuoso/initialScrollTopSystem.js +7 -7
  134. package/es6/components/Virtuoso/react-virtuoso/initialTopMostItemIndexSystem.js +13 -20
  135. package/es6/components/Virtuoso/react-virtuoso/listStateSystem.js +101 -54
  136. package/es6/components/Virtuoso/react-virtuoso/listSystem.js +15 -16
  137. package/es6/components/Virtuoso/react-virtuoso/loggerSystem.js +2 -4
  138. package/es6/components/Virtuoso/react-virtuoso/propsReadySystem.js +3 -4
  139. package/es6/components/Virtuoso/react-virtuoso/react-urx/index.js +197 -0
  140. package/es6/components/Virtuoso/react-virtuoso/recalcSystem.js +5 -0
  141. package/es6/components/Virtuoso/react-virtuoso/scrollIntoViewSystem.js +34 -22
  142. package/es6/components/Virtuoso/react-virtuoso/scrollSeekSystem.js +7 -10
  143. package/es6/components/Virtuoso/react-virtuoso/scrollToIndexSystem.js +11 -23
  144. package/es6/components/Virtuoso/react-virtuoso/sizeRangeSystem.js +16 -28
  145. package/es6/components/Virtuoso/react-virtuoso/sizeSystem.js +180 -53
  146. package/es6/components/Virtuoso/react-virtuoso/stateFlagsSystem.js +32 -23
  147. package/es6/components/Virtuoso/react-virtuoso/stateLoadSystem.js +39 -0
  148. package/es6/components/Virtuoso/react-virtuoso/topItemCountSystem.js +5 -5
  149. package/es6/components/Virtuoso/react-virtuoso/totalListHeightSystem.js +6 -13
  150. package/es6/components/Virtuoso/react-virtuoso/upwardScrollFixSystem.js +75 -32
  151. package/es6/components/Virtuoso/react-virtuoso/urx/actions.js +90 -0
  152. package/es6/components/Virtuoso/react-virtuoso/urx/constants.js +4 -0
  153. package/es6/components/Virtuoso/react-virtuoso/urx/index.js +6 -0
  154. package/es6/components/Virtuoso/react-virtuoso/urx/pipe.js +266 -0
  155. package/es6/components/Virtuoso/react-virtuoso/urx/streams.js +220 -0
  156. package/es6/components/Virtuoso/react-virtuoso/urx/system.js +102 -0
  157. package/es6/components/Virtuoso/react-virtuoso/urx/transformers.js +101 -0
  158. package/es6/components/Virtuoso/react-virtuoso/urx/utils.js +88 -0
  159. package/es6/components/Virtuoso/react-virtuoso/utils/approximatelyEqual.js +3 -0
  160. package/es6/components/Virtuoso/react-virtuoso/utils/context.js +3 -0
  161. package/es6/components/Virtuoso/react-virtuoso/utils/skipFrames.js +8 -0
  162. package/es6/components/Virtuoso/react-virtuoso/windowScrollerSystem.js +1 -1
  163. package/package.json +2 -2
  164. package/components/Virtuoso/Virtuoso.d.ts +0 -1
  165. package/components/Virtuoso/Virtuoso.js +0 -4
  166. package/components/Virtuoso/react-virtuoso/Grid.js +0 -168
  167. package/components/Virtuoso/react-virtuoso/List.d.ts +0 -6749
  168. package/components/Virtuoso/react-virtuoso/List.js +0 -393
  169. package/components/Virtuoso/react-virtuoso/Table.d.ts +0 -6515
  170. package/components/Virtuoso/react-virtuoso/Table.js +0 -196
  171. package/components/Virtuoso/react-virtuoso/components.d.ts +0 -505
  172. package/components/Virtuoso/react-virtuoso/components.js +0 -9
  173. package/components/Virtuoso/react-virtuoso/utils/conditionalFlushSync.d.ts +0 -1
  174. package/components/Virtuoso/react-virtuoso/utils/conditionalFlushSync.js +0 -11
  175. package/es6/components/Virtuoso/Virtuoso.js +0 -1
  176. package/es6/components/Virtuoso/react-virtuoso/Grid.js +0 -166
  177. package/es6/components/Virtuoso/react-virtuoso/components.js +0 -7
  178. package/es6/components/Virtuoso/react-virtuoso/utils/conditionalFlushSync.js +0 -8
@@ -0,0 +1,279 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var tslib_1 = require("tslib");
4
+ /**
5
+ *
6
+ * Stream values can be transformed and controlled by {@link pipe | **piping**} through **operators**.
7
+ * urx includes several operators like [[map]], [[filter]], [[scan]], and [[throttleTime]].
8
+ * The [[withLatestFrom]] operator allows the combination of values from other streams.
9
+ *
10
+ * ```ts
11
+ * const foo = stream<number>()
12
+ *
13
+ * // create an emitter that first adds 2 to the passed value, then multiplies it by * 2
14
+ * const bar = pipe(foo, map(value => value + 2), map(value => value * 2))
15
+ * subscribe(bar, value => console.log(value))
16
+ * publish(foo, 2) // outputs 8
17
+ * ```
18
+ *
19
+ * ### Implementing Custom Operators
20
+ * To implement your own operators, implement the [[Operator]] interface.
21
+ * @packageDocumentation
22
+ */
23
+ var utils_1 = require("./utils");
24
+ var actions_1 = require("./actions");
25
+ var constants_1 = require("./constants");
26
+ /** @internal */
27
+ function combineOperators() {
28
+ var operators = [];
29
+ for (var _i = 0; _i < arguments.length; _i++) {
30
+ operators[_i] = arguments[_i];
31
+ }
32
+ return function (subscriber) {
33
+ return operators.reduceRight(utils_1.thrush, subscriber);
34
+ };
35
+ }
36
+ function pipe(source) {
37
+ var operators = [];
38
+ for (var _i = 1; _i < arguments.length; _i++) {
39
+ operators[_i - 1] = arguments[_i];
40
+ }
41
+ // prettier-ignore
42
+ var project = combineOperators.apply(void 0, tslib_1.__spread(operators));
43
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
44
+ return (function (action, subscription) {
45
+ switch (action) {
46
+ case constants_1.SUBSCRIBE:
47
+ return actions_1.subscribe(source, project(subscription));
48
+ case constants_1.RESET:
49
+ actions_1.reset(source);
50
+ return;
51
+ }
52
+ });
53
+ }
54
+ exports.pipe = pipe;
55
+ /**
56
+ * The default [[Comparator]] for [[distinctUntilChanged]] and [[duc]].
57
+ */
58
+ function defaultComparator(previous, next) {
59
+ return previous === next;
60
+ }
61
+ exports.defaultComparator = defaultComparator;
62
+ /**
63
+ * Filters out identical values. Pass an optional [[Comparator]] if you need to filter non-primitive values.
64
+ * ```ts
65
+ * const foo = stream<number>()
66
+ *
67
+ * subscribe(
68
+ * pipe(foo, distinctUntilChanged()),
69
+ * console.log
70
+ * ) // will be called only once
71
+ *
72
+ * publish(foo, 42)
73
+ * publish(foo, 42)
74
+ * ```
75
+ */
76
+ function distinctUntilChanged(comparator) {
77
+ if (comparator === void 0) { comparator = defaultComparator; }
78
+ var current;
79
+ return function (done) { return function (next) {
80
+ if (!comparator(current, next)) {
81
+ current = next;
82
+ done(next);
83
+ }
84
+ }; };
85
+ }
86
+ exports.distinctUntilChanged = distinctUntilChanged;
87
+ /**
88
+ * Filters out values for which the predicator does not return `true`-ish.
89
+ * ```ts
90
+ * const foo = stream<number>()
91
+ *
92
+ * subscribe(
93
+ * pipe(foo, filter(value => value % 2 === 0)),
94
+ * console.log
95
+ * ) // will be called only with even values
96
+ *
97
+ * publish(foo, 2)
98
+ * publish(foo, 3)
99
+ * publish(foo, 4)
100
+ * publish(foo, 5)
101
+ * ```
102
+ */
103
+ function filter(predicate) {
104
+ return function (done) { return function (value) {
105
+ predicate(value) && done(value);
106
+ }; };
107
+ }
108
+ exports.filter = filter;
109
+ /**
110
+ * Maps values using the provided project function.
111
+ * ```ts
112
+ * const foo = stream<number>()
113
+ *
114
+ * subscribe(
115
+ * pipe(foo, map(value => value * 2)),
116
+ * console.log
117
+ * ) // 4, 6
118
+ *
119
+ * publish(foo, 2)
120
+ * publish(foo, 3)
121
+ * ```
122
+ */
123
+ function map(project) {
124
+ return function (done) { return utils_1.compose(done, project); };
125
+ }
126
+ exports.map = map;
127
+ /**
128
+ * Maps values to the hard-coded value.
129
+ * ```ts
130
+ * const foo = stream<number>()
131
+ *
132
+ * subscribe(
133
+ * pipe(foo, mapTo(3)),
134
+ * console.log
135
+ * ) // 3, 3
136
+ *
137
+ * publish(foo, 1)
138
+ * publish(foo, 2)
139
+ * ```
140
+ */
141
+ function mapTo(value) {
142
+ return function (done) { return function () { return done(value); }; };
143
+ }
144
+ exports.mapTo = mapTo;
145
+ /**
146
+ * Works like Array#reduce.
147
+ * Applies an accumulator function on the emitter, and outputs intermediate result. Starts with the initial value.
148
+ * ```ts
149
+ * const foo = stream<number>()
150
+ *
151
+ * subscribe(
152
+ * pipe(foo, scan((acc, value) => acc + value, 2),
153
+ * console.log
154
+ * ) // 3, 5
155
+ *
156
+ * publish(foo, 1)
157
+ * publish(foo, 2)
158
+ * ```
159
+ */
160
+ function scan(scanner, initial) {
161
+ return function (done) { return function (value) { return done((initial = scanner(initial, value))); }; };
162
+ }
163
+ exports.scan = scan;
164
+ /**
165
+ * Skips the specified amount of values from the emitter.
166
+ * ```ts
167
+ * const foo = stream<number>()
168
+ *
169
+ * subscribe(
170
+ * pipe(foo, skip(2)),
171
+ * console.log
172
+ * ) // 3, 4
173
+ *
174
+ * publish(foo, 1) // skipped
175
+ * publish(foo, 2) // skipped
176
+ * publish(foo, 3)
177
+ * publish(foo, 4)
178
+ * ```
179
+ */
180
+ function skip(times) {
181
+ return function (done) { return function (value) {
182
+ times > 0 ? times-- : done(value);
183
+ }; };
184
+ }
185
+ exports.skip = skip;
186
+ /**
187
+ * Throttles flowing values at the provided interval in milliseconds.
188
+ * [Throttle VS Debounce in SO](https://stackoverflow.com/questions/25991367/difference-between-throttling-and-debouncing-a-function).
189
+ *
190
+ * ```ts
191
+ * const foo = stream<number>()
192
+ * publish(foo, 1)
193
+ *
194
+ * setTimeout(() => publish(foo, 2), 20)
195
+ * setTimeout(() => publish(foo, 3), 20)
196
+ *
197
+ * subscribe(pipe(foo, throttleTime(50)), val => {
198
+ * console.log(value); // 3
199
+ * })
200
+ * ```
201
+ */
202
+ function throttleTime(interval) {
203
+ var currentValue = null;
204
+ var timeout;
205
+ return function (done) { return function (value) {
206
+ currentValue = value;
207
+ if (timeout) {
208
+ return;
209
+ }
210
+ timeout = setTimeout(function () {
211
+ timeout = undefined;
212
+ done(currentValue);
213
+ }, interval);
214
+ }; };
215
+ }
216
+ exports.throttleTime = throttleTime;
217
+ /**
218
+ * Debounces flowing values at the provided interval in milliseconds.
219
+ * [Throttle VS Debounce in SO](https://stackoverflow.com/questions/25991367/difference-between-throttling-and-debouncing-a-function).
220
+ *
221
+ * ```ts
222
+ * const foo = stream<number>()
223
+ * publish(foo, 1)
224
+ *
225
+ * setTimeout(() => publish(foo, 2), 20)
226
+ * setTimeout(() => publish(foo, 3), 20)
227
+ *
228
+ * subscribe(pipe(foo, debounceTime(50)), val => {
229
+ * console.log(value); // 3
230
+ * })
231
+ * ```
232
+ */
233
+ function debounceTime(interval) {
234
+ var currentValue;
235
+ var timeout;
236
+ return function (done) { return function (value) {
237
+ currentValue = value;
238
+ if (timeout) {
239
+ clearTimeout(timeout);
240
+ }
241
+ timeout = setTimeout(function () {
242
+ done(currentValue);
243
+ }, interval);
244
+ }; };
245
+ }
246
+ exports.debounceTime = debounceTime;
247
+ function withLatestFrom() {
248
+ var sources = [];
249
+ for (var _i = 0; _i < arguments.length; _i++) {
250
+ sources[_i] = arguments[_i];
251
+ }
252
+ var values = new Array(sources.length);
253
+ var called = 0;
254
+ var pendingCall = null;
255
+ var allCalled = Math.pow(2, sources.length) - 1;
256
+ sources.forEach(function (source, index) {
257
+ var bit = Math.pow(2, index);
258
+ actions_1.subscribe(source, function (value) {
259
+ var prevCalled = called;
260
+ called = called | bit;
261
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
262
+ values[index] = value;
263
+ if (prevCalled !== allCalled && called === allCalled && pendingCall) {
264
+ pendingCall();
265
+ pendingCall = null;
266
+ }
267
+ });
268
+ });
269
+ return function (done) { return function (value) {
270
+ var call = function () { return done([value].concat(values)); };
271
+ if (called === allCalled) {
272
+ call();
273
+ }
274
+ else {
275
+ pendingCall = call;
276
+ }
277
+ }; };
278
+ }
279
+ exports.withLatestFrom = withLatestFrom;
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Streams are the basic building blocks of a reactive system. Think of them as the system permanent "data tubes".
3
+ *
4
+ * A stream acts as both an [[Emitter]] and [[Publisher]]. Each stream can have multiple {@link Subscription | Subscriptions}.
5
+ *
6
+ * urx streams are either **stateless** or **stateful**.
7
+ * Stateless streams emit data to existing subscriptions when published, without keeping track of it.
8
+ * Stateful streams remember the last published value and immediately publish it to new subscriptions.
9
+ *
10
+ * ```ts
11
+ * import { stream, statefulStream, publish, subscribe } from "@virtuoso.dev/urx";
12
+ *
13
+ * // foo is a stateless stream
14
+ * const foo = stream<number>();
15
+ *
16
+ * publish(foo, 42);
17
+ * // this subsription will not be called...
18
+ * subscribe(foo, (value) => console.log(value));
19
+ * // it will only catch published values after it
20
+ * publish(foo, 43);
21
+ *
22
+ * // stateful streams always start with an initial value
23
+ * const bar = statefulStream(42);
24
+ *
25
+ * // subscribing to a stateful stream
26
+ * // immediately calls the subscription with the current value
27
+ * subscribe(bar, (value) => console.log(value));
28
+ *
29
+ * // subsequent publishing works just like stateless streams
30
+ * publish(bar, 43);
31
+ * ```
32
+ * @packageDocumentation
33
+ */
34
+ import { Emitter, StatefulStream, Stream } from './actions';
35
+ /**
36
+ * Constructs a new stateless stream.
37
+ * ```ts
38
+ * const foo = stream<number>();
39
+ * ```
40
+ * @typeParam T the type of values to publish in the stream.
41
+ * @returns a [[Stream]]
42
+ */
43
+ export declare function stream<T>(): Stream<T>;
44
+ /**
45
+ * Constructs a new stateful stream.
46
+ * ```ts
47
+ * const foo = statefulStream(42);
48
+ * ```
49
+ * @param initial the initial value in the stream.
50
+ * @typeParam T the type of values to publish in the stream. If omitted, the function infers it from the initial value.
51
+ * @returns a [[StatefulStream]]
52
+ */
53
+ export declare function statefulStream<T>(initial: T): StatefulStream<T>;
54
+ /**
55
+ * Event handlers are special emitters which can have **at most one active subscription**.
56
+ * Subscribing to an event handler unsubscribes the previous subscription, if present.
57
+ * ```ts
58
+ * const foo = stream<number>();
59
+ * const fooEvent = eventHandler(foo);
60
+ *
61
+ * // will be called once with 42
62
+ * subscribe(fooEvent, (value) => console.log(`Sub 1 ${value}`));
63
+ * publish(foo, 42);
64
+ *
65
+ * // unsubscribes sub 1
66
+ * subscribe(fooEvent, (value) => console.log(`Sub 2 ${value}`));
67
+ * publish(foo, 43);
68
+ * ```
69
+ * @param emitter the source emitter.
70
+ * @returns the single-subscription emitter.
71
+ */
72
+ export declare function eventHandler<T>(emitter: Emitter<T>): Emitter<T>;
73
+ /**
74
+ * Creates and connects a "junction" stream to the specified emitter. Often used with [[pipe]], to avoid the multiple evaluation of operator sets.
75
+ *
76
+ * ```ts
77
+ * const foo = stream<number>();
78
+ *
79
+ * const fooX2 = pipe(
80
+ * foo,
81
+ * map((value) => {
82
+ * console.log(`multiplying ${value}`);
83
+ * return value * 2;
84
+ * })
85
+ * );
86
+ *
87
+ * subscribe(fooX2, (value) => console.log(value));
88
+ * subscribe(fooX2, (value) => console.log(value));
89
+ *
90
+ * publish(foo, 42); // executes the map operator twice for each subscription.
91
+ *
92
+ * const sharedFooX2 = streamFromEmitter(pipe(
93
+ * foo,
94
+ * map((value) => {
95
+ * console.log(`shared multiplying ${value}`);
96
+ * return value * 2;
97
+ * })
98
+ * ));
99
+ *
100
+ * subscribe(sharedFooX2, (value) => console.log(value));
101
+ * subscribe(sharedFooX2, (value) => console.log(value));
102
+ *
103
+ * publish(foo, 42);
104
+ *```
105
+ * @returns the resulting stream.
106
+ */
107
+ export declare function streamFromEmitter<T>(emitter: Emitter<T>): Stream<T>;
108
+ /**
109
+ * Creates and connects a "junction" stateful stream to the specified emitter. Often used with [[pipe]], to avoid the multiple evaluation of operator sets.
110
+ *
111
+ * ```ts
112
+ * const foo = stream<number>();
113
+ *
114
+ * const fooX2 = pipe(
115
+ * foo,
116
+ * map((value) => {
117
+ * console.log(`multiplying ${value}`);
118
+ * return value * 2;
119
+ * })
120
+ * );
121
+ *
122
+ * subscribe(fooX2, (value) => console.log(value));
123
+ * subscribe(fooX2, (value) => console.log(value));
124
+ *
125
+ * publish(foo, 42); // executes the map operator twice for each subscription.
126
+ *
127
+ * const sharedFooX2 = statefulStreamFromEmitter(pipe(
128
+ * foo,
129
+ * map((value) => {
130
+ * console.log(`shared multiplying ${value}`);
131
+ * return value * 2;
132
+ * })
133
+ * ), 42);
134
+ *
135
+ * subscribe(sharedFooX2, (value) => console.log(value));
136
+ * subscribe(sharedFooX2, (value) => console.log(value));
137
+ *
138
+ * publish(foo, 42);
139
+ *```
140
+ * @param initial the initial value in the stream.
141
+ * @returns the resulting stateful stream.
142
+ */
143
+ export declare function statefulStreamFromEmitter<T>(emitter: Emitter<T>, initial: T): StatefulStream<T>;
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
3
+ /* eslint-disable @typescript-eslint/no-unsafe-return */
4
+ /**
5
+ * Streams are the basic building blocks of a reactive system. Think of them as the system permanent "data tubes".
6
+ *
7
+ * A stream acts as both an [[Emitter]] and [[Publisher]]. Each stream can have multiple {@link Subscription | Subscriptions}.
8
+ *
9
+ * urx streams are either **stateless** or **stateful**.
10
+ * Stateless streams emit data to existing subscriptions when published, without keeping track of it.
11
+ * Stateful streams remember the last published value and immediately publish it to new subscriptions.
12
+ *
13
+ * ```ts
14
+ * import { stream, statefulStream, publish, subscribe } from "@virtuoso.dev/urx";
15
+ *
16
+ * // foo is a stateless stream
17
+ * const foo = stream<number>();
18
+ *
19
+ * publish(foo, 42);
20
+ * // this subsription will not be called...
21
+ * subscribe(foo, (value) => console.log(value));
22
+ * // it will only catch published values after it
23
+ * publish(foo, 43);
24
+ *
25
+ * // stateful streams always start with an initial value
26
+ * const bar = statefulStream(42);
27
+ *
28
+ * // subscribing to a stateful stream
29
+ * // immediately calls the subscription with the current value
30
+ * subscribe(bar, (value) => console.log(value));
31
+ *
32
+ * // subsequent publishing works just like stateless streams
33
+ * publish(bar, 43);
34
+ * ```
35
+ * @packageDocumentation
36
+ */
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ var actions_1 = require("./actions");
39
+ var constants_1 = require("./constants");
40
+ var utils_1 = require("./utils");
41
+ /**
42
+ * Constructs a new stateless stream.
43
+ * ```ts
44
+ * const foo = stream<number>();
45
+ * ```
46
+ * @typeParam T the type of values to publish in the stream.
47
+ * @returns a [[Stream]]
48
+ */
49
+ function stream() {
50
+ var subscriptions = [];
51
+ return (function (action, arg) {
52
+ switch (action) {
53
+ case constants_1.RESET:
54
+ subscriptions.splice(0, subscriptions.length);
55
+ return;
56
+ case constants_1.SUBSCRIBE:
57
+ subscriptions.push(arg);
58
+ return function () {
59
+ var indexOf = subscriptions.indexOf(arg);
60
+ if (indexOf > -1) {
61
+ subscriptions.splice(indexOf, 1);
62
+ }
63
+ };
64
+ case constants_1.PUBLISH:
65
+ subscriptions.slice().forEach(function (subscription) {
66
+ subscription(arg);
67
+ });
68
+ return;
69
+ default:
70
+ throw new Error("unrecognized action " + action);
71
+ }
72
+ });
73
+ }
74
+ exports.stream = stream;
75
+ /**
76
+ * Constructs a new stateful stream.
77
+ * ```ts
78
+ * const foo = statefulStream(42);
79
+ * ```
80
+ * @param initial the initial value in the stream.
81
+ * @typeParam T the type of values to publish in the stream. If omitted, the function infers it from the initial value.
82
+ * @returns a [[StatefulStream]]
83
+ */
84
+ function statefulStream(initial) {
85
+ var value = initial;
86
+ var innerSubject = stream();
87
+ return (function (action, arg) {
88
+ switch (action) {
89
+ case constants_1.SUBSCRIBE:
90
+ var subscription = arg;
91
+ subscription(value);
92
+ break;
93
+ case constants_1.PUBLISH:
94
+ value = arg;
95
+ break;
96
+ case constants_1.VALUE:
97
+ return value;
98
+ }
99
+ return innerSubject(action, arg);
100
+ });
101
+ }
102
+ exports.statefulStream = statefulStream;
103
+ /**
104
+ * Event handlers are special emitters which can have **at most one active subscription**.
105
+ * Subscribing to an event handler unsubscribes the previous subscription, if present.
106
+ * ```ts
107
+ * const foo = stream<number>();
108
+ * const fooEvent = eventHandler(foo);
109
+ *
110
+ * // will be called once with 42
111
+ * subscribe(fooEvent, (value) => console.log(`Sub 1 ${value}`));
112
+ * publish(foo, 42);
113
+ *
114
+ * // unsubscribes sub 1
115
+ * subscribe(fooEvent, (value) => console.log(`Sub 2 ${value}`));
116
+ * publish(foo, 43);
117
+ * ```
118
+ * @param emitter the source emitter.
119
+ * @returns the single-subscription emitter.
120
+ */
121
+ function eventHandler(emitter) {
122
+ var unsub;
123
+ var currentSubscription;
124
+ var cleanup = function () { return unsub && unsub(); };
125
+ return function (action, subscription) {
126
+ switch (action) {
127
+ case constants_1.SUBSCRIBE:
128
+ if (subscription) {
129
+ if (currentSubscription === subscription) {
130
+ return;
131
+ }
132
+ cleanup();
133
+ currentSubscription = subscription;
134
+ unsub = actions_1.subscribe(emitter, subscription);
135
+ return unsub;
136
+ }
137
+ else {
138
+ cleanup();
139
+ return utils_1.noop;
140
+ }
141
+ case constants_1.RESET:
142
+ cleanup();
143
+ currentSubscription = null;
144
+ return;
145
+ default:
146
+ throw new Error("unrecognized action " + action);
147
+ }
148
+ };
149
+ }
150
+ exports.eventHandler = eventHandler;
151
+ /**
152
+ * Creates and connects a "junction" stream to the specified emitter. Often used with [[pipe]], to avoid the multiple evaluation of operator sets.
153
+ *
154
+ * ```ts
155
+ * const foo = stream<number>();
156
+ *
157
+ * const fooX2 = pipe(
158
+ * foo,
159
+ * map((value) => {
160
+ * console.log(`multiplying ${value}`);
161
+ * return value * 2;
162
+ * })
163
+ * );
164
+ *
165
+ * subscribe(fooX2, (value) => console.log(value));
166
+ * subscribe(fooX2, (value) => console.log(value));
167
+ *
168
+ * publish(foo, 42); // executes the map operator twice for each subscription.
169
+ *
170
+ * const sharedFooX2 = streamFromEmitter(pipe(
171
+ * foo,
172
+ * map((value) => {
173
+ * console.log(`shared multiplying ${value}`);
174
+ * return value * 2;
175
+ * })
176
+ * ));
177
+ *
178
+ * subscribe(sharedFooX2, (value) => console.log(value));
179
+ * subscribe(sharedFooX2, (value) => console.log(value));
180
+ *
181
+ * publish(foo, 42);
182
+ *```
183
+ * @returns the resulting stream.
184
+ */
185
+ function streamFromEmitter(emitter) {
186
+ return utils_1.tap(stream(), function (stream) { return actions_1.connect(emitter, stream); });
187
+ }
188
+ exports.streamFromEmitter = streamFromEmitter;
189
+ /**
190
+ * Creates and connects a "junction" stateful stream to the specified emitter. Often used with [[pipe]], to avoid the multiple evaluation of operator sets.
191
+ *
192
+ * ```ts
193
+ * const foo = stream<number>();
194
+ *
195
+ * const fooX2 = pipe(
196
+ * foo,
197
+ * map((value) => {
198
+ * console.log(`multiplying ${value}`);
199
+ * return value * 2;
200
+ * })
201
+ * );
202
+ *
203
+ * subscribe(fooX2, (value) => console.log(value));
204
+ * subscribe(fooX2, (value) => console.log(value));
205
+ *
206
+ * publish(foo, 42); // executes the map operator twice for each subscription.
207
+ *
208
+ * const sharedFooX2 = statefulStreamFromEmitter(pipe(
209
+ * foo,
210
+ * map((value) => {
211
+ * console.log(`shared multiplying ${value}`);
212
+ * return value * 2;
213
+ * })
214
+ * ), 42);
215
+ *
216
+ * subscribe(sharedFooX2, (value) => console.log(value));
217
+ * subscribe(sharedFooX2, (value) => console.log(value));
218
+ *
219
+ * publish(foo, 42);
220
+ *```
221
+ * @param initial the initial value in the stream.
222
+ * @returns the resulting stateful stream.
223
+ */
224
+ function statefulStreamFromEmitter(emitter, initial) {
225
+ return utils_1.tap(statefulStream(initial), function (stream) { return actions_1.connect(emitter, stream); });
226
+ }
227
+ exports.statefulStreamFromEmitter = statefulStreamFromEmitter;