sygnal 2.5.0 → 2.6.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.
- package/dist/index.cjs.js +3671 -362
- package/dist/index.esm.js +3700 -368
- package/dist/jsx.cjs.js +52 -8
- package/dist/jsx.esm.js +52 -5
- package/dist/sygnal.min.js +1 -1
- package/package.json +1 -3
package/dist/index.esm.js
CHANGED
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
import isolate from '@cycle/isolate';
|
|
2
2
|
import { makeCollection, StateSource, withState } from '@cycle/state';
|
|
3
|
-
import xs, { Stream } from 'xstream';
|
|
3
|
+
import xs$1, { Stream as Stream$1 } from 'xstream';
|
|
4
4
|
export { default as xs } from 'xstream';
|
|
5
|
-
import dropRepeats from 'xstream/extra/dropRepeats';
|
|
6
|
-
export { default as dropRepeats } from 'xstream/extra/dropRepeats';
|
|
7
|
-
import delay from 'xstream/extra/delay.js';
|
|
8
|
-
import concat from 'xstream/extra/concat.js';
|
|
9
|
-
import debounce from 'xstream/extra/debounce.js';
|
|
10
|
-
import dropRepeats$1 from 'xstream/extra/dropRepeats.js';
|
|
11
5
|
import { run as run$1 } from '@cycle/run';
|
|
12
6
|
import { makeDOMDriver } from '@cycle/dom';
|
|
13
7
|
export * from '@cycle/dom';
|
|
14
|
-
import { adapt } from '@cycle/run/lib/adapt';
|
|
15
|
-
export { default as debounce } from 'xstream/extra/debounce';
|
|
16
|
-
export { default as throttle } from 'xstream/extra/throttle';
|
|
17
|
-
export { default as delay } from 'xstream/extra/delay';
|
|
18
|
-
export { default as sampleCombine } from 'xstream/extra/sampleCombine';
|
|
19
8
|
|
|
20
9
|
function collection(component, stateLense, opts={}) {
|
|
21
10
|
const {
|
|
@@ -39,12 +28,12 @@ function collection(component, stateLense, opts={}) {
|
|
|
39
28
|
if (combineList.includes(name)) {
|
|
40
29
|
const combined = instances.pickCombine(name);
|
|
41
30
|
if (name === domSourceName && container) {
|
|
42
|
-
acc
|
|
31
|
+
acc[domSourceName] = combined.map(children => {
|
|
43
32
|
const data = (containerClass) ? { props: { className: containerClass } } : {};
|
|
44
33
|
return { sel: container, data, children, key, text: undefined, elm: undefined}
|
|
45
34
|
});
|
|
46
35
|
} else {
|
|
47
|
-
console.warn('Collections without wrapping containers will fail in unpredictable ways when used inside JSX fragments')
|
|
36
|
+
// console.warn('Collections without wrapping containers will fail in unpredictable ways when used inside JSX fragments')
|
|
48
37
|
acc[name] = combined;
|
|
49
38
|
}
|
|
50
39
|
} else {
|
|
@@ -77,6 +66,2665 @@ function collection(component, stateLense, opts={}) {
|
|
|
77
66
|
return isolate(makeCollection(collectionOpts), isolateOpts)(sources)
|
|
78
67
|
}
|
|
79
68
|
|
|
69
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
70
|
+
|
|
71
|
+
var dropRepeats$1 = {};
|
|
72
|
+
|
|
73
|
+
var xstream = {};
|
|
74
|
+
|
|
75
|
+
var ponyfill$1 = {exports: {}};
|
|
76
|
+
|
|
77
|
+
var ponyfill = {};
|
|
78
|
+
|
|
79
|
+
(function (exports) {
|
|
80
|
+
|
|
81
|
+
Object.defineProperty(exports, "__esModule", {
|
|
82
|
+
value: true
|
|
83
|
+
});
|
|
84
|
+
exports['default'] = symbolObservablePonyfill;
|
|
85
|
+
function symbolObservablePonyfill(root) {
|
|
86
|
+
var result;
|
|
87
|
+
var _Symbol = root.Symbol;
|
|
88
|
+
|
|
89
|
+
if (typeof _Symbol === 'function') {
|
|
90
|
+
if (_Symbol.observable) {
|
|
91
|
+
result = _Symbol.observable;
|
|
92
|
+
} else {
|
|
93
|
+
|
|
94
|
+
// This just needs to be something that won't trample other user's Symbol.for use
|
|
95
|
+
// It also will guide people to the source of their issues, if this is problematic.
|
|
96
|
+
// META: It's a resource locator!
|
|
97
|
+
result = _Symbol['for']('https://github.com/benlesh/symbol-observable');
|
|
98
|
+
try {
|
|
99
|
+
_Symbol.observable = result;
|
|
100
|
+
} catch (err) {
|
|
101
|
+
// Do nothing. In some environments, users have frozen `Symbol` for security reasons,
|
|
102
|
+
// if it is frozen assigning to it will throw. In this case, we don't care, because
|
|
103
|
+
// they will need to use the returned value from the ponyfill.
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
result = '@@observable';
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return result;
|
|
111
|
+
}} (ponyfill));
|
|
112
|
+
|
|
113
|
+
(function (module) {
|
|
114
|
+
module.exports = ponyfill;
|
|
115
|
+
} (ponyfill$1));
|
|
116
|
+
|
|
117
|
+
var toStr$2 = Object.prototype.toString;
|
|
118
|
+
|
|
119
|
+
var isArguments = function isArguments(value) {
|
|
120
|
+
var str = toStr$2.call(value);
|
|
121
|
+
var isArgs = str === '[object Arguments]';
|
|
122
|
+
if (!isArgs) {
|
|
123
|
+
isArgs = str !== '[object Array]' &&
|
|
124
|
+
value !== null &&
|
|
125
|
+
typeof value === 'object' &&
|
|
126
|
+
typeof value.length === 'number' &&
|
|
127
|
+
value.length >= 0 &&
|
|
128
|
+
toStr$2.call(value.callee) === '[object Function]';
|
|
129
|
+
}
|
|
130
|
+
return isArgs;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
var implementation$5;
|
|
134
|
+
var hasRequiredImplementation;
|
|
135
|
+
|
|
136
|
+
function requireImplementation () {
|
|
137
|
+
if (hasRequiredImplementation) return implementation$5;
|
|
138
|
+
hasRequiredImplementation = 1;
|
|
139
|
+
|
|
140
|
+
var keysShim;
|
|
141
|
+
if (!Object.keys) {
|
|
142
|
+
// modified from https://github.com/es-shims/es5-shim
|
|
143
|
+
var has = Object.prototype.hasOwnProperty;
|
|
144
|
+
var toStr = Object.prototype.toString;
|
|
145
|
+
var isArgs = isArguments; // eslint-disable-line global-require
|
|
146
|
+
var isEnumerable = Object.prototype.propertyIsEnumerable;
|
|
147
|
+
var hasDontEnumBug = !isEnumerable.call({ toString: null }, 'toString');
|
|
148
|
+
var hasProtoEnumBug = isEnumerable.call(function () {}, 'prototype');
|
|
149
|
+
var dontEnums = [
|
|
150
|
+
'toString',
|
|
151
|
+
'toLocaleString',
|
|
152
|
+
'valueOf',
|
|
153
|
+
'hasOwnProperty',
|
|
154
|
+
'isPrototypeOf',
|
|
155
|
+
'propertyIsEnumerable',
|
|
156
|
+
'constructor'
|
|
157
|
+
];
|
|
158
|
+
var equalsConstructorPrototype = function (o) {
|
|
159
|
+
var ctor = o.constructor;
|
|
160
|
+
return ctor && ctor.prototype === o;
|
|
161
|
+
};
|
|
162
|
+
var excludedKeys = {
|
|
163
|
+
$applicationCache: true,
|
|
164
|
+
$console: true,
|
|
165
|
+
$external: true,
|
|
166
|
+
$frame: true,
|
|
167
|
+
$frameElement: true,
|
|
168
|
+
$frames: true,
|
|
169
|
+
$innerHeight: true,
|
|
170
|
+
$innerWidth: true,
|
|
171
|
+
$onmozfullscreenchange: true,
|
|
172
|
+
$onmozfullscreenerror: true,
|
|
173
|
+
$outerHeight: true,
|
|
174
|
+
$outerWidth: true,
|
|
175
|
+
$pageXOffset: true,
|
|
176
|
+
$pageYOffset: true,
|
|
177
|
+
$parent: true,
|
|
178
|
+
$scrollLeft: true,
|
|
179
|
+
$scrollTop: true,
|
|
180
|
+
$scrollX: true,
|
|
181
|
+
$scrollY: true,
|
|
182
|
+
$self: true,
|
|
183
|
+
$webkitIndexedDB: true,
|
|
184
|
+
$webkitStorageInfo: true,
|
|
185
|
+
$window: true
|
|
186
|
+
};
|
|
187
|
+
var hasAutomationEqualityBug = (function () {
|
|
188
|
+
/* global window */
|
|
189
|
+
if (typeof window === 'undefined') { return false; }
|
|
190
|
+
for (var k in window) {
|
|
191
|
+
try {
|
|
192
|
+
if (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') {
|
|
193
|
+
try {
|
|
194
|
+
equalsConstructorPrototype(window[k]);
|
|
195
|
+
} catch (e) {
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
} catch (e) {
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return false;
|
|
204
|
+
}());
|
|
205
|
+
var equalsConstructorPrototypeIfNotBuggy = function (o) {
|
|
206
|
+
/* global window */
|
|
207
|
+
if (typeof window === 'undefined' || !hasAutomationEqualityBug) {
|
|
208
|
+
return equalsConstructorPrototype(o);
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
return equalsConstructorPrototype(o);
|
|
212
|
+
} catch (e) {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
keysShim = function keys(object) {
|
|
218
|
+
var isObject = object !== null && typeof object === 'object';
|
|
219
|
+
var isFunction = toStr.call(object) === '[object Function]';
|
|
220
|
+
var isArguments = isArgs(object);
|
|
221
|
+
var isString = isObject && toStr.call(object) === '[object String]';
|
|
222
|
+
var theKeys = [];
|
|
223
|
+
|
|
224
|
+
if (!isObject && !isFunction && !isArguments) {
|
|
225
|
+
throw new TypeError('Object.keys called on a non-object');
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
var skipProto = hasProtoEnumBug && isFunction;
|
|
229
|
+
if (isString && object.length > 0 && !has.call(object, 0)) {
|
|
230
|
+
for (var i = 0; i < object.length; ++i) {
|
|
231
|
+
theKeys.push(String(i));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (isArguments && object.length > 0) {
|
|
236
|
+
for (var j = 0; j < object.length; ++j) {
|
|
237
|
+
theKeys.push(String(j));
|
|
238
|
+
}
|
|
239
|
+
} else {
|
|
240
|
+
for (var name in object) {
|
|
241
|
+
if (!(skipProto && name === 'prototype') && has.call(object, name)) {
|
|
242
|
+
theKeys.push(String(name));
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (hasDontEnumBug) {
|
|
248
|
+
var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
|
|
249
|
+
|
|
250
|
+
for (var k = 0; k < dontEnums.length; ++k) {
|
|
251
|
+
if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) {
|
|
252
|
+
theKeys.push(dontEnums[k]);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return theKeys;
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
implementation$5 = keysShim;
|
|
260
|
+
return implementation$5;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
var slice$1 = Array.prototype.slice;
|
|
264
|
+
var isArgs = isArguments;
|
|
265
|
+
|
|
266
|
+
var origKeys = Object.keys;
|
|
267
|
+
var keysShim = origKeys ? function keys(o) { return origKeys(o); } : requireImplementation();
|
|
268
|
+
|
|
269
|
+
var originalKeys = Object.keys;
|
|
270
|
+
|
|
271
|
+
keysShim.shim = function shimObjectKeys() {
|
|
272
|
+
if (Object.keys) {
|
|
273
|
+
var keysWorksWithArguments = (function () {
|
|
274
|
+
// Safari 5.0 bug
|
|
275
|
+
var args = Object.keys(arguments);
|
|
276
|
+
return args && args.length === arguments.length;
|
|
277
|
+
}(1, 2));
|
|
278
|
+
if (!keysWorksWithArguments) {
|
|
279
|
+
Object.keys = function keys(object) { // eslint-disable-line func-name-matching
|
|
280
|
+
if (isArgs(object)) {
|
|
281
|
+
return originalKeys(slice$1.call(object));
|
|
282
|
+
}
|
|
283
|
+
return originalKeys(object);
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
} else {
|
|
287
|
+
Object.keys = keysShim;
|
|
288
|
+
}
|
|
289
|
+
return Object.keys || keysShim;
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
var objectKeys = keysShim;
|
|
293
|
+
|
|
294
|
+
/* eslint complexity: [2, 18], max-statements: [2, 33] */
|
|
295
|
+
var shams = function hasSymbols() {
|
|
296
|
+
if (typeof Symbol !== 'function' || typeof Object.getOwnPropertySymbols !== 'function') { return false; }
|
|
297
|
+
if (typeof Symbol.iterator === 'symbol') { return true; }
|
|
298
|
+
|
|
299
|
+
var obj = {};
|
|
300
|
+
var sym = Symbol('test');
|
|
301
|
+
var symObj = Object(sym);
|
|
302
|
+
if (typeof sym === 'string') { return false; }
|
|
303
|
+
|
|
304
|
+
if (Object.prototype.toString.call(sym) !== '[object Symbol]') { return false; }
|
|
305
|
+
if (Object.prototype.toString.call(symObj) !== '[object Symbol]') { return false; }
|
|
306
|
+
|
|
307
|
+
// temp disabled per https://github.com/ljharb/object.assign/issues/17
|
|
308
|
+
// if (sym instanceof Symbol) { return false; }
|
|
309
|
+
// temp disabled per https://github.com/WebReflection/get-own-property-symbols/issues/4
|
|
310
|
+
// if (!(symObj instanceof Symbol)) { return false; }
|
|
311
|
+
|
|
312
|
+
// if (typeof Symbol.prototype.toString !== 'function') { return false; }
|
|
313
|
+
// if (String(sym) !== Symbol.prototype.toString.call(sym)) { return false; }
|
|
314
|
+
|
|
315
|
+
var symVal = 42;
|
|
316
|
+
obj[sym] = symVal;
|
|
317
|
+
for (sym in obj) { return false; } // eslint-disable-line no-restricted-syntax, no-unreachable-loop
|
|
318
|
+
if (typeof Object.keys === 'function' && Object.keys(obj).length !== 0) { return false; }
|
|
319
|
+
|
|
320
|
+
if (typeof Object.getOwnPropertyNames === 'function' && Object.getOwnPropertyNames(obj).length !== 0) { return false; }
|
|
321
|
+
|
|
322
|
+
var syms = Object.getOwnPropertySymbols(obj);
|
|
323
|
+
if (syms.length !== 1 || syms[0] !== sym) { return false; }
|
|
324
|
+
|
|
325
|
+
if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) { return false; }
|
|
326
|
+
|
|
327
|
+
if (typeof Object.getOwnPropertyDescriptor === 'function') {
|
|
328
|
+
var descriptor = Object.getOwnPropertyDescriptor(obj, sym);
|
|
329
|
+
if (descriptor.value !== symVal || descriptor.enumerable !== true) { return false; }
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return true;
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
var origSymbol = typeof Symbol !== 'undefined' && Symbol;
|
|
336
|
+
var hasSymbolSham = shams;
|
|
337
|
+
|
|
338
|
+
var hasSymbols$2 = function hasNativeSymbols() {
|
|
339
|
+
if (typeof origSymbol !== 'function') { return false; }
|
|
340
|
+
if (typeof Symbol !== 'function') { return false; }
|
|
341
|
+
if (typeof origSymbol('foo') !== 'symbol') { return false; }
|
|
342
|
+
if (typeof Symbol('bar') !== 'symbol') { return false; }
|
|
343
|
+
|
|
344
|
+
return hasSymbolSham();
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
/* eslint no-invalid-this: 1 */
|
|
348
|
+
|
|
349
|
+
var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible ';
|
|
350
|
+
var slice = Array.prototype.slice;
|
|
351
|
+
var toStr$1 = Object.prototype.toString;
|
|
352
|
+
var funcType = '[object Function]';
|
|
353
|
+
|
|
354
|
+
var implementation$4 = function bind(that) {
|
|
355
|
+
var target = this;
|
|
356
|
+
if (typeof target !== 'function' || toStr$1.call(target) !== funcType) {
|
|
357
|
+
throw new TypeError(ERROR_MESSAGE + target);
|
|
358
|
+
}
|
|
359
|
+
var args = slice.call(arguments, 1);
|
|
360
|
+
|
|
361
|
+
var bound;
|
|
362
|
+
var binder = function () {
|
|
363
|
+
if (this instanceof bound) {
|
|
364
|
+
var result = target.apply(
|
|
365
|
+
this,
|
|
366
|
+
args.concat(slice.call(arguments))
|
|
367
|
+
);
|
|
368
|
+
if (Object(result) === result) {
|
|
369
|
+
return result;
|
|
370
|
+
}
|
|
371
|
+
return this;
|
|
372
|
+
} else {
|
|
373
|
+
return target.apply(
|
|
374
|
+
that,
|
|
375
|
+
args.concat(slice.call(arguments))
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
var boundLength = Math.max(0, target.length - args.length);
|
|
381
|
+
var boundArgs = [];
|
|
382
|
+
for (var i = 0; i < boundLength; i++) {
|
|
383
|
+
boundArgs.push('$' + i);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this,arguments); }')(binder);
|
|
387
|
+
|
|
388
|
+
if (target.prototype) {
|
|
389
|
+
var Empty = function Empty() {};
|
|
390
|
+
Empty.prototype = target.prototype;
|
|
391
|
+
bound.prototype = new Empty();
|
|
392
|
+
Empty.prototype = null;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return bound;
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
var implementation$3 = implementation$4;
|
|
399
|
+
|
|
400
|
+
var functionBind = Function.prototype.bind || implementation$3;
|
|
401
|
+
|
|
402
|
+
var bind$1 = functionBind;
|
|
403
|
+
|
|
404
|
+
var src = bind$1.call(Function.call, Object.prototype.hasOwnProperty);
|
|
405
|
+
|
|
406
|
+
var undefined$1;
|
|
407
|
+
|
|
408
|
+
var $SyntaxError = SyntaxError;
|
|
409
|
+
var $Function = Function;
|
|
410
|
+
var $TypeError = TypeError;
|
|
411
|
+
|
|
412
|
+
// eslint-disable-next-line consistent-return
|
|
413
|
+
var getEvalledConstructor = function (expressionSyntax) {
|
|
414
|
+
try {
|
|
415
|
+
return $Function('"use strict"; return (' + expressionSyntax + ').constructor;')();
|
|
416
|
+
} catch (e) {}
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
var $gOPD = Object.getOwnPropertyDescriptor;
|
|
420
|
+
if ($gOPD) {
|
|
421
|
+
try {
|
|
422
|
+
$gOPD({}, '');
|
|
423
|
+
} catch (e) {
|
|
424
|
+
$gOPD = null; // this is IE 8, which has a broken gOPD
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
var throwTypeError = function () {
|
|
429
|
+
throw new $TypeError();
|
|
430
|
+
};
|
|
431
|
+
var ThrowTypeError = $gOPD
|
|
432
|
+
? (function () {
|
|
433
|
+
try {
|
|
434
|
+
// eslint-disable-next-line no-unused-expressions, no-caller, no-restricted-properties
|
|
435
|
+
arguments.callee; // IE 8 does not throw here
|
|
436
|
+
return throwTypeError;
|
|
437
|
+
} catch (calleeThrows) {
|
|
438
|
+
try {
|
|
439
|
+
// IE 8 throws on Object.getOwnPropertyDescriptor(arguments, '')
|
|
440
|
+
return $gOPD(arguments, 'callee').get;
|
|
441
|
+
} catch (gOPDthrows) {
|
|
442
|
+
return throwTypeError;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}())
|
|
446
|
+
: throwTypeError;
|
|
447
|
+
|
|
448
|
+
var hasSymbols$1 = hasSymbols$2();
|
|
449
|
+
|
|
450
|
+
var getProto = Object.getPrototypeOf || function (x) { return x.__proto__; }; // eslint-disable-line no-proto
|
|
451
|
+
|
|
452
|
+
var needsEval = {};
|
|
453
|
+
|
|
454
|
+
var TypedArray = typeof Uint8Array === 'undefined' ? undefined$1 : getProto(Uint8Array);
|
|
455
|
+
|
|
456
|
+
var INTRINSICS = {
|
|
457
|
+
'%AggregateError%': typeof AggregateError === 'undefined' ? undefined$1 : AggregateError,
|
|
458
|
+
'%Array%': Array,
|
|
459
|
+
'%ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined$1 : ArrayBuffer,
|
|
460
|
+
'%ArrayIteratorPrototype%': hasSymbols$1 ? getProto([][Symbol.iterator]()) : undefined$1,
|
|
461
|
+
'%AsyncFromSyncIteratorPrototype%': undefined$1,
|
|
462
|
+
'%AsyncFunction%': needsEval,
|
|
463
|
+
'%AsyncGenerator%': needsEval,
|
|
464
|
+
'%AsyncGeneratorFunction%': needsEval,
|
|
465
|
+
'%AsyncIteratorPrototype%': needsEval,
|
|
466
|
+
'%Atomics%': typeof Atomics === 'undefined' ? undefined$1 : Atomics,
|
|
467
|
+
'%BigInt%': typeof BigInt === 'undefined' ? undefined$1 : BigInt,
|
|
468
|
+
'%Boolean%': Boolean,
|
|
469
|
+
'%DataView%': typeof DataView === 'undefined' ? undefined$1 : DataView,
|
|
470
|
+
'%Date%': Date,
|
|
471
|
+
'%decodeURI%': decodeURI,
|
|
472
|
+
'%decodeURIComponent%': decodeURIComponent,
|
|
473
|
+
'%encodeURI%': encodeURI,
|
|
474
|
+
'%encodeURIComponent%': encodeURIComponent,
|
|
475
|
+
'%Error%': Error,
|
|
476
|
+
'%eval%': eval, // eslint-disable-line no-eval
|
|
477
|
+
'%EvalError%': EvalError,
|
|
478
|
+
'%Float32Array%': typeof Float32Array === 'undefined' ? undefined$1 : Float32Array,
|
|
479
|
+
'%Float64Array%': typeof Float64Array === 'undefined' ? undefined$1 : Float64Array,
|
|
480
|
+
'%FinalizationRegistry%': typeof FinalizationRegistry === 'undefined' ? undefined$1 : FinalizationRegistry,
|
|
481
|
+
'%Function%': $Function,
|
|
482
|
+
'%GeneratorFunction%': needsEval,
|
|
483
|
+
'%Int8Array%': typeof Int8Array === 'undefined' ? undefined$1 : Int8Array,
|
|
484
|
+
'%Int16Array%': typeof Int16Array === 'undefined' ? undefined$1 : Int16Array,
|
|
485
|
+
'%Int32Array%': typeof Int32Array === 'undefined' ? undefined$1 : Int32Array,
|
|
486
|
+
'%isFinite%': isFinite,
|
|
487
|
+
'%isNaN%': isNaN,
|
|
488
|
+
'%IteratorPrototype%': hasSymbols$1 ? getProto(getProto([][Symbol.iterator]())) : undefined$1,
|
|
489
|
+
'%JSON%': typeof JSON === 'object' ? JSON : undefined$1,
|
|
490
|
+
'%Map%': typeof Map === 'undefined' ? undefined$1 : Map,
|
|
491
|
+
'%MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols$1 ? undefined$1 : getProto(new Map()[Symbol.iterator]()),
|
|
492
|
+
'%Math%': Math,
|
|
493
|
+
'%Number%': Number,
|
|
494
|
+
'%Object%': Object,
|
|
495
|
+
'%parseFloat%': parseFloat,
|
|
496
|
+
'%parseInt%': parseInt,
|
|
497
|
+
'%Promise%': typeof Promise === 'undefined' ? undefined$1 : Promise,
|
|
498
|
+
'%Proxy%': typeof Proxy === 'undefined' ? undefined$1 : Proxy,
|
|
499
|
+
'%RangeError%': RangeError,
|
|
500
|
+
'%ReferenceError%': ReferenceError,
|
|
501
|
+
'%Reflect%': typeof Reflect === 'undefined' ? undefined$1 : Reflect,
|
|
502
|
+
'%RegExp%': RegExp,
|
|
503
|
+
'%Set%': typeof Set === 'undefined' ? undefined$1 : Set,
|
|
504
|
+
'%SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols$1 ? undefined$1 : getProto(new Set()[Symbol.iterator]()),
|
|
505
|
+
'%SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined$1 : SharedArrayBuffer,
|
|
506
|
+
'%String%': String,
|
|
507
|
+
'%StringIteratorPrototype%': hasSymbols$1 ? getProto(''[Symbol.iterator]()) : undefined$1,
|
|
508
|
+
'%Symbol%': hasSymbols$1 ? Symbol : undefined$1,
|
|
509
|
+
'%SyntaxError%': $SyntaxError,
|
|
510
|
+
'%ThrowTypeError%': ThrowTypeError,
|
|
511
|
+
'%TypedArray%': TypedArray,
|
|
512
|
+
'%TypeError%': $TypeError,
|
|
513
|
+
'%Uint8Array%': typeof Uint8Array === 'undefined' ? undefined$1 : Uint8Array,
|
|
514
|
+
'%Uint8ClampedArray%': typeof Uint8ClampedArray === 'undefined' ? undefined$1 : Uint8ClampedArray,
|
|
515
|
+
'%Uint16Array%': typeof Uint16Array === 'undefined' ? undefined$1 : Uint16Array,
|
|
516
|
+
'%Uint32Array%': typeof Uint32Array === 'undefined' ? undefined$1 : Uint32Array,
|
|
517
|
+
'%URIError%': URIError,
|
|
518
|
+
'%WeakMap%': typeof WeakMap === 'undefined' ? undefined$1 : WeakMap,
|
|
519
|
+
'%WeakRef%': typeof WeakRef === 'undefined' ? undefined$1 : WeakRef,
|
|
520
|
+
'%WeakSet%': typeof WeakSet === 'undefined' ? undefined$1 : WeakSet
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
var doEval = function doEval(name) {
|
|
524
|
+
var value;
|
|
525
|
+
if (name === '%AsyncFunction%') {
|
|
526
|
+
value = getEvalledConstructor('async function () {}');
|
|
527
|
+
} else if (name === '%GeneratorFunction%') {
|
|
528
|
+
value = getEvalledConstructor('function* () {}');
|
|
529
|
+
} else if (name === '%AsyncGeneratorFunction%') {
|
|
530
|
+
value = getEvalledConstructor('async function* () {}');
|
|
531
|
+
} else if (name === '%AsyncGenerator%') {
|
|
532
|
+
var fn = doEval('%AsyncGeneratorFunction%');
|
|
533
|
+
if (fn) {
|
|
534
|
+
value = fn.prototype;
|
|
535
|
+
}
|
|
536
|
+
} else if (name === '%AsyncIteratorPrototype%') {
|
|
537
|
+
var gen = doEval('%AsyncGenerator%');
|
|
538
|
+
if (gen) {
|
|
539
|
+
value = getProto(gen.prototype);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
INTRINSICS[name] = value;
|
|
544
|
+
|
|
545
|
+
return value;
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
var LEGACY_ALIASES = {
|
|
549
|
+
'%ArrayBufferPrototype%': ['ArrayBuffer', 'prototype'],
|
|
550
|
+
'%ArrayPrototype%': ['Array', 'prototype'],
|
|
551
|
+
'%ArrayProto_entries%': ['Array', 'prototype', 'entries'],
|
|
552
|
+
'%ArrayProto_forEach%': ['Array', 'prototype', 'forEach'],
|
|
553
|
+
'%ArrayProto_keys%': ['Array', 'prototype', 'keys'],
|
|
554
|
+
'%ArrayProto_values%': ['Array', 'prototype', 'values'],
|
|
555
|
+
'%AsyncFunctionPrototype%': ['AsyncFunction', 'prototype'],
|
|
556
|
+
'%AsyncGenerator%': ['AsyncGeneratorFunction', 'prototype'],
|
|
557
|
+
'%AsyncGeneratorPrototype%': ['AsyncGeneratorFunction', 'prototype', 'prototype'],
|
|
558
|
+
'%BooleanPrototype%': ['Boolean', 'prototype'],
|
|
559
|
+
'%DataViewPrototype%': ['DataView', 'prototype'],
|
|
560
|
+
'%DatePrototype%': ['Date', 'prototype'],
|
|
561
|
+
'%ErrorPrototype%': ['Error', 'prototype'],
|
|
562
|
+
'%EvalErrorPrototype%': ['EvalError', 'prototype'],
|
|
563
|
+
'%Float32ArrayPrototype%': ['Float32Array', 'prototype'],
|
|
564
|
+
'%Float64ArrayPrototype%': ['Float64Array', 'prototype'],
|
|
565
|
+
'%FunctionPrototype%': ['Function', 'prototype'],
|
|
566
|
+
'%Generator%': ['GeneratorFunction', 'prototype'],
|
|
567
|
+
'%GeneratorPrototype%': ['GeneratorFunction', 'prototype', 'prototype'],
|
|
568
|
+
'%Int8ArrayPrototype%': ['Int8Array', 'prototype'],
|
|
569
|
+
'%Int16ArrayPrototype%': ['Int16Array', 'prototype'],
|
|
570
|
+
'%Int32ArrayPrototype%': ['Int32Array', 'prototype'],
|
|
571
|
+
'%JSONParse%': ['JSON', 'parse'],
|
|
572
|
+
'%JSONStringify%': ['JSON', 'stringify'],
|
|
573
|
+
'%MapPrototype%': ['Map', 'prototype'],
|
|
574
|
+
'%NumberPrototype%': ['Number', 'prototype'],
|
|
575
|
+
'%ObjectPrototype%': ['Object', 'prototype'],
|
|
576
|
+
'%ObjProto_toString%': ['Object', 'prototype', 'toString'],
|
|
577
|
+
'%ObjProto_valueOf%': ['Object', 'prototype', 'valueOf'],
|
|
578
|
+
'%PromisePrototype%': ['Promise', 'prototype'],
|
|
579
|
+
'%PromiseProto_then%': ['Promise', 'prototype', 'then'],
|
|
580
|
+
'%Promise_all%': ['Promise', 'all'],
|
|
581
|
+
'%Promise_reject%': ['Promise', 'reject'],
|
|
582
|
+
'%Promise_resolve%': ['Promise', 'resolve'],
|
|
583
|
+
'%RangeErrorPrototype%': ['RangeError', 'prototype'],
|
|
584
|
+
'%ReferenceErrorPrototype%': ['ReferenceError', 'prototype'],
|
|
585
|
+
'%RegExpPrototype%': ['RegExp', 'prototype'],
|
|
586
|
+
'%SetPrototype%': ['Set', 'prototype'],
|
|
587
|
+
'%SharedArrayBufferPrototype%': ['SharedArrayBuffer', 'prototype'],
|
|
588
|
+
'%StringPrototype%': ['String', 'prototype'],
|
|
589
|
+
'%SymbolPrototype%': ['Symbol', 'prototype'],
|
|
590
|
+
'%SyntaxErrorPrototype%': ['SyntaxError', 'prototype'],
|
|
591
|
+
'%TypedArrayPrototype%': ['TypedArray', 'prototype'],
|
|
592
|
+
'%TypeErrorPrototype%': ['TypeError', 'prototype'],
|
|
593
|
+
'%Uint8ArrayPrototype%': ['Uint8Array', 'prototype'],
|
|
594
|
+
'%Uint8ClampedArrayPrototype%': ['Uint8ClampedArray', 'prototype'],
|
|
595
|
+
'%Uint16ArrayPrototype%': ['Uint16Array', 'prototype'],
|
|
596
|
+
'%Uint32ArrayPrototype%': ['Uint32Array', 'prototype'],
|
|
597
|
+
'%URIErrorPrototype%': ['URIError', 'prototype'],
|
|
598
|
+
'%WeakMapPrototype%': ['WeakMap', 'prototype'],
|
|
599
|
+
'%WeakSetPrototype%': ['WeakSet', 'prototype']
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
var bind = functionBind;
|
|
603
|
+
var hasOwn = src;
|
|
604
|
+
var $concat = bind.call(Function.call, Array.prototype.concat);
|
|
605
|
+
var $spliceApply = bind.call(Function.apply, Array.prototype.splice);
|
|
606
|
+
var $replace = bind.call(Function.call, String.prototype.replace);
|
|
607
|
+
var $strSlice = bind.call(Function.call, String.prototype.slice);
|
|
608
|
+
|
|
609
|
+
/* adapted from https://github.com/lodash/lodash/blob/4.17.15/dist/lodash.js#L6735-L6744 */
|
|
610
|
+
var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g;
|
|
611
|
+
var reEscapeChar = /\\(\\)?/g; /** Used to match backslashes in property paths. */
|
|
612
|
+
var stringToPath = function stringToPath(string) {
|
|
613
|
+
var first = $strSlice(string, 0, 1);
|
|
614
|
+
var last = $strSlice(string, -1);
|
|
615
|
+
if (first === '%' && last !== '%') {
|
|
616
|
+
throw new $SyntaxError('invalid intrinsic syntax, expected closing `%`');
|
|
617
|
+
} else if (last === '%' && first !== '%') {
|
|
618
|
+
throw new $SyntaxError('invalid intrinsic syntax, expected opening `%`');
|
|
619
|
+
}
|
|
620
|
+
var result = [];
|
|
621
|
+
$replace(string, rePropName, function (match, number, quote, subString) {
|
|
622
|
+
result[result.length] = quote ? $replace(subString, reEscapeChar, '$1') : number || match;
|
|
623
|
+
});
|
|
624
|
+
return result;
|
|
625
|
+
};
|
|
626
|
+
/* end adaptation */
|
|
627
|
+
|
|
628
|
+
var getBaseIntrinsic = function getBaseIntrinsic(name, allowMissing) {
|
|
629
|
+
var intrinsicName = name;
|
|
630
|
+
var alias;
|
|
631
|
+
if (hasOwn(LEGACY_ALIASES, intrinsicName)) {
|
|
632
|
+
alias = LEGACY_ALIASES[intrinsicName];
|
|
633
|
+
intrinsicName = '%' + alias[0] + '%';
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
if (hasOwn(INTRINSICS, intrinsicName)) {
|
|
637
|
+
var value = INTRINSICS[intrinsicName];
|
|
638
|
+
if (value === needsEval) {
|
|
639
|
+
value = doEval(intrinsicName);
|
|
640
|
+
}
|
|
641
|
+
if (typeof value === 'undefined' && !allowMissing) {
|
|
642
|
+
throw new $TypeError('intrinsic ' + name + ' exists, but is not available. Please file an issue!');
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
return {
|
|
646
|
+
alias: alias,
|
|
647
|
+
name: intrinsicName,
|
|
648
|
+
value: value
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
throw new $SyntaxError('intrinsic ' + name + ' does not exist!');
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
var getIntrinsic = function GetIntrinsic(name, allowMissing) {
|
|
656
|
+
if (typeof name !== 'string' || name.length === 0) {
|
|
657
|
+
throw new $TypeError('intrinsic name must be a non-empty string');
|
|
658
|
+
}
|
|
659
|
+
if (arguments.length > 1 && typeof allowMissing !== 'boolean') {
|
|
660
|
+
throw new $TypeError('"allowMissing" argument must be a boolean');
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
var parts = stringToPath(name);
|
|
664
|
+
var intrinsicBaseName = parts.length > 0 ? parts[0] : '';
|
|
665
|
+
|
|
666
|
+
var intrinsic = getBaseIntrinsic('%' + intrinsicBaseName + '%', allowMissing);
|
|
667
|
+
var intrinsicRealName = intrinsic.name;
|
|
668
|
+
var value = intrinsic.value;
|
|
669
|
+
var skipFurtherCaching = false;
|
|
670
|
+
|
|
671
|
+
var alias = intrinsic.alias;
|
|
672
|
+
if (alias) {
|
|
673
|
+
intrinsicBaseName = alias[0];
|
|
674
|
+
$spliceApply(parts, $concat([0, 1], alias));
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
for (var i = 1, isOwn = true; i < parts.length; i += 1) {
|
|
678
|
+
var part = parts[i];
|
|
679
|
+
var first = $strSlice(part, 0, 1);
|
|
680
|
+
var last = $strSlice(part, -1);
|
|
681
|
+
if (
|
|
682
|
+
(
|
|
683
|
+
(first === '"' || first === "'" || first === '`')
|
|
684
|
+
|| (last === '"' || last === "'" || last === '`')
|
|
685
|
+
)
|
|
686
|
+
&& first !== last
|
|
687
|
+
) {
|
|
688
|
+
throw new $SyntaxError('property names with quotes must have matching quotes');
|
|
689
|
+
}
|
|
690
|
+
if (part === 'constructor' || !isOwn) {
|
|
691
|
+
skipFurtherCaching = true;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
intrinsicBaseName += '.' + part;
|
|
695
|
+
intrinsicRealName = '%' + intrinsicBaseName + '%';
|
|
696
|
+
|
|
697
|
+
if (hasOwn(INTRINSICS, intrinsicRealName)) {
|
|
698
|
+
value = INTRINSICS[intrinsicRealName];
|
|
699
|
+
} else if (value != null) {
|
|
700
|
+
if (!(part in value)) {
|
|
701
|
+
if (!allowMissing) {
|
|
702
|
+
throw new $TypeError('base intrinsic for ' + name + ' exists, but the property is not available.');
|
|
703
|
+
}
|
|
704
|
+
return void undefined$1;
|
|
705
|
+
}
|
|
706
|
+
if ($gOPD && (i + 1) >= parts.length) {
|
|
707
|
+
var desc = $gOPD(value, part);
|
|
708
|
+
isOwn = !!desc;
|
|
709
|
+
|
|
710
|
+
// By convention, when a data property is converted to an accessor
|
|
711
|
+
// property to emulate a data property that does not suffer from
|
|
712
|
+
// the override mistake, that accessor's getter is marked with
|
|
713
|
+
// an `originalValue` property. Here, when we detect this, we
|
|
714
|
+
// uphold the illusion by pretending to see that original data
|
|
715
|
+
// property, i.e., returning the value rather than the getter
|
|
716
|
+
// itself.
|
|
717
|
+
if (isOwn && 'get' in desc && !('originalValue' in desc.get)) {
|
|
718
|
+
value = desc.get;
|
|
719
|
+
} else {
|
|
720
|
+
value = value[part];
|
|
721
|
+
}
|
|
722
|
+
} else {
|
|
723
|
+
isOwn = hasOwn(value, part);
|
|
724
|
+
value = value[part];
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
if (isOwn && !skipFurtherCaching) {
|
|
728
|
+
INTRINSICS[intrinsicRealName] = value;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
return value;
|
|
733
|
+
};
|
|
734
|
+
|
|
735
|
+
var GetIntrinsic = getIntrinsic;
|
|
736
|
+
|
|
737
|
+
var $defineProperty = GetIntrinsic('%Object.defineProperty%', true);
|
|
738
|
+
|
|
739
|
+
var hasPropertyDescriptors$1 = function hasPropertyDescriptors() {
|
|
740
|
+
if ($defineProperty) {
|
|
741
|
+
try {
|
|
742
|
+
$defineProperty({}, 'a', { value: 1 });
|
|
743
|
+
return true;
|
|
744
|
+
} catch (e) {
|
|
745
|
+
// IE 8 has a broken defineProperty
|
|
746
|
+
return false;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
return false;
|
|
750
|
+
};
|
|
751
|
+
|
|
752
|
+
hasPropertyDescriptors$1.hasArrayLengthDefineBug = function hasArrayLengthDefineBug() {
|
|
753
|
+
// node v0.6 has a bug where array lengths can be Set but not Defined
|
|
754
|
+
if (!hasPropertyDescriptors$1()) {
|
|
755
|
+
return null;
|
|
756
|
+
}
|
|
757
|
+
try {
|
|
758
|
+
return $defineProperty([], 'length', { value: 1 }).length !== 1;
|
|
759
|
+
} catch (e) {
|
|
760
|
+
// In Firefox 4-22, defining length on an array throws an exception.
|
|
761
|
+
return true;
|
|
762
|
+
}
|
|
763
|
+
};
|
|
764
|
+
|
|
765
|
+
var hasPropertyDescriptors_1 = hasPropertyDescriptors$1;
|
|
766
|
+
|
|
767
|
+
var keys = objectKeys;
|
|
768
|
+
var hasSymbols = typeof Symbol === 'function' && typeof Symbol('foo') === 'symbol';
|
|
769
|
+
|
|
770
|
+
var toStr = Object.prototype.toString;
|
|
771
|
+
var concat$2 = Array.prototype.concat;
|
|
772
|
+
var origDefineProperty = Object.defineProperty;
|
|
773
|
+
|
|
774
|
+
var isFunction = function (fn) {
|
|
775
|
+
return typeof fn === 'function' && toStr.call(fn) === '[object Function]';
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
var hasPropertyDescriptors = hasPropertyDescriptors_1();
|
|
779
|
+
|
|
780
|
+
var supportsDescriptors = origDefineProperty && hasPropertyDescriptors;
|
|
781
|
+
|
|
782
|
+
var defineProperty = function (object, name, value, predicate) {
|
|
783
|
+
if (name in object && (!isFunction(predicate) || !predicate())) {
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
if (supportsDescriptors) {
|
|
787
|
+
origDefineProperty(object, name, {
|
|
788
|
+
configurable: true,
|
|
789
|
+
enumerable: false,
|
|
790
|
+
value: value,
|
|
791
|
+
writable: true
|
|
792
|
+
});
|
|
793
|
+
} else {
|
|
794
|
+
object[name] = value; // eslint-disable-line no-param-reassign
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
|
|
798
|
+
var defineProperties$1 = function (object, map) {
|
|
799
|
+
var predicates = arguments.length > 2 ? arguments[2] : {};
|
|
800
|
+
var props = keys(map);
|
|
801
|
+
if (hasSymbols) {
|
|
802
|
+
props = concat$2.call(props, Object.getOwnPropertySymbols(map));
|
|
803
|
+
}
|
|
804
|
+
for (var i = 0; i < props.length; i += 1) {
|
|
805
|
+
defineProperty(object, props[i], map[props[i]], predicates[props[i]]);
|
|
806
|
+
}
|
|
807
|
+
};
|
|
808
|
+
|
|
809
|
+
defineProperties$1.supportsDescriptors = !!supportsDescriptors;
|
|
810
|
+
|
|
811
|
+
var defineProperties_1 = defineProperties$1;
|
|
812
|
+
|
|
813
|
+
var implementation$2 = commonjsGlobal;
|
|
814
|
+
|
|
815
|
+
var implementation$1 = implementation$2;
|
|
816
|
+
|
|
817
|
+
var polyfill$1 = function getPolyfill() {
|
|
818
|
+
if (typeof commonjsGlobal !== 'object' || !commonjsGlobal || commonjsGlobal.Math !== Math || commonjsGlobal.Array !== Array) {
|
|
819
|
+
return implementation$1;
|
|
820
|
+
}
|
|
821
|
+
return commonjsGlobal;
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
var define = defineProperties_1;
|
|
825
|
+
var getPolyfill$1 = polyfill$1;
|
|
826
|
+
|
|
827
|
+
var shim$1 = function shimGlobal() {
|
|
828
|
+
var polyfill = getPolyfill$1();
|
|
829
|
+
if (define.supportsDescriptors) {
|
|
830
|
+
var descriptor = Object.getOwnPropertyDescriptor(polyfill, 'globalThis');
|
|
831
|
+
if (!descriptor || (descriptor.configurable && (descriptor.enumerable || !descriptor.writable || globalThis !== polyfill))) { // eslint-disable-line max-len
|
|
832
|
+
Object.defineProperty(polyfill, 'globalThis', {
|
|
833
|
+
configurable: true,
|
|
834
|
+
enumerable: false,
|
|
835
|
+
value: polyfill,
|
|
836
|
+
writable: true
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
} else if (typeof globalThis !== 'object' || globalThis !== polyfill) {
|
|
840
|
+
polyfill.globalThis = polyfill;
|
|
841
|
+
}
|
|
842
|
+
return polyfill;
|
|
843
|
+
};
|
|
844
|
+
|
|
845
|
+
var defineProperties = defineProperties_1;
|
|
846
|
+
|
|
847
|
+
var implementation = implementation$2;
|
|
848
|
+
var getPolyfill = polyfill$1;
|
|
849
|
+
var shim = shim$1;
|
|
850
|
+
|
|
851
|
+
var polyfill = getPolyfill();
|
|
852
|
+
|
|
853
|
+
var getGlobal$1 = function () { return polyfill; };
|
|
854
|
+
|
|
855
|
+
defineProperties(getGlobal$1, {
|
|
856
|
+
getPolyfill: getPolyfill,
|
|
857
|
+
implementation: implementation,
|
|
858
|
+
shim: shim
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
var globalthis = getGlobal$1;
|
|
862
|
+
|
|
863
|
+
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
864
|
+
var extendStatics = function (d, b) {
|
|
865
|
+
extendStatics = Object.setPrototypeOf ||
|
|
866
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
867
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
868
|
+
return extendStatics(d, b);
|
|
869
|
+
};
|
|
870
|
+
return function (d, b) {
|
|
871
|
+
extendStatics(d, b);
|
|
872
|
+
function __() { this.constructor = d; }
|
|
873
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
874
|
+
};
|
|
875
|
+
})();
|
|
876
|
+
Object.defineProperty(xstream, "__esModule", { value: true });
|
|
877
|
+
xstream.NO_IL = xstream.NO = xstream.MemoryStream = xstream.Stream = void 0;
|
|
878
|
+
var ponyfill_1 = ponyfill$1.exports;
|
|
879
|
+
var globalthis_1 = globalthis;
|
|
880
|
+
var $$observable = ponyfill_1.default(globalthis_1.getPolyfill());
|
|
881
|
+
var NO$1 = {};
|
|
882
|
+
xstream.NO = NO$1;
|
|
883
|
+
function noop() { }
|
|
884
|
+
function cp(a) {
|
|
885
|
+
var l = a.length;
|
|
886
|
+
var b = Array(l);
|
|
887
|
+
for (var i = 0; i < l; ++i)
|
|
888
|
+
b[i] = a[i];
|
|
889
|
+
return b;
|
|
890
|
+
}
|
|
891
|
+
function and(f1, f2) {
|
|
892
|
+
return function andFn(t) {
|
|
893
|
+
return f1(t) && f2(t);
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
function _try(c, t, u) {
|
|
897
|
+
try {
|
|
898
|
+
return c.f(t);
|
|
899
|
+
}
|
|
900
|
+
catch (e) {
|
|
901
|
+
u._e(e);
|
|
902
|
+
return NO$1;
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
var NO_IL = {
|
|
906
|
+
_n: noop,
|
|
907
|
+
_e: noop,
|
|
908
|
+
_c: noop,
|
|
909
|
+
};
|
|
910
|
+
xstream.NO_IL = NO_IL;
|
|
911
|
+
// mutates the input
|
|
912
|
+
function internalizeProducer(producer) {
|
|
913
|
+
producer._start = function _start(il) {
|
|
914
|
+
il.next = il._n;
|
|
915
|
+
il.error = il._e;
|
|
916
|
+
il.complete = il._c;
|
|
917
|
+
this.start(il);
|
|
918
|
+
};
|
|
919
|
+
producer._stop = producer.stop;
|
|
920
|
+
}
|
|
921
|
+
var StreamSub = /** @class */ (function () {
|
|
922
|
+
function StreamSub(_stream, _listener) {
|
|
923
|
+
this._stream = _stream;
|
|
924
|
+
this._listener = _listener;
|
|
925
|
+
}
|
|
926
|
+
StreamSub.prototype.unsubscribe = function () {
|
|
927
|
+
this._stream._remove(this._listener);
|
|
928
|
+
};
|
|
929
|
+
return StreamSub;
|
|
930
|
+
}());
|
|
931
|
+
var Observer = /** @class */ (function () {
|
|
932
|
+
function Observer(_listener) {
|
|
933
|
+
this._listener = _listener;
|
|
934
|
+
}
|
|
935
|
+
Observer.prototype.next = function (value) {
|
|
936
|
+
this._listener._n(value);
|
|
937
|
+
};
|
|
938
|
+
Observer.prototype.error = function (err) {
|
|
939
|
+
this._listener._e(err);
|
|
940
|
+
};
|
|
941
|
+
Observer.prototype.complete = function () {
|
|
942
|
+
this._listener._c();
|
|
943
|
+
};
|
|
944
|
+
return Observer;
|
|
945
|
+
}());
|
|
946
|
+
var FromObservable = /** @class */ (function () {
|
|
947
|
+
function FromObservable(observable) {
|
|
948
|
+
this.type = 'fromObservable';
|
|
949
|
+
this.ins = observable;
|
|
950
|
+
this.active = false;
|
|
951
|
+
}
|
|
952
|
+
FromObservable.prototype._start = function (out) {
|
|
953
|
+
this.out = out;
|
|
954
|
+
this.active = true;
|
|
955
|
+
this._sub = this.ins.subscribe(new Observer(out));
|
|
956
|
+
if (!this.active)
|
|
957
|
+
this._sub.unsubscribe();
|
|
958
|
+
};
|
|
959
|
+
FromObservable.prototype._stop = function () {
|
|
960
|
+
if (this._sub)
|
|
961
|
+
this._sub.unsubscribe();
|
|
962
|
+
this.active = false;
|
|
963
|
+
};
|
|
964
|
+
return FromObservable;
|
|
965
|
+
}());
|
|
966
|
+
var Merge = /** @class */ (function () {
|
|
967
|
+
function Merge(insArr) {
|
|
968
|
+
this.type = 'merge';
|
|
969
|
+
this.insArr = insArr;
|
|
970
|
+
this.out = NO$1;
|
|
971
|
+
this.ac = 0;
|
|
972
|
+
}
|
|
973
|
+
Merge.prototype._start = function (out) {
|
|
974
|
+
this.out = out;
|
|
975
|
+
var s = this.insArr;
|
|
976
|
+
var L = s.length;
|
|
977
|
+
this.ac = L;
|
|
978
|
+
for (var i = 0; i < L; i++)
|
|
979
|
+
s[i]._add(this);
|
|
980
|
+
};
|
|
981
|
+
Merge.prototype._stop = function () {
|
|
982
|
+
var s = this.insArr;
|
|
983
|
+
var L = s.length;
|
|
984
|
+
for (var i = 0; i < L; i++)
|
|
985
|
+
s[i]._remove(this);
|
|
986
|
+
this.out = NO$1;
|
|
987
|
+
};
|
|
988
|
+
Merge.prototype._n = function (t) {
|
|
989
|
+
var u = this.out;
|
|
990
|
+
if (u === NO$1)
|
|
991
|
+
return;
|
|
992
|
+
u._n(t);
|
|
993
|
+
};
|
|
994
|
+
Merge.prototype._e = function (err) {
|
|
995
|
+
var u = this.out;
|
|
996
|
+
if (u === NO$1)
|
|
997
|
+
return;
|
|
998
|
+
u._e(err);
|
|
999
|
+
};
|
|
1000
|
+
Merge.prototype._c = function () {
|
|
1001
|
+
if (--this.ac <= 0) {
|
|
1002
|
+
var u = this.out;
|
|
1003
|
+
if (u === NO$1)
|
|
1004
|
+
return;
|
|
1005
|
+
u._c();
|
|
1006
|
+
}
|
|
1007
|
+
};
|
|
1008
|
+
return Merge;
|
|
1009
|
+
}());
|
|
1010
|
+
var CombineListener = /** @class */ (function () {
|
|
1011
|
+
function CombineListener(i, out, p) {
|
|
1012
|
+
this.i = i;
|
|
1013
|
+
this.out = out;
|
|
1014
|
+
this.p = p;
|
|
1015
|
+
p.ils.push(this);
|
|
1016
|
+
}
|
|
1017
|
+
CombineListener.prototype._n = function (t) {
|
|
1018
|
+
var p = this.p, out = this.out;
|
|
1019
|
+
if (out === NO$1)
|
|
1020
|
+
return;
|
|
1021
|
+
if (p.up(t, this.i)) {
|
|
1022
|
+
var b = cp(p.vals);
|
|
1023
|
+
out._n(b);
|
|
1024
|
+
}
|
|
1025
|
+
};
|
|
1026
|
+
CombineListener.prototype._e = function (err) {
|
|
1027
|
+
var out = this.out;
|
|
1028
|
+
if (out === NO$1)
|
|
1029
|
+
return;
|
|
1030
|
+
out._e(err);
|
|
1031
|
+
};
|
|
1032
|
+
CombineListener.prototype._c = function () {
|
|
1033
|
+
var p = this.p;
|
|
1034
|
+
if (p.out === NO$1)
|
|
1035
|
+
return;
|
|
1036
|
+
if (--p.Nc === 0)
|
|
1037
|
+
p.out._c();
|
|
1038
|
+
};
|
|
1039
|
+
return CombineListener;
|
|
1040
|
+
}());
|
|
1041
|
+
var Combine = /** @class */ (function () {
|
|
1042
|
+
function Combine(insArr) {
|
|
1043
|
+
this.type = 'combine';
|
|
1044
|
+
this.insArr = insArr;
|
|
1045
|
+
this.out = NO$1;
|
|
1046
|
+
this.ils = [];
|
|
1047
|
+
this.Nc = this.Nn = 0;
|
|
1048
|
+
this.vals = [];
|
|
1049
|
+
}
|
|
1050
|
+
Combine.prototype.up = function (t, i) {
|
|
1051
|
+
var v = this.vals[i];
|
|
1052
|
+
var Nn = !this.Nn ? 0 : v === NO$1 ? --this.Nn : this.Nn;
|
|
1053
|
+
this.vals[i] = t;
|
|
1054
|
+
return Nn === 0;
|
|
1055
|
+
};
|
|
1056
|
+
Combine.prototype._start = function (out) {
|
|
1057
|
+
this.out = out;
|
|
1058
|
+
var s = this.insArr;
|
|
1059
|
+
var n = this.Nc = this.Nn = s.length;
|
|
1060
|
+
var vals = this.vals = new Array(n);
|
|
1061
|
+
if (n === 0) {
|
|
1062
|
+
out._n([]);
|
|
1063
|
+
out._c();
|
|
1064
|
+
}
|
|
1065
|
+
else {
|
|
1066
|
+
for (var i = 0; i < n; i++) {
|
|
1067
|
+
vals[i] = NO$1;
|
|
1068
|
+
s[i]._add(new CombineListener(i, out, this));
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
};
|
|
1072
|
+
Combine.prototype._stop = function () {
|
|
1073
|
+
var s = this.insArr;
|
|
1074
|
+
var n = s.length;
|
|
1075
|
+
var ils = this.ils;
|
|
1076
|
+
for (var i = 0; i < n; i++)
|
|
1077
|
+
s[i]._remove(ils[i]);
|
|
1078
|
+
this.out = NO$1;
|
|
1079
|
+
this.ils = [];
|
|
1080
|
+
this.vals = [];
|
|
1081
|
+
};
|
|
1082
|
+
return Combine;
|
|
1083
|
+
}());
|
|
1084
|
+
var FromArray = /** @class */ (function () {
|
|
1085
|
+
function FromArray(a) {
|
|
1086
|
+
this.type = 'fromArray';
|
|
1087
|
+
this.a = a;
|
|
1088
|
+
}
|
|
1089
|
+
FromArray.prototype._start = function (out) {
|
|
1090
|
+
var a = this.a;
|
|
1091
|
+
for (var i = 0, n = a.length; i < n; i++)
|
|
1092
|
+
out._n(a[i]);
|
|
1093
|
+
out._c();
|
|
1094
|
+
};
|
|
1095
|
+
FromArray.prototype._stop = function () {
|
|
1096
|
+
};
|
|
1097
|
+
return FromArray;
|
|
1098
|
+
}());
|
|
1099
|
+
var FromPromise = /** @class */ (function () {
|
|
1100
|
+
function FromPromise(p) {
|
|
1101
|
+
this.type = 'fromPromise';
|
|
1102
|
+
this.on = false;
|
|
1103
|
+
this.p = p;
|
|
1104
|
+
}
|
|
1105
|
+
FromPromise.prototype._start = function (out) {
|
|
1106
|
+
var prod = this;
|
|
1107
|
+
this.on = true;
|
|
1108
|
+
this.p.then(function (v) {
|
|
1109
|
+
if (prod.on) {
|
|
1110
|
+
out._n(v);
|
|
1111
|
+
out._c();
|
|
1112
|
+
}
|
|
1113
|
+
}, function (e) {
|
|
1114
|
+
out._e(e);
|
|
1115
|
+
}).then(noop, function (err) {
|
|
1116
|
+
setTimeout(function () { throw err; });
|
|
1117
|
+
});
|
|
1118
|
+
};
|
|
1119
|
+
FromPromise.prototype._stop = function () {
|
|
1120
|
+
this.on = false;
|
|
1121
|
+
};
|
|
1122
|
+
return FromPromise;
|
|
1123
|
+
}());
|
|
1124
|
+
var Periodic = /** @class */ (function () {
|
|
1125
|
+
function Periodic(period) {
|
|
1126
|
+
this.type = 'periodic';
|
|
1127
|
+
this.period = period;
|
|
1128
|
+
this.intervalID = -1;
|
|
1129
|
+
this.i = 0;
|
|
1130
|
+
}
|
|
1131
|
+
Periodic.prototype._start = function (out) {
|
|
1132
|
+
var self = this;
|
|
1133
|
+
function intervalHandler() { out._n(self.i++); }
|
|
1134
|
+
this.intervalID = setInterval(intervalHandler, this.period);
|
|
1135
|
+
};
|
|
1136
|
+
Periodic.prototype._stop = function () {
|
|
1137
|
+
if (this.intervalID !== -1)
|
|
1138
|
+
clearInterval(this.intervalID);
|
|
1139
|
+
this.intervalID = -1;
|
|
1140
|
+
this.i = 0;
|
|
1141
|
+
};
|
|
1142
|
+
return Periodic;
|
|
1143
|
+
}());
|
|
1144
|
+
var Debug = /** @class */ (function () {
|
|
1145
|
+
function Debug(ins, arg) {
|
|
1146
|
+
this.type = 'debug';
|
|
1147
|
+
this.ins = ins;
|
|
1148
|
+
this.out = NO$1;
|
|
1149
|
+
this.s = noop;
|
|
1150
|
+
this.l = '';
|
|
1151
|
+
if (typeof arg === 'string')
|
|
1152
|
+
this.l = arg;
|
|
1153
|
+
else if (typeof arg === 'function')
|
|
1154
|
+
this.s = arg;
|
|
1155
|
+
}
|
|
1156
|
+
Debug.prototype._start = function (out) {
|
|
1157
|
+
this.out = out;
|
|
1158
|
+
this.ins._add(this);
|
|
1159
|
+
};
|
|
1160
|
+
Debug.prototype._stop = function () {
|
|
1161
|
+
this.ins._remove(this);
|
|
1162
|
+
this.out = NO$1;
|
|
1163
|
+
};
|
|
1164
|
+
Debug.prototype._n = function (t) {
|
|
1165
|
+
var u = this.out;
|
|
1166
|
+
if (u === NO$1)
|
|
1167
|
+
return;
|
|
1168
|
+
var s = this.s, l = this.l;
|
|
1169
|
+
if (s !== noop) {
|
|
1170
|
+
try {
|
|
1171
|
+
s(t);
|
|
1172
|
+
}
|
|
1173
|
+
catch (e) {
|
|
1174
|
+
u._e(e);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
else if (l)
|
|
1178
|
+
console.log(l + ':', t);
|
|
1179
|
+
else
|
|
1180
|
+
console.log(t);
|
|
1181
|
+
u._n(t);
|
|
1182
|
+
};
|
|
1183
|
+
Debug.prototype._e = function (err) {
|
|
1184
|
+
var u = this.out;
|
|
1185
|
+
if (u === NO$1)
|
|
1186
|
+
return;
|
|
1187
|
+
u._e(err);
|
|
1188
|
+
};
|
|
1189
|
+
Debug.prototype._c = function () {
|
|
1190
|
+
var u = this.out;
|
|
1191
|
+
if (u === NO$1)
|
|
1192
|
+
return;
|
|
1193
|
+
u._c();
|
|
1194
|
+
};
|
|
1195
|
+
return Debug;
|
|
1196
|
+
}());
|
|
1197
|
+
var Drop = /** @class */ (function () {
|
|
1198
|
+
function Drop(max, ins) {
|
|
1199
|
+
this.type = 'drop';
|
|
1200
|
+
this.ins = ins;
|
|
1201
|
+
this.out = NO$1;
|
|
1202
|
+
this.max = max;
|
|
1203
|
+
this.dropped = 0;
|
|
1204
|
+
}
|
|
1205
|
+
Drop.prototype._start = function (out) {
|
|
1206
|
+
this.out = out;
|
|
1207
|
+
this.dropped = 0;
|
|
1208
|
+
this.ins._add(this);
|
|
1209
|
+
};
|
|
1210
|
+
Drop.prototype._stop = function () {
|
|
1211
|
+
this.ins._remove(this);
|
|
1212
|
+
this.out = NO$1;
|
|
1213
|
+
};
|
|
1214
|
+
Drop.prototype._n = function (t) {
|
|
1215
|
+
var u = this.out;
|
|
1216
|
+
if (u === NO$1)
|
|
1217
|
+
return;
|
|
1218
|
+
if (this.dropped++ >= this.max)
|
|
1219
|
+
u._n(t);
|
|
1220
|
+
};
|
|
1221
|
+
Drop.prototype._e = function (err) {
|
|
1222
|
+
var u = this.out;
|
|
1223
|
+
if (u === NO$1)
|
|
1224
|
+
return;
|
|
1225
|
+
u._e(err);
|
|
1226
|
+
};
|
|
1227
|
+
Drop.prototype._c = function () {
|
|
1228
|
+
var u = this.out;
|
|
1229
|
+
if (u === NO$1)
|
|
1230
|
+
return;
|
|
1231
|
+
u._c();
|
|
1232
|
+
};
|
|
1233
|
+
return Drop;
|
|
1234
|
+
}());
|
|
1235
|
+
var EndWhenListener = /** @class */ (function () {
|
|
1236
|
+
function EndWhenListener(out, op) {
|
|
1237
|
+
this.out = out;
|
|
1238
|
+
this.op = op;
|
|
1239
|
+
}
|
|
1240
|
+
EndWhenListener.prototype._n = function () {
|
|
1241
|
+
this.op.end();
|
|
1242
|
+
};
|
|
1243
|
+
EndWhenListener.prototype._e = function (err) {
|
|
1244
|
+
this.out._e(err);
|
|
1245
|
+
};
|
|
1246
|
+
EndWhenListener.prototype._c = function () {
|
|
1247
|
+
this.op.end();
|
|
1248
|
+
};
|
|
1249
|
+
return EndWhenListener;
|
|
1250
|
+
}());
|
|
1251
|
+
var EndWhen = /** @class */ (function () {
|
|
1252
|
+
function EndWhen(o, ins) {
|
|
1253
|
+
this.type = 'endWhen';
|
|
1254
|
+
this.ins = ins;
|
|
1255
|
+
this.out = NO$1;
|
|
1256
|
+
this.o = o;
|
|
1257
|
+
this.oil = NO_IL;
|
|
1258
|
+
}
|
|
1259
|
+
EndWhen.prototype._start = function (out) {
|
|
1260
|
+
this.out = out;
|
|
1261
|
+
this.o._add(this.oil = new EndWhenListener(out, this));
|
|
1262
|
+
this.ins._add(this);
|
|
1263
|
+
};
|
|
1264
|
+
EndWhen.prototype._stop = function () {
|
|
1265
|
+
this.ins._remove(this);
|
|
1266
|
+
this.o._remove(this.oil);
|
|
1267
|
+
this.out = NO$1;
|
|
1268
|
+
this.oil = NO_IL;
|
|
1269
|
+
};
|
|
1270
|
+
EndWhen.prototype.end = function () {
|
|
1271
|
+
var u = this.out;
|
|
1272
|
+
if (u === NO$1)
|
|
1273
|
+
return;
|
|
1274
|
+
u._c();
|
|
1275
|
+
};
|
|
1276
|
+
EndWhen.prototype._n = function (t) {
|
|
1277
|
+
var u = this.out;
|
|
1278
|
+
if (u === NO$1)
|
|
1279
|
+
return;
|
|
1280
|
+
u._n(t);
|
|
1281
|
+
};
|
|
1282
|
+
EndWhen.prototype._e = function (err) {
|
|
1283
|
+
var u = this.out;
|
|
1284
|
+
if (u === NO$1)
|
|
1285
|
+
return;
|
|
1286
|
+
u._e(err);
|
|
1287
|
+
};
|
|
1288
|
+
EndWhen.prototype._c = function () {
|
|
1289
|
+
this.end();
|
|
1290
|
+
};
|
|
1291
|
+
return EndWhen;
|
|
1292
|
+
}());
|
|
1293
|
+
var Filter = /** @class */ (function () {
|
|
1294
|
+
function Filter(passes, ins) {
|
|
1295
|
+
this.type = 'filter';
|
|
1296
|
+
this.ins = ins;
|
|
1297
|
+
this.out = NO$1;
|
|
1298
|
+
this.f = passes;
|
|
1299
|
+
}
|
|
1300
|
+
Filter.prototype._start = function (out) {
|
|
1301
|
+
this.out = out;
|
|
1302
|
+
this.ins._add(this);
|
|
1303
|
+
};
|
|
1304
|
+
Filter.prototype._stop = function () {
|
|
1305
|
+
this.ins._remove(this);
|
|
1306
|
+
this.out = NO$1;
|
|
1307
|
+
};
|
|
1308
|
+
Filter.prototype._n = function (t) {
|
|
1309
|
+
var u = this.out;
|
|
1310
|
+
if (u === NO$1)
|
|
1311
|
+
return;
|
|
1312
|
+
var r = _try(this, t, u);
|
|
1313
|
+
if (r === NO$1 || !r)
|
|
1314
|
+
return;
|
|
1315
|
+
u._n(t);
|
|
1316
|
+
};
|
|
1317
|
+
Filter.prototype._e = function (err) {
|
|
1318
|
+
var u = this.out;
|
|
1319
|
+
if (u === NO$1)
|
|
1320
|
+
return;
|
|
1321
|
+
u._e(err);
|
|
1322
|
+
};
|
|
1323
|
+
Filter.prototype._c = function () {
|
|
1324
|
+
var u = this.out;
|
|
1325
|
+
if (u === NO$1)
|
|
1326
|
+
return;
|
|
1327
|
+
u._c();
|
|
1328
|
+
};
|
|
1329
|
+
return Filter;
|
|
1330
|
+
}());
|
|
1331
|
+
var FlattenListener = /** @class */ (function () {
|
|
1332
|
+
function FlattenListener(out, op) {
|
|
1333
|
+
this.out = out;
|
|
1334
|
+
this.op = op;
|
|
1335
|
+
}
|
|
1336
|
+
FlattenListener.prototype._n = function (t) {
|
|
1337
|
+
this.out._n(t);
|
|
1338
|
+
};
|
|
1339
|
+
FlattenListener.prototype._e = function (err) {
|
|
1340
|
+
this.out._e(err);
|
|
1341
|
+
};
|
|
1342
|
+
FlattenListener.prototype._c = function () {
|
|
1343
|
+
this.op.inner = NO$1;
|
|
1344
|
+
this.op.less();
|
|
1345
|
+
};
|
|
1346
|
+
return FlattenListener;
|
|
1347
|
+
}());
|
|
1348
|
+
var Flatten = /** @class */ (function () {
|
|
1349
|
+
function Flatten(ins) {
|
|
1350
|
+
this.type = 'flatten';
|
|
1351
|
+
this.ins = ins;
|
|
1352
|
+
this.out = NO$1;
|
|
1353
|
+
this.open = true;
|
|
1354
|
+
this.inner = NO$1;
|
|
1355
|
+
this.il = NO_IL;
|
|
1356
|
+
}
|
|
1357
|
+
Flatten.prototype._start = function (out) {
|
|
1358
|
+
this.out = out;
|
|
1359
|
+
this.open = true;
|
|
1360
|
+
this.inner = NO$1;
|
|
1361
|
+
this.il = NO_IL;
|
|
1362
|
+
this.ins._add(this);
|
|
1363
|
+
};
|
|
1364
|
+
Flatten.prototype._stop = function () {
|
|
1365
|
+
this.ins._remove(this);
|
|
1366
|
+
if (this.inner !== NO$1)
|
|
1367
|
+
this.inner._remove(this.il);
|
|
1368
|
+
this.out = NO$1;
|
|
1369
|
+
this.open = true;
|
|
1370
|
+
this.inner = NO$1;
|
|
1371
|
+
this.il = NO_IL;
|
|
1372
|
+
};
|
|
1373
|
+
Flatten.prototype.less = function () {
|
|
1374
|
+
var u = this.out;
|
|
1375
|
+
if (u === NO$1)
|
|
1376
|
+
return;
|
|
1377
|
+
if (!this.open && this.inner === NO$1)
|
|
1378
|
+
u._c();
|
|
1379
|
+
};
|
|
1380
|
+
Flatten.prototype._n = function (s) {
|
|
1381
|
+
var u = this.out;
|
|
1382
|
+
if (u === NO$1)
|
|
1383
|
+
return;
|
|
1384
|
+
var _a = this, inner = _a.inner, il = _a.il;
|
|
1385
|
+
if (inner !== NO$1 && il !== NO_IL)
|
|
1386
|
+
inner._remove(il);
|
|
1387
|
+
(this.inner = s)._add(this.il = new FlattenListener(u, this));
|
|
1388
|
+
};
|
|
1389
|
+
Flatten.prototype._e = function (err) {
|
|
1390
|
+
var u = this.out;
|
|
1391
|
+
if (u === NO$1)
|
|
1392
|
+
return;
|
|
1393
|
+
u._e(err);
|
|
1394
|
+
};
|
|
1395
|
+
Flatten.prototype._c = function () {
|
|
1396
|
+
this.open = false;
|
|
1397
|
+
this.less();
|
|
1398
|
+
};
|
|
1399
|
+
return Flatten;
|
|
1400
|
+
}());
|
|
1401
|
+
var Fold = /** @class */ (function () {
|
|
1402
|
+
function Fold(f, seed, ins) {
|
|
1403
|
+
var _this = this;
|
|
1404
|
+
this.type = 'fold';
|
|
1405
|
+
this.ins = ins;
|
|
1406
|
+
this.out = NO$1;
|
|
1407
|
+
this.f = function (t) { return f(_this.acc, t); };
|
|
1408
|
+
this.acc = this.seed = seed;
|
|
1409
|
+
}
|
|
1410
|
+
Fold.prototype._start = function (out) {
|
|
1411
|
+
this.out = out;
|
|
1412
|
+
this.acc = this.seed;
|
|
1413
|
+
out._n(this.acc);
|
|
1414
|
+
this.ins._add(this);
|
|
1415
|
+
};
|
|
1416
|
+
Fold.prototype._stop = function () {
|
|
1417
|
+
this.ins._remove(this);
|
|
1418
|
+
this.out = NO$1;
|
|
1419
|
+
this.acc = this.seed;
|
|
1420
|
+
};
|
|
1421
|
+
Fold.prototype._n = function (t) {
|
|
1422
|
+
var u = this.out;
|
|
1423
|
+
if (u === NO$1)
|
|
1424
|
+
return;
|
|
1425
|
+
var r = _try(this, t, u);
|
|
1426
|
+
if (r === NO$1)
|
|
1427
|
+
return;
|
|
1428
|
+
u._n(this.acc = r);
|
|
1429
|
+
};
|
|
1430
|
+
Fold.prototype._e = function (err) {
|
|
1431
|
+
var u = this.out;
|
|
1432
|
+
if (u === NO$1)
|
|
1433
|
+
return;
|
|
1434
|
+
u._e(err);
|
|
1435
|
+
};
|
|
1436
|
+
Fold.prototype._c = function () {
|
|
1437
|
+
var u = this.out;
|
|
1438
|
+
if (u === NO$1)
|
|
1439
|
+
return;
|
|
1440
|
+
u._c();
|
|
1441
|
+
};
|
|
1442
|
+
return Fold;
|
|
1443
|
+
}());
|
|
1444
|
+
var Last = /** @class */ (function () {
|
|
1445
|
+
function Last(ins) {
|
|
1446
|
+
this.type = 'last';
|
|
1447
|
+
this.ins = ins;
|
|
1448
|
+
this.out = NO$1;
|
|
1449
|
+
this.has = false;
|
|
1450
|
+
this.val = NO$1;
|
|
1451
|
+
}
|
|
1452
|
+
Last.prototype._start = function (out) {
|
|
1453
|
+
this.out = out;
|
|
1454
|
+
this.has = false;
|
|
1455
|
+
this.ins._add(this);
|
|
1456
|
+
};
|
|
1457
|
+
Last.prototype._stop = function () {
|
|
1458
|
+
this.ins._remove(this);
|
|
1459
|
+
this.out = NO$1;
|
|
1460
|
+
this.val = NO$1;
|
|
1461
|
+
};
|
|
1462
|
+
Last.prototype._n = function (t) {
|
|
1463
|
+
this.has = true;
|
|
1464
|
+
this.val = t;
|
|
1465
|
+
};
|
|
1466
|
+
Last.prototype._e = function (err) {
|
|
1467
|
+
var u = this.out;
|
|
1468
|
+
if (u === NO$1)
|
|
1469
|
+
return;
|
|
1470
|
+
u._e(err);
|
|
1471
|
+
};
|
|
1472
|
+
Last.prototype._c = function () {
|
|
1473
|
+
var u = this.out;
|
|
1474
|
+
if (u === NO$1)
|
|
1475
|
+
return;
|
|
1476
|
+
if (this.has) {
|
|
1477
|
+
u._n(this.val);
|
|
1478
|
+
u._c();
|
|
1479
|
+
}
|
|
1480
|
+
else
|
|
1481
|
+
u._e(new Error('last() failed because input stream completed'));
|
|
1482
|
+
};
|
|
1483
|
+
return Last;
|
|
1484
|
+
}());
|
|
1485
|
+
var MapOp = /** @class */ (function () {
|
|
1486
|
+
function MapOp(project, ins) {
|
|
1487
|
+
this.type = 'map';
|
|
1488
|
+
this.ins = ins;
|
|
1489
|
+
this.out = NO$1;
|
|
1490
|
+
this.f = project;
|
|
1491
|
+
}
|
|
1492
|
+
MapOp.prototype._start = function (out) {
|
|
1493
|
+
this.out = out;
|
|
1494
|
+
this.ins._add(this);
|
|
1495
|
+
};
|
|
1496
|
+
MapOp.prototype._stop = function () {
|
|
1497
|
+
this.ins._remove(this);
|
|
1498
|
+
this.out = NO$1;
|
|
1499
|
+
};
|
|
1500
|
+
MapOp.prototype._n = function (t) {
|
|
1501
|
+
var u = this.out;
|
|
1502
|
+
if (u === NO$1)
|
|
1503
|
+
return;
|
|
1504
|
+
var r = _try(this, t, u);
|
|
1505
|
+
if (r === NO$1)
|
|
1506
|
+
return;
|
|
1507
|
+
u._n(r);
|
|
1508
|
+
};
|
|
1509
|
+
MapOp.prototype._e = function (err) {
|
|
1510
|
+
var u = this.out;
|
|
1511
|
+
if (u === NO$1)
|
|
1512
|
+
return;
|
|
1513
|
+
u._e(err);
|
|
1514
|
+
};
|
|
1515
|
+
MapOp.prototype._c = function () {
|
|
1516
|
+
var u = this.out;
|
|
1517
|
+
if (u === NO$1)
|
|
1518
|
+
return;
|
|
1519
|
+
u._c();
|
|
1520
|
+
};
|
|
1521
|
+
return MapOp;
|
|
1522
|
+
}());
|
|
1523
|
+
var Remember = /** @class */ (function () {
|
|
1524
|
+
function Remember(ins) {
|
|
1525
|
+
this.type = 'remember';
|
|
1526
|
+
this.ins = ins;
|
|
1527
|
+
this.out = NO$1;
|
|
1528
|
+
}
|
|
1529
|
+
Remember.prototype._start = function (out) {
|
|
1530
|
+
this.out = out;
|
|
1531
|
+
this.ins._add(out);
|
|
1532
|
+
};
|
|
1533
|
+
Remember.prototype._stop = function () {
|
|
1534
|
+
this.ins._remove(this.out);
|
|
1535
|
+
this.out = NO$1;
|
|
1536
|
+
};
|
|
1537
|
+
return Remember;
|
|
1538
|
+
}());
|
|
1539
|
+
var ReplaceError = /** @class */ (function () {
|
|
1540
|
+
function ReplaceError(replacer, ins) {
|
|
1541
|
+
this.type = 'replaceError';
|
|
1542
|
+
this.ins = ins;
|
|
1543
|
+
this.out = NO$1;
|
|
1544
|
+
this.f = replacer;
|
|
1545
|
+
}
|
|
1546
|
+
ReplaceError.prototype._start = function (out) {
|
|
1547
|
+
this.out = out;
|
|
1548
|
+
this.ins._add(this);
|
|
1549
|
+
};
|
|
1550
|
+
ReplaceError.prototype._stop = function () {
|
|
1551
|
+
this.ins._remove(this);
|
|
1552
|
+
this.out = NO$1;
|
|
1553
|
+
};
|
|
1554
|
+
ReplaceError.prototype._n = function (t) {
|
|
1555
|
+
var u = this.out;
|
|
1556
|
+
if (u === NO$1)
|
|
1557
|
+
return;
|
|
1558
|
+
u._n(t);
|
|
1559
|
+
};
|
|
1560
|
+
ReplaceError.prototype._e = function (err) {
|
|
1561
|
+
var u = this.out;
|
|
1562
|
+
if (u === NO$1)
|
|
1563
|
+
return;
|
|
1564
|
+
try {
|
|
1565
|
+
this.ins._remove(this);
|
|
1566
|
+
(this.ins = this.f(err))._add(this);
|
|
1567
|
+
}
|
|
1568
|
+
catch (e) {
|
|
1569
|
+
u._e(e);
|
|
1570
|
+
}
|
|
1571
|
+
};
|
|
1572
|
+
ReplaceError.prototype._c = function () {
|
|
1573
|
+
var u = this.out;
|
|
1574
|
+
if (u === NO$1)
|
|
1575
|
+
return;
|
|
1576
|
+
u._c();
|
|
1577
|
+
};
|
|
1578
|
+
return ReplaceError;
|
|
1579
|
+
}());
|
|
1580
|
+
var StartWith = /** @class */ (function () {
|
|
1581
|
+
function StartWith(ins, val) {
|
|
1582
|
+
this.type = 'startWith';
|
|
1583
|
+
this.ins = ins;
|
|
1584
|
+
this.out = NO$1;
|
|
1585
|
+
this.val = val;
|
|
1586
|
+
}
|
|
1587
|
+
StartWith.prototype._start = function (out) {
|
|
1588
|
+
this.out = out;
|
|
1589
|
+
this.out._n(this.val);
|
|
1590
|
+
this.ins._add(out);
|
|
1591
|
+
};
|
|
1592
|
+
StartWith.prototype._stop = function () {
|
|
1593
|
+
this.ins._remove(this.out);
|
|
1594
|
+
this.out = NO$1;
|
|
1595
|
+
};
|
|
1596
|
+
return StartWith;
|
|
1597
|
+
}());
|
|
1598
|
+
var Take = /** @class */ (function () {
|
|
1599
|
+
function Take(max, ins) {
|
|
1600
|
+
this.type = 'take';
|
|
1601
|
+
this.ins = ins;
|
|
1602
|
+
this.out = NO$1;
|
|
1603
|
+
this.max = max;
|
|
1604
|
+
this.taken = 0;
|
|
1605
|
+
}
|
|
1606
|
+
Take.prototype._start = function (out) {
|
|
1607
|
+
this.out = out;
|
|
1608
|
+
this.taken = 0;
|
|
1609
|
+
if (this.max <= 0)
|
|
1610
|
+
out._c();
|
|
1611
|
+
else
|
|
1612
|
+
this.ins._add(this);
|
|
1613
|
+
};
|
|
1614
|
+
Take.prototype._stop = function () {
|
|
1615
|
+
this.ins._remove(this);
|
|
1616
|
+
this.out = NO$1;
|
|
1617
|
+
};
|
|
1618
|
+
Take.prototype._n = function (t) {
|
|
1619
|
+
var u = this.out;
|
|
1620
|
+
if (u === NO$1)
|
|
1621
|
+
return;
|
|
1622
|
+
var m = ++this.taken;
|
|
1623
|
+
if (m < this.max)
|
|
1624
|
+
u._n(t);
|
|
1625
|
+
else if (m === this.max) {
|
|
1626
|
+
u._n(t);
|
|
1627
|
+
u._c();
|
|
1628
|
+
}
|
|
1629
|
+
};
|
|
1630
|
+
Take.prototype._e = function (err) {
|
|
1631
|
+
var u = this.out;
|
|
1632
|
+
if (u === NO$1)
|
|
1633
|
+
return;
|
|
1634
|
+
u._e(err);
|
|
1635
|
+
};
|
|
1636
|
+
Take.prototype._c = function () {
|
|
1637
|
+
var u = this.out;
|
|
1638
|
+
if (u === NO$1)
|
|
1639
|
+
return;
|
|
1640
|
+
u._c();
|
|
1641
|
+
};
|
|
1642
|
+
return Take;
|
|
1643
|
+
}());
|
|
1644
|
+
var Stream = /** @class */ (function () {
|
|
1645
|
+
function Stream(producer) {
|
|
1646
|
+
this._prod = producer || NO$1;
|
|
1647
|
+
this._ils = [];
|
|
1648
|
+
this._stopID = NO$1;
|
|
1649
|
+
this._dl = NO$1;
|
|
1650
|
+
this._d = false;
|
|
1651
|
+
this._target = null;
|
|
1652
|
+
this._err = NO$1;
|
|
1653
|
+
}
|
|
1654
|
+
Stream.prototype._n = function (t) {
|
|
1655
|
+
var a = this._ils;
|
|
1656
|
+
var L = a.length;
|
|
1657
|
+
if (this._d)
|
|
1658
|
+
this._dl._n(t);
|
|
1659
|
+
if (L == 1)
|
|
1660
|
+
a[0]._n(t);
|
|
1661
|
+
else if (L == 0)
|
|
1662
|
+
return;
|
|
1663
|
+
else {
|
|
1664
|
+
var b = cp(a);
|
|
1665
|
+
for (var i = 0; i < L; i++)
|
|
1666
|
+
b[i]._n(t);
|
|
1667
|
+
}
|
|
1668
|
+
};
|
|
1669
|
+
Stream.prototype._e = function (err) {
|
|
1670
|
+
if (this._err !== NO$1)
|
|
1671
|
+
return;
|
|
1672
|
+
this._err = err;
|
|
1673
|
+
var a = this._ils;
|
|
1674
|
+
var L = a.length;
|
|
1675
|
+
this._x();
|
|
1676
|
+
if (this._d)
|
|
1677
|
+
this._dl._e(err);
|
|
1678
|
+
if (L == 1)
|
|
1679
|
+
a[0]._e(err);
|
|
1680
|
+
else if (L == 0)
|
|
1681
|
+
return;
|
|
1682
|
+
else {
|
|
1683
|
+
var b = cp(a);
|
|
1684
|
+
for (var i = 0; i < L; i++)
|
|
1685
|
+
b[i]._e(err);
|
|
1686
|
+
}
|
|
1687
|
+
if (!this._d && L == 0)
|
|
1688
|
+
throw this._err;
|
|
1689
|
+
};
|
|
1690
|
+
Stream.prototype._c = function () {
|
|
1691
|
+
var a = this._ils;
|
|
1692
|
+
var L = a.length;
|
|
1693
|
+
this._x();
|
|
1694
|
+
if (this._d)
|
|
1695
|
+
this._dl._c();
|
|
1696
|
+
if (L == 1)
|
|
1697
|
+
a[0]._c();
|
|
1698
|
+
else if (L == 0)
|
|
1699
|
+
return;
|
|
1700
|
+
else {
|
|
1701
|
+
var b = cp(a);
|
|
1702
|
+
for (var i = 0; i < L; i++)
|
|
1703
|
+
b[i]._c();
|
|
1704
|
+
}
|
|
1705
|
+
};
|
|
1706
|
+
Stream.prototype._x = function () {
|
|
1707
|
+
if (this._ils.length === 0)
|
|
1708
|
+
return;
|
|
1709
|
+
if (this._prod !== NO$1)
|
|
1710
|
+
this._prod._stop();
|
|
1711
|
+
this._err = NO$1;
|
|
1712
|
+
this._ils = [];
|
|
1713
|
+
};
|
|
1714
|
+
Stream.prototype._stopNow = function () {
|
|
1715
|
+
// WARNING: code that calls this method should
|
|
1716
|
+
// first check if this._prod is valid (not `NO`)
|
|
1717
|
+
this._prod._stop();
|
|
1718
|
+
this._err = NO$1;
|
|
1719
|
+
this._stopID = NO$1;
|
|
1720
|
+
};
|
|
1721
|
+
Stream.prototype._add = function (il) {
|
|
1722
|
+
var ta = this._target;
|
|
1723
|
+
if (ta)
|
|
1724
|
+
return ta._add(il);
|
|
1725
|
+
var a = this._ils;
|
|
1726
|
+
a.push(il);
|
|
1727
|
+
if (a.length > 1)
|
|
1728
|
+
return;
|
|
1729
|
+
if (this._stopID !== NO$1) {
|
|
1730
|
+
clearTimeout(this._stopID);
|
|
1731
|
+
this._stopID = NO$1;
|
|
1732
|
+
}
|
|
1733
|
+
else {
|
|
1734
|
+
var p = this._prod;
|
|
1735
|
+
if (p !== NO$1)
|
|
1736
|
+
p._start(this);
|
|
1737
|
+
}
|
|
1738
|
+
};
|
|
1739
|
+
Stream.prototype._remove = function (il) {
|
|
1740
|
+
var _this = this;
|
|
1741
|
+
var ta = this._target;
|
|
1742
|
+
if (ta)
|
|
1743
|
+
return ta._remove(il);
|
|
1744
|
+
var a = this._ils;
|
|
1745
|
+
var i = a.indexOf(il);
|
|
1746
|
+
if (i > -1) {
|
|
1747
|
+
a.splice(i, 1);
|
|
1748
|
+
if (this._prod !== NO$1 && a.length <= 0) {
|
|
1749
|
+
this._err = NO$1;
|
|
1750
|
+
this._stopID = setTimeout(function () { return _this._stopNow(); });
|
|
1751
|
+
}
|
|
1752
|
+
else if (a.length === 1) {
|
|
1753
|
+
this._pruneCycles();
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
};
|
|
1757
|
+
// If all paths stemming from `this` stream eventually end at `this`
|
|
1758
|
+
// stream, then we remove the single listener of `this` stream, to
|
|
1759
|
+
// force it to end its execution and dispose resources. This method
|
|
1760
|
+
// assumes as a precondition that this._ils has just one listener.
|
|
1761
|
+
Stream.prototype._pruneCycles = function () {
|
|
1762
|
+
if (this._hasNoSinks(this, []))
|
|
1763
|
+
this._remove(this._ils[0]);
|
|
1764
|
+
};
|
|
1765
|
+
// Checks whether *there is no* path starting from `x` that leads to an end
|
|
1766
|
+
// listener (sink) in the stream graph, following edges A->B where B is a
|
|
1767
|
+
// listener of A. This means these paths constitute a cycle somehow. Is given
|
|
1768
|
+
// a trace of all visited nodes so far.
|
|
1769
|
+
Stream.prototype._hasNoSinks = function (x, trace) {
|
|
1770
|
+
if (trace.indexOf(x) !== -1)
|
|
1771
|
+
return true;
|
|
1772
|
+
else if (x.out === this)
|
|
1773
|
+
return true;
|
|
1774
|
+
else if (x.out && x.out !== NO$1)
|
|
1775
|
+
return this._hasNoSinks(x.out, trace.concat(x));
|
|
1776
|
+
else if (x._ils) {
|
|
1777
|
+
for (var i = 0, N = x._ils.length; i < N; i++)
|
|
1778
|
+
if (!this._hasNoSinks(x._ils[i], trace.concat(x)))
|
|
1779
|
+
return false;
|
|
1780
|
+
return true;
|
|
1781
|
+
}
|
|
1782
|
+
else
|
|
1783
|
+
return false;
|
|
1784
|
+
};
|
|
1785
|
+
Stream.prototype.ctor = function () {
|
|
1786
|
+
return this instanceof MemoryStream ? MemoryStream : Stream;
|
|
1787
|
+
};
|
|
1788
|
+
/**
|
|
1789
|
+
* Adds a Listener to the Stream.
|
|
1790
|
+
*
|
|
1791
|
+
* @param {Listener} listener
|
|
1792
|
+
*/
|
|
1793
|
+
Stream.prototype.addListener = function (listener) {
|
|
1794
|
+
listener._n = listener.next || noop;
|
|
1795
|
+
listener._e = listener.error || noop;
|
|
1796
|
+
listener._c = listener.complete || noop;
|
|
1797
|
+
this._add(listener);
|
|
1798
|
+
};
|
|
1799
|
+
/**
|
|
1800
|
+
* Removes a Listener from the Stream, assuming the Listener was added to it.
|
|
1801
|
+
*
|
|
1802
|
+
* @param {Listener<T>} listener
|
|
1803
|
+
*/
|
|
1804
|
+
Stream.prototype.removeListener = function (listener) {
|
|
1805
|
+
this._remove(listener);
|
|
1806
|
+
};
|
|
1807
|
+
/**
|
|
1808
|
+
* Adds a Listener to the Stream returning a Subscription to remove that
|
|
1809
|
+
* listener.
|
|
1810
|
+
*
|
|
1811
|
+
* @param {Listener} listener
|
|
1812
|
+
* @returns {Subscription}
|
|
1813
|
+
*/
|
|
1814
|
+
Stream.prototype.subscribe = function (listener) {
|
|
1815
|
+
this.addListener(listener);
|
|
1816
|
+
return new StreamSub(this, listener);
|
|
1817
|
+
};
|
|
1818
|
+
/**
|
|
1819
|
+
* Add interop between most.js and RxJS 5
|
|
1820
|
+
*
|
|
1821
|
+
* @returns {Stream}
|
|
1822
|
+
*/
|
|
1823
|
+
Stream.prototype[$$observable] = function () {
|
|
1824
|
+
return this;
|
|
1825
|
+
};
|
|
1826
|
+
/**
|
|
1827
|
+
* Creates a new Stream given a Producer.
|
|
1828
|
+
*
|
|
1829
|
+
* @factory true
|
|
1830
|
+
* @param {Producer} producer An optional Producer that dictates how to
|
|
1831
|
+
* start, generate events, and stop the Stream.
|
|
1832
|
+
* @return {Stream}
|
|
1833
|
+
*/
|
|
1834
|
+
Stream.create = function (producer) {
|
|
1835
|
+
if (producer) {
|
|
1836
|
+
if (typeof producer.start !== 'function'
|
|
1837
|
+
|| typeof producer.stop !== 'function')
|
|
1838
|
+
throw new Error('producer requires both start and stop functions');
|
|
1839
|
+
internalizeProducer(producer); // mutates the input
|
|
1840
|
+
}
|
|
1841
|
+
return new Stream(producer);
|
|
1842
|
+
};
|
|
1843
|
+
/**
|
|
1844
|
+
* Creates a new MemoryStream given a Producer.
|
|
1845
|
+
*
|
|
1846
|
+
* @factory true
|
|
1847
|
+
* @param {Producer} producer An optional Producer that dictates how to
|
|
1848
|
+
* start, generate events, and stop the Stream.
|
|
1849
|
+
* @return {MemoryStream}
|
|
1850
|
+
*/
|
|
1851
|
+
Stream.createWithMemory = function (producer) {
|
|
1852
|
+
if (producer)
|
|
1853
|
+
internalizeProducer(producer); // mutates the input
|
|
1854
|
+
return new MemoryStream(producer);
|
|
1855
|
+
};
|
|
1856
|
+
/**
|
|
1857
|
+
* Creates a Stream that does nothing when started. It never emits any event.
|
|
1858
|
+
*
|
|
1859
|
+
* Marble diagram:
|
|
1860
|
+
*
|
|
1861
|
+
* ```text
|
|
1862
|
+
* never
|
|
1863
|
+
* -----------------------
|
|
1864
|
+
* ```
|
|
1865
|
+
*
|
|
1866
|
+
* @factory true
|
|
1867
|
+
* @return {Stream}
|
|
1868
|
+
*/
|
|
1869
|
+
Stream.never = function () {
|
|
1870
|
+
return new Stream({ _start: noop, _stop: noop });
|
|
1871
|
+
};
|
|
1872
|
+
/**
|
|
1873
|
+
* Creates a Stream that immediately emits the "complete" notification when
|
|
1874
|
+
* started, and that's it.
|
|
1875
|
+
*
|
|
1876
|
+
* Marble diagram:
|
|
1877
|
+
*
|
|
1878
|
+
* ```text
|
|
1879
|
+
* empty
|
|
1880
|
+
* -|
|
|
1881
|
+
* ```
|
|
1882
|
+
*
|
|
1883
|
+
* @factory true
|
|
1884
|
+
* @return {Stream}
|
|
1885
|
+
*/
|
|
1886
|
+
Stream.empty = function () {
|
|
1887
|
+
return new Stream({
|
|
1888
|
+
_start: function (il) { il._c(); },
|
|
1889
|
+
_stop: noop,
|
|
1890
|
+
});
|
|
1891
|
+
};
|
|
1892
|
+
/**
|
|
1893
|
+
* Creates a Stream that immediately emits an "error" notification with the
|
|
1894
|
+
* value you passed as the `error` argument when the stream starts, and that's
|
|
1895
|
+
* it.
|
|
1896
|
+
*
|
|
1897
|
+
* Marble diagram:
|
|
1898
|
+
*
|
|
1899
|
+
* ```text
|
|
1900
|
+
* throw(X)
|
|
1901
|
+
* -X
|
|
1902
|
+
* ```
|
|
1903
|
+
*
|
|
1904
|
+
* @factory true
|
|
1905
|
+
* @param error The error event to emit on the created stream.
|
|
1906
|
+
* @return {Stream}
|
|
1907
|
+
*/
|
|
1908
|
+
Stream.throw = function (error) {
|
|
1909
|
+
return new Stream({
|
|
1910
|
+
_start: function (il) { il._e(error); },
|
|
1911
|
+
_stop: noop,
|
|
1912
|
+
});
|
|
1913
|
+
};
|
|
1914
|
+
/**
|
|
1915
|
+
* Creates a stream from an Array, Promise, or an Observable.
|
|
1916
|
+
*
|
|
1917
|
+
* @factory true
|
|
1918
|
+
* @param {Array|PromiseLike|Observable} input The input to make a stream from.
|
|
1919
|
+
* @return {Stream}
|
|
1920
|
+
*/
|
|
1921
|
+
Stream.from = function (input) {
|
|
1922
|
+
if (typeof input[$$observable] === 'function')
|
|
1923
|
+
return Stream.fromObservable(input);
|
|
1924
|
+
else if (typeof input.then === 'function')
|
|
1925
|
+
return Stream.fromPromise(input);
|
|
1926
|
+
else if (Array.isArray(input))
|
|
1927
|
+
return Stream.fromArray(input);
|
|
1928
|
+
throw new TypeError("Type of input to from() must be an Array, Promise, or Observable");
|
|
1929
|
+
};
|
|
1930
|
+
/**
|
|
1931
|
+
* Creates a Stream that immediately emits the arguments that you give to
|
|
1932
|
+
* *of*, then completes.
|
|
1933
|
+
*
|
|
1934
|
+
* Marble diagram:
|
|
1935
|
+
*
|
|
1936
|
+
* ```text
|
|
1937
|
+
* of(1,2,3)
|
|
1938
|
+
* 123|
|
|
1939
|
+
* ```
|
|
1940
|
+
*
|
|
1941
|
+
* @factory true
|
|
1942
|
+
* @param a The first value you want to emit as an event on the stream.
|
|
1943
|
+
* @param b The second value you want to emit as an event on the stream. One
|
|
1944
|
+
* or more of these values may be given as arguments.
|
|
1945
|
+
* @return {Stream}
|
|
1946
|
+
*/
|
|
1947
|
+
Stream.of = function () {
|
|
1948
|
+
var items = [];
|
|
1949
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1950
|
+
items[_i] = arguments[_i];
|
|
1951
|
+
}
|
|
1952
|
+
return Stream.fromArray(items);
|
|
1953
|
+
};
|
|
1954
|
+
/**
|
|
1955
|
+
* Converts an array to a stream. The returned stream will emit synchronously
|
|
1956
|
+
* all the items in the array, and then complete.
|
|
1957
|
+
*
|
|
1958
|
+
* Marble diagram:
|
|
1959
|
+
*
|
|
1960
|
+
* ```text
|
|
1961
|
+
* fromArray([1,2,3])
|
|
1962
|
+
* 123|
|
|
1963
|
+
* ```
|
|
1964
|
+
*
|
|
1965
|
+
* @factory true
|
|
1966
|
+
* @param {Array} array The array to be converted as a stream.
|
|
1967
|
+
* @return {Stream}
|
|
1968
|
+
*/
|
|
1969
|
+
Stream.fromArray = function (array) {
|
|
1970
|
+
return new Stream(new FromArray(array));
|
|
1971
|
+
};
|
|
1972
|
+
/**
|
|
1973
|
+
* Converts a promise to a stream. The returned stream will emit the resolved
|
|
1974
|
+
* value of the promise, and then complete. However, if the promise is
|
|
1975
|
+
* rejected, the stream will emit the corresponding error.
|
|
1976
|
+
*
|
|
1977
|
+
* Marble diagram:
|
|
1978
|
+
*
|
|
1979
|
+
* ```text
|
|
1980
|
+
* fromPromise( ----42 )
|
|
1981
|
+
* -----------------42|
|
|
1982
|
+
* ```
|
|
1983
|
+
*
|
|
1984
|
+
* @factory true
|
|
1985
|
+
* @param {PromiseLike} promise The promise to be converted as a stream.
|
|
1986
|
+
* @return {Stream}
|
|
1987
|
+
*/
|
|
1988
|
+
Stream.fromPromise = function (promise) {
|
|
1989
|
+
return new Stream(new FromPromise(promise));
|
|
1990
|
+
};
|
|
1991
|
+
/**
|
|
1992
|
+
* Converts an Observable into a Stream.
|
|
1993
|
+
*
|
|
1994
|
+
* @factory true
|
|
1995
|
+
* @param {any} observable The observable to be converted as a stream.
|
|
1996
|
+
* @return {Stream}
|
|
1997
|
+
*/
|
|
1998
|
+
Stream.fromObservable = function (obs) {
|
|
1999
|
+
if (obs.endWhen !== undefined)
|
|
2000
|
+
return obs;
|
|
2001
|
+
var o = typeof obs[$$observable] === 'function' ? obs[$$observable]() : obs;
|
|
2002
|
+
return new Stream(new FromObservable(o));
|
|
2003
|
+
};
|
|
2004
|
+
/**
|
|
2005
|
+
* Creates a stream that periodically emits incremental numbers, every
|
|
2006
|
+
* `period` milliseconds.
|
|
2007
|
+
*
|
|
2008
|
+
* Marble diagram:
|
|
2009
|
+
*
|
|
2010
|
+
* ```text
|
|
2011
|
+
* periodic(1000)
|
|
2012
|
+
* ---0---1---2---3---4---...
|
|
2013
|
+
* ```
|
|
2014
|
+
*
|
|
2015
|
+
* @factory true
|
|
2016
|
+
* @param {number} period The interval in milliseconds to use as a rate of
|
|
2017
|
+
* emission.
|
|
2018
|
+
* @return {Stream}
|
|
2019
|
+
*/
|
|
2020
|
+
Stream.periodic = function (period) {
|
|
2021
|
+
return new Stream(new Periodic(period));
|
|
2022
|
+
};
|
|
2023
|
+
Stream.prototype._map = function (project) {
|
|
2024
|
+
return new (this.ctor())(new MapOp(project, this));
|
|
2025
|
+
};
|
|
2026
|
+
/**
|
|
2027
|
+
* Transforms each event from the input Stream through a `project` function,
|
|
2028
|
+
* to get a Stream that emits those transformed events.
|
|
2029
|
+
*
|
|
2030
|
+
* Marble diagram:
|
|
2031
|
+
*
|
|
2032
|
+
* ```text
|
|
2033
|
+
* --1---3--5-----7------
|
|
2034
|
+
* map(i => i * 10)
|
|
2035
|
+
* --10--30-50----70-----
|
|
2036
|
+
* ```
|
|
2037
|
+
*
|
|
2038
|
+
* @param {Function} project A function of type `(t: T) => U` that takes event
|
|
2039
|
+
* `t` of type `T` from the input Stream and produces an event of type `U`, to
|
|
2040
|
+
* be emitted on the output Stream.
|
|
2041
|
+
* @return {Stream}
|
|
2042
|
+
*/
|
|
2043
|
+
Stream.prototype.map = function (project) {
|
|
2044
|
+
return this._map(project);
|
|
2045
|
+
};
|
|
2046
|
+
/**
|
|
2047
|
+
* It's like `map`, but transforms each input event to always the same
|
|
2048
|
+
* constant value on the output Stream.
|
|
2049
|
+
*
|
|
2050
|
+
* Marble diagram:
|
|
2051
|
+
*
|
|
2052
|
+
* ```text
|
|
2053
|
+
* --1---3--5-----7-----
|
|
2054
|
+
* mapTo(10)
|
|
2055
|
+
* --10--10-10----10----
|
|
2056
|
+
* ```
|
|
2057
|
+
*
|
|
2058
|
+
* @param projectedValue A value to emit on the output Stream whenever the
|
|
2059
|
+
* input Stream emits any value.
|
|
2060
|
+
* @return {Stream}
|
|
2061
|
+
*/
|
|
2062
|
+
Stream.prototype.mapTo = function (projectedValue) {
|
|
2063
|
+
var s = this.map(function () { return projectedValue; });
|
|
2064
|
+
var op = s._prod;
|
|
2065
|
+
op.type = 'mapTo';
|
|
2066
|
+
return s;
|
|
2067
|
+
};
|
|
2068
|
+
/**
|
|
2069
|
+
* Only allows events that pass the test given by the `passes` argument.
|
|
2070
|
+
*
|
|
2071
|
+
* Each event from the input stream is given to the `passes` function. If the
|
|
2072
|
+
* function returns `true`, the event is forwarded to the output stream,
|
|
2073
|
+
* otherwise it is ignored and not forwarded.
|
|
2074
|
+
*
|
|
2075
|
+
* Marble diagram:
|
|
2076
|
+
*
|
|
2077
|
+
* ```text
|
|
2078
|
+
* --1---2--3-----4-----5---6--7-8--
|
|
2079
|
+
* filter(i => i % 2 === 0)
|
|
2080
|
+
* ------2--------4---------6----8--
|
|
2081
|
+
* ```
|
|
2082
|
+
*
|
|
2083
|
+
* @param {Function} passes A function of type `(t: T) => boolean` that takes
|
|
2084
|
+
* an event from the input stream and checks if it passes, by returning a
|
|
2085
|
+
* boolean.
|
|
2086
|
+
* @return {Stream}
|
|
2087
|
+
*/
|
|
2088
|
+
Stream.prototype.filter = function (passes) {
|
|
2089
|
+
var p = this._prod;
|
|
2090
|
+
if (p instanceof Filter)
|
|
2091
|
+
return new Stream(new Filter(and(p.f, passes), p.ins));
|
|
2092
|
+
return new Stream(new Filter(passes, this));
|
|
2093
|
+
};
|
|
2094
|
+
/**
|
|
2095
|
+
* Lets the first `amount` many events from the input stream pass to the
|
|
2096
|
+
* output stream, then makes the output stream complete.
|
|
2097
|
+
*
|
|
2098
|
+
* Marble diagram:
|
|
2099
|
+
*
|
|
2100
|
+
* ```text
|
|
2101
|
+
* --a---b--c----d---e--
|
|
2102
|
+
* take(3)
|
|
2103
|
+
* --a---b--c|
|
|
2104
|
+
* ```
|
|
2105
|
+
*
|
|
2106
|
+
* @param {number} amount How many events to allow from the input stream
|
|
2107
|
+
* before completing the output stream.
|
|
2108
|
+
* @return {Stream}
|
|
2109
|
+
*/
|
|
2110
|
+
Stream.prototype.take = function (amount) {
|
|
2111
|
+
return new (this.ctor())(new Take(amount, this));
|
|
2112
|
+
};
|
|
2113
|
+
/**
|
|
2114
|
+
* Ignores the first `amount` many events from the input stream, and then
|
|
2115
|
+
* after that starts forwarding events from the input stream to the output
|
|
2116
|
+
* stream.
|
|
2117
|
+
*
|
|
2118
|
+
* Marble diagram:
|
|
2119
|
+
*
|
|
2120
|
+
* ```text
|
|
2121
|
+
* --a---b--c----d---e--
|
|
2122
|
+
* drop(3)
|
|
2123
|
+
* --------------d---e--
|
|
2124
|
+
* ```
|
|
2125
|
+
*
|
|
2126
|
+
* @param {number} amount How many events to ignore from the input stream
|
|
2127
|
+
* before forwarding all events from the input stream to the output stream.
|
|
2128
|
+
* @return {Stream}
|
|
2129
|
+
*/
|
|
2130
|
+
Stream.prototype.drop = function (amount) {
|
|
2131
|
+
return new Stream(new Drop(amount, this));
|
|
2132
|
+
};
|
|
2133
|
+
/**
|
|
2134
|
+
* When the input stream completes, the output stream will emit the last event
|
|
2135
|
+
* emitted by the input stream, and then will also complete.
|
|
2136
|
+
*
|
|
2137
|
+
* Marble diagram:
|
|
2138
|
+
*
|
|
2139
|
+
* ```text
|
|
2140
|
+
* --a---b--c--d----|
|
|
2141
|
+
* last()
|
|
2142
|
+
* -----------------d|
|
|
2143
|
+
* ```
|
|
2144
|
+
*
|
|
2145
|
+
* @return {Stream}
|
|
2146
|
+
*/
|
|
2147
|
+
Stream.prototype.last = function () {
|
|
2148
|
+
return new Stream(new Last(this));
|
|
2149
|
+
};
|
|
2150
|
+
/**
|
|
2151
|
+
* Prepends the given `initial` value to the sequence of events emitted by the
|
|
2152
|
+
* input stream. The returned stream is a MemoryStream, which means it is
|
|
2153
|
+
* already `remember()`'d.
|
|
2154
|
+
*
|
|
2155
|
+
* Marble diagram:
|
|
2156
|
+
*
|
|
2157
|
+
* ```text
|
|
2158
|
+
* ---1---2-----3---
|
|
2159
|
+
* startWith(0)
|
|
2160
|
+
* 0--1---2-----3---
|
|
2161
|
+
* ```
|
|
2162
|
+
*
|
|
2163
|
+
* @param initial The value or event to prepend.
|
|
2164
|
+
* @return {MemoryStream}
|
|
2165
|
+
*/
|
|
2166
|
+
Stream.prototype.startWith = function (initial) {
|
|
2167
|
+
return new MemoryStream(new StartWith(this, initial));
|
|
2168
|
+
};
|
|
2169
|
+
/**
|
|
2170
|
+
* Uses another stream to determine when to complete the current stream.
|
|
2171
|
+
*
|
|
2172
|
+
* When the given `other` stream emits an event or completes, the output
|
|
2173
|
+
* stream will complete. Before that happens, the output stream will behaves
|
|
2174
|
+
* like the input stream.
|
|
2175
|
+
*
|
|
2176
|
+
* Marble diagram:
|
|
2177
|
+
*
|
|
2178
|
+
* ```text
|
|
2179
|
+
* ---1---2-----3--4----5----6---
|
|
2180
|
+
* endWhen( --------a--b--| )
|
|
2181
|
+
* ---1---2-----3--4--|
|
|
2182
|
+
* ```
|
|
2183
|
+
*
|
|
2184
|
+
* @param other Some other stream that is used to know when should the output
|
|
2185
|
+
* stream of this operator complete.
|
|
2186
|
+
* @return {Stream}
|
|
2187
|
+
*/
|
|
2188
|
+
Stream.prototype.endWhen = function (other) {
|
|
2189
|
+
return new (this.ctor())(new EndWhen(other, this));
|
|
2190
|
+
};
|
|
2191
|
+
/**
|
|
2192
|
+
* "Folds" the stream onto itself.
|
|
2193
|
+
*
|
|
2194
|
+
* Combines events from the past throughout
|
|
2195
|
+
* the entire execution of the input stream, allowing you to accumulate them
|
|
2196
|
+
* together. It's essentially like `Array.prototype.reduce`. The returned
|
|
2197
|
+
* stream is a MemoryStream, which means it is already `remember()`'d.
|
|
2198
|
+
*
|
|
2199
|
+
* The output stream starts by emitting the `seed` which you give as argument.
|
|
2200
|
+
* Then, when an event happens on the input stream, it is combined with that
|
|
2201
|
+
* seed value through the `accumulate` function, and the output value is
|
|
2202
|
+
* emitted on the output stream. `fold` remembers that output value as `acc`
|
|
2203
|
+
* ("accumulator"), and then when a new input event `t` happens, `acc` will be
|
|
2204
|
+
* combined with that to produce the new `acc` and so forth.
|
|
2205
|
+
*
|
|
2206
|
+
* Marble diagram:
|
|
2207
|
+
*
|
|
2208
|
+
* ```text
|
|
2209
|
+
* ------1-----1--2----1----1------
|
|
2210
|
+
* fold((acc, x) => acc + x, 3)
|
|
2211
|
+
* 3-----4-----5--7----8----9------
|
|
2212
|
+
* ```
|
|
2213
|
+
*
|
|
2214
|
+
* @param {Function} accumulate A function of type `(acc: R, t: T) => R` that
|
|
2215
|
+
* takes the previous accumulated value `acc` and the incoming event from the
|
|
2216
|
+
* input stream and produces the new accumulated value.
|
|
2217
|
+
* @param seed The initial accumulated value, of type `R`.
|
|
2218
|
+
* @return {MemoryStream}
|
|
2219
|
+
*/
|
|
2220
|
+
Stream.prototype.fold = function (accumulate, seed) {
|
|
2221
|
+
return new MemoryStream(new Fold(accumulate, seed, this));
|
|
2222
|
+
};
|
|
2223
|
+
/**
|
|
2224
|
+
* Replaces an error with another stream.
|
|
2225
|
+
*
|
|
2226
|
+
* When (and if) an error happens on the input stream, instead of forwarding
|
|
2227
|
+
* that error to the output stream, *replaceError* will call the `replace`
|
|
2228
|
+
* function which returns the stream that the output stream will replicate.
|
|
2229
|
+
* And, in case that new stream also emits an error, `replace` will be called
|
|
2230
|
+
* again to get another stream to start replicating.
|
|
2231
|
+
*
|
|
2232
|
+
* Marble diagram:
|
|
2233
|
+
*
|
|
2234
|
+
* ```text
|
|
2235
|
+
* --1---2-----3--4-----X
|
|
2236
|
+
* replaceError( () => --10--| )
|
|
2237
|
+
* --1---2-----3--4--------10--|
|
|
2238
|
+
* ```
|
|
2239
|
+
*
|
|
2240
|
+
* @param {Function} replace A function of type `(err) => Stream` that takes
|
|
2241
|
+
* the error that occurred on the input stream or on the previous replacement
|
|
2242
|
+
* stream and returns a new stream. The output stream will behave like the
|
|
2243
|
+
* stream that this function returns.
|
|
2244
|
+
* @return {Stream}
|
|
2245
|
+
*/
|
|
2246
|
+
Stream.prototype.replaceError = function (replace) {
|
|
2247
|
+
return new (this.ctor())(new ReplaceError(replace, this));
|
|
2248
|
+
};
|
|
2249
|
+
/**
|
|
2250
|
+
* Flattens a "stream of streams", handling only one nested stream at a time
|
|
2251
|
+
* (no concurrency).
|
|
2252
|
+
*
|
|
2253
|
+
* If the input stream is a stream that emits streams, then this operator will
|
|
2254
|
+
* return an output stream which is a flat stream: emits regular events. The
|
|
2255
|
+
* flattening happens without concurrency. It works like this: when the input
|
|
2256
|
+
* stream emits a nested stream, *flatten* will start imitating that nested
|
|
2257
|
+
* one. However, as soon as the next nested stream is emitted on the input
|
|
2258
|
+
* stream, *flatten* will forget the previous nested one it was imitating, and
|
|
2259
|
+
* will start imitating the new nested one.
|
|
2260
|
+
*
|
|
2261
|
+
* Marble diagram:
|
|
2262
|
+
*
|
|
2263
|
+
* ```text
|
|
2264
|
+
* --+--------+---------------
|
|
2265
|
+
* \ \
|
|
2266
|
+
* \ ----1----2---3--
|
|
2267
|
+
* --a--b----c----d--------
|
|
2268
|
+
* flatten
|
|
2269
|
+
* -----a--b------1----2---3--
|
|
2270
|
+
* ```
|
|
2271
|
+
*
|
|
2272
|
+
* @return {Stream}
|
|
2273
|
+
*/
|
|
2274
|
+
Stream.prototype.flatten = function () {
|
|
2275
|
+
return new Stream(new Flatten(this));
|
|
2276
|
+
};
|
|
2277
|
+
/**
|
|
2278
|
+
* Passes the input stream to a custom operator, to produce an output stream.
|
|
2279
|
+
*
|
|
2280
|
+
* *compose* is a handy way of using an existing function in a chained style.
|
|
2281
|
+
* Instead of writing `outStream = f(inStream)` you can write
|
|
2282
|
+
* `outStream = inStream.compose(f)`.
|
|
2283
|
+
*
|
|
2284
|
+
* @param {function} operator A function that takes a stream as input and
|
|
2285
|
+
* returns a stream as well.
|
|
2286
|
+
* @return {Stream}
|
|
2287
|
+
*/
|
|
2288
|
+
Stream.prototype.compose = function (operator) {
|
|
2289
|
+
return operator(this);
|
|
2290
|
+
};
|
|
2291
|
+
/**
|
|
2292
|
+
* Returns an output stream that behaves like the input stream, but also
|
|
2293
|
+
* remembers the most recent event that happens on the input stream, so that a
|
|
2294
|
+
* newly added listener will immediately receive that memorised event.
|
|
2295
|
+
*
|
|
2296
|
+
* @return {MemoryStream}
|
|
2297
|
+
*/
|
|
2298
|
+
Stream.prototype.remember = function () {
|
|
2299
|
+
return new MemoryStream(new Remember(this));
|
|
2300
|
+
};
|
|
2301
|
+
/**
|
|
2302
|
+
* Returns an output stream that identically behaves like the input stream,
|
|
2303
|
+
* but also runs a `spy` function for each event, to help you debug your app.
|
|
2304
|
+
*
|
|
2305
|
+
* *debug* takes a `spy` function as argument, and runs that for each event
|
|
2306
|
+
* happening on the input stream. If you don't provide the `spy` argument,
|
|
2307
|
+
* then *debug* will just `console.log` each event. This helps you to
|
|
2308
|
+
* understand the flow of events through some operator chain.
|
|
2309
|
+
*
|
|
2310
|
+
* Please note that if the output stream has no listeners, then it will not
|
|
2311
|
+
* start, which means `spy` will never run because no actual event happens in
|
|
2312
|
+
* that case.
|
|
2313
|
+
*
|
|
2314
|
+
* Marble diagram:
|
|
2315
|
+
*
|
|
2316
|
+
* ```text
|
|
2317
|
+
* --1----2-----3-----4--
|
|
2318
|
+
* debug
|
|
2319
|
+
* --1----2-----3-----4--
|
|
2320
|
+
* ```
|
|
2321
|
+
*
|
|
2322
|
+
* @param {function} labelOrSpy A string to use as the label when printing
|
|
2323
|
+
* debug information on the console, or a 'spy' function that takes an event
|
|
2324
|
+
* as argument, and does not need to return anything.
|
|
2325
|
+
* @return {Stream}
|
|
2326
|
+
*/
|
|
2327
|
+
Stream.prototype.debug = function (labelOrSpy) {
|
|
2328
|
+
return new (this.ctor())(new Debug(this, labelOrSpy));
|
|
2329
|
+
};
|
|
2330
|
+
/**
|
|
2331
|
+
* *imitate* changes this current Stream to emit the same events that the
|
|
2332
|
+
* `other` given Stream does. This method returns nothing.
|
|
2333
|
+
*
|
|
2334
|
+
* This method exists to allow one thing: **circular dependency of streams**.
|
|
2335
|
+
* For instance, let's imagine that for some reason you need to create a
|
|
2336
|
+
* circular dependency where stream `first$` depends on stream `second$`
|
|
2337
|
+
* which in turn depends on `first$`:
|
|
2338
|
+
*
|
|
2339
|
+
* <!-- skip-example -->
|
|
2340
|
+
* ```js
|
|
2341
|
+
* import delay from 'xstream/extra/delay'
|
|
2342
|
+
*
|
|
2343
|
+
* var first$ = second$.map(x => x * 10).take(3);
|
|
2344
|
+
* var second$ = first$.map(x => x + 1).startWith(1).compose(delay(100));
|
|
2345
|
+
* ```
|
|
2346
|
+
*
|
|
2347
|
+
* However, that is invalid JavaScript, because `second$` is undefined
|
|
2348
|
+
* on the first line. This is how *imitate* can help solve it:
|
|
2349
|
+
*
|
|
2350
|
+
* ```js
|
|
2351
|
+
* import delay from 'xstream/extra/delay'
|
|
2352
|
+
*
|
|
2353
|
+
* var secondProxy$ = xs.create();
|
|
2354
|
+
* var first$ = secondProxy$.map(x => x * 10).take(3);
|
|
2355
|
+
* var second$ = first$.map(x => x + 1).startWith(1).compose(delay(100));
|
|
2356
|
+
* secondProxy$.imitate(second$);
|
|
2357
|
+
* ```
|
|
2358
|
+
*
|
|
2359
|
+
* We create `secondProxy$` before the others, so it can be used in the
|
|
2360
|
+
* declaration of `first$`. Then, after both `first$` and `second$` are
|
|
2361
|
+
* defined, we hook `secondProxy$` with `second$` with `imitate()` to tell
|
|
2362
|
+
* that they are "the same". `imitate` will not trigger the start of any
|
|
2363
|
+
* stream, it just binds `secondProxy$` and `second$` together.
|
|
2364
|
+
*
|
|
2365
|
+
* The following is an example where `imitate()` is important in Cycle.js
|
|
2366
|
+
* applications. A parent component contains some child components. A child
|
|
2367
|
+
* has an action stream which is given to the parent to define its state:
|
|
2368
|
+
*
|
|
2369
|
+
* <!-- skip-example -->
|
|
2370
|
+
* ```js
|
|
2371
|
+
* const childActionProxy$ = xs.create();
|
|
2372
|
+
* const parent = Parent({...sources, childAction$: childActionProxy$});
|
|
2373
|
+
* const childAction$ = parent.state$.map(s => s.child.action$).flatten();
|
|
2374
|
+
* childActionProxy$.imitate(childAction$);
|
|
2375
|
+
* ```
|
|
2376
|
+
*
|
|
2377
|
+
* Note, though, that **`imitate()` does not support MemoryStreams**. If we
|
|
2378
|
+
* would attempt to imitate a MemoryStream in a circular dependency, we would
|
|
2379
|
+
* either get a race condition (where the symptom would be "nothing happens")
|
|
2380
|
+
* or an infinite cyclic emission of values. It's useful to think about
|
|
2381
|
+
* MemoryStreams as cells in a spreadsheet. It doesn't make any sense to
|
|
2382
|
+
* define a spreadsheet cell `A1` with a formula that depends on `B1` and
|
|
2383
|
+
* cell `B1` defined with a formula that depends on `A1`.
|
|
2384
|
+
*
|
|
2385
|
+
* If you find yourself wanting to use `imitate()` with a
|
|
2386
|
+
* MemoryStream, you should rework your code around `imitate()` to use a
|
|
2387
|
+
* Stream instead. Look for the stream in the circular dependency that
|
|
2388
|
+
* represents an event stream, and that would be a candidate for creating a
|
|
2389
|
+
* proxy Stream which then imitates the target Stream.
|
|
2390
|
+
*
|
|
2391
|
+
* @param {Stream} target The other stream to imitate on the current one. Must
|
|
2392
|
+
* not be a MemoryStream.
|
|
2393
|
+
*/
|
|
2394
|
+
Stream.prototype.imitate = function (target) {
|
|
2395
|
+
if (target instanceof MemoryStream)
|
|
2396
|
+
throw new Error('A MemoryStream was given to imitate(), but it only ' +
|
|
2397
|
+
'supports a Stream. Read more about this restriction here: ' +
|
|
2398
|
+
'https://github.com/staltz/xstream#faq');
|
|
2399
|
+
this._target = target;
|
|
2400
|
+
for (var ils = this._ils, N = ils.length, i = 0; i < N; i++)
|
|
2401
|
+
target._add(ils[i]);
|
|
2402
|
+
this._ils = [];
|
|
2403
|
+
};
|
|
2404
|
+
/**
|
|
2405
|
+
* Forces the Stream to emit the given value to its listeners.
|
|
2406
|
+
*
|
|
2407
|
+
* As the name indicates, if you use this, you are most likely doing something
|
|
2408
|
+
* The Wrong Way. Please try to understand the reactive way before using this
|
|
2409
|
+
* method. Use it only when you know what you are doing.
|
|
2410
|
+
*
|
|
2411
|
+
* @param value The "next" value you want to broadcast to all listeners of
|
|
2412
|
+
* this Stream.
|
|
2413
|
+
*/
|
|
2414
|
+
Stream.prototype.shamefullySendNext = function (value) {
|
|
2415
|
+
this._n(value);
|
|
2416
|
+
};
|
|
2417
|
+
/**
|
|
2418
|
+
* Forces the Stream to emit the given error to its listeners.
|
|
2419
|
+
*
|
|
2420
|
+
* As the name indicates, if you use this, you are most likely doing something
|
|
2421
|
+
* The Wrong Way. Please try to understand the reactive way before using this
|
|
2422
|
+
* method. Use it only when you know what you are doing.
|
|
2423
|
+
*
|
|
2424
|
+
* @param {any} error The error you want to broadcast to all the listeners of
|
|
2425
|
+
* this Stream.
|
|
2426
|
+
*/
|
|
2427
|
+
Stream.prototype.shamefullySendError = function (error) {
|
|
2428
|
+
this._e(error);
|
|
2429
|
+
};
|
|
2430
|
+
/**
|
|
2431
|
+
* Forces the Stream to emit the "completed" event to its listeners.
|
|
2432
|
+
*
|
|
2433
|
+
* As the name indicates, if you use this, you are most likely doing something
|
|
2434
|
+
* The Wrong Way. Please try to understand the reactive way before using this
|
|
2435
|
+
* method. Use it only when you know what you are doing.
|
|
2436
|
+
*/
|
|
2437
|
+
Stream.prototype.shamefullySendComplete = function () {
|
|
2438
|
+
this._c();
|
|
2439
|
+
};
|
|
2440
|
+
/**
|
|
2441
|
+
* Adds a "debug" listener to the stream. There can only be one debug
|
|
2442
|
+
* listener, that's why this is 'setDebugListener'. To remove the debug
|
|
2443
|
+
* listener, just call setDebugListener(null).
|
|
2444
|
+
*
|
|
2445
|
+
* A debug listener is like any other listener. The only difference is that a
|
|
2446
|
+
* debug listener is "stealthy": its presence/absence does not trigger the
|
|
2447
|
+
* start/stop of the stream (or the producer inside the stream). This is
|
|
2448
|
+
* useful so you can inspect what is going on without changing the behavior
|
|
2449
|
+
* of the program. If you have an idle stream and you add a normal listener to
|
|
2450
|
+
* it, the stream will start executing. But if you set a debug listener on an
|
|
2451
|
+
* idle stream, it won't start executing (not until the first normal listener
|
|
2452
|
+
* is added).
|
|
2453
|
+
*
|
|
2454
|
+
* As the name indicates, we don't recommend using this method to build app
|
|
2455
|
+
* logic. In fact, in most cases the debug operator works just fine. Only use
|
|
2456
|
+
* this one if you know what you're doing.
|
|
2457
|
+
*
|
|
2458
|
+
* @param {Listener<T>} listener
|
|
2459
|
+
*/
|
|
2460
|
+
Stream.prototype.setDebugListener = function (listener) {
|
|
2461
|
+
if (!listener) {
|
|
2462
|
+
this._d = false;
|
|
2463
|
+
this._dl = NO$1;
|
|
2464
|
+
}
|
|
2465
|
+
else {
|
|
2466
|
+
this._d = true;
|
|
2467
|
+
listener._n = listener.next || noop;
|
|
2468
|
+
listener._e = listener.error || noop;
|
|
2469
|
+
listener._c = listener.complete || noop;
|
|
2470
|
+
this._dl = listener;
|
|
2471
|
+
}
|
|
2472
|
+
};
|
|
2473
|
+
/**
|
|
2474
|
+
* Blends multiple streams together, emitting events from all of them
|
|
2475
|
+
* concurrently.
|
|
2476
|
+
*
|
|
2477
|
+
* *merge* takes multiple streams as arguments, and creates a stream that
|
|
2478
|
+
* behaves like each of the argument streams, in parallel.
|
|
2479
|
+
*
|
|
2480
|
+
* Marble diagram:
|
|
2481
|
+
*
|
|
2482
|
+
* ```text
|
|
2483
|
+
* --1----2-----3--------4---
|
|
2484
|
+
* ----a-----b----c---d------
|
|
2485
|
+
* merge
|
|
2486
|
+
* --1-a--2--b--3-c---d--4---
|
|
2487
|
+
* ```
|
|
2488
|
+
*
|
|
2489
|
+
* @factory true
|
|
2490
|
+
* @param {Stream} stream1 A stream to merge together with other streams.
|
|
2491
|
+
* @param {Stream} stream2 A stream to merge together with other streams. Two
|
|
2492
|
+
* or more streams may be given as arguments.
|
|
2493
|
+
* @return {Stream}
|
|
2494
|
+
*/
|
|
2495
|
+
Stream.merge = function merge() {
|
|
2496
|
+
var streams = [];
|
|
2497
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2498
|
+
streams[_i] = arguments[_i];
|
|
2499
|
+
}
|
|
2500
|
+
return new Stream(new Merge(streams));
|
|
2501
|
+
};
|
|
2502
|
+
/**
|
|
2503
|
+
* Combines multiple input streams together to return a stream whose events
|
|
2504
|
+
* are arrays that collect the latest events from each input stream.
|
|
2505
|
+
*
|
|
2506
|
+
* *combine* internally remembers the most recent event from each of the input
|
|
2507
|
+
* streams. When any of the input streams emits an event, that event together
|
|
2508
|
+
* with all the other saved events are combined into an array. That array will
|
|
2509
|
+
* be emitted on the output stream. It's essentially a way of joining together
|
|
2510
|
+
* the events from multiple streams.
|
|
2511
|
+
*
|
|
2512
|
+
* Marble diagram:
|
|
2513
|
+
*
|
|
2514
|
+
* ```text
|
|
2515
|
+
* --1----2-----3--------4---
|
|
2516
|
+
* ----a-----b-----c--d------
|
|
2517
|
+
* combine
|
|
2518
|
+
* ----1a-2a-2b-3b-3c-3d-4d--
|
|
2519
|
+
* ```
|
|
2520
|
+
*
|
|
2521
|
+
* @factory true
|
|
2522
|
+
* @param {Stream} stream1 A stream to combine together with other streams.
|
|
2523
|
+
* @param {Stream} stream2 A stream to combine together with other streams.
|
|
2524
|
+
* Multiple streams, not just two, may be given as arguments.
|
|
2525
|
+
* @return {Stream}
|
|
2526
|
+
*/
|
|
2527
|
+
Stream.combine = function combine() {
|
|
2528
|
+
var streams = [];
|
|
2529
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2530
|
+
streams[_i] = arguments[_i];
|
|
2531
|
+
}
|
|
2532
|
+
return new Stream(new Combine(streams));
|
|
2533
|
+
};
|
|
2534
|
+
return Stream;
|
|
2535
|
+
}());
|
|
2536
|
+
xstream.Stream = Stream;
|
|
2537
|
+
var MemoryStream = /** @class */ (function (_super) {
|
|
2538
|
+
__extends(MemoryStream, _super);
|
|
2539
|
+
function MemoryStream(producer) {
|
|
2540
|
+
var _this = _super.call(this, producer) || this;
|
|
2541
|
+
_this._has = false;
|
|
2542
|
+
return _this;
|
|
2543
|
+
}
|
|
2544
|
+
MemoryStream.prototype._n = function (x) {
|
|
2545
|
+
this._v = x;
|
|
2546
|
+
this._has = true;
|
|
2547
|
+
_super.prototype._n.call(this, x);
|
|
2548
|
+
};
|
|
2549
|
+
MemoryStream.prototype._add = function (il) {
|
|
2550
|
+
var ta = this._target;
|
|
2551
|
+
if (ta)
|
|
2552
|
+
return ta._add(il);
|
|
2553
|
+
var a = this._ils;
|
|
2554
|
+
a.push(il);
|
|
2555
|
+
if (a.length > 1) {
|
|
2556
|
+
if (this._has)
|
|
2557
|
+
il._n(this._v);
|
|
2558
|
+
return;
|
|
2559
|
+
}
|
|
2560
|
+
if (this._stopID !== NO$1) {
|
|
2561
|
+
if (this._has)
|
|
2562
|
+
il._n(this._v);
|
|
2563
|
+
clearTimeout(this._stopID);
|
|
2564
|
+
this._stopID = NO$1;
|
|
2565
|
+
}
|
|
2566
|
+
else if (this._has)
|
|
2567
|
+
il._n(this._v);
|
|
2568
|
+
else {
|
|
2569
|
+
var p = this._prod;
|
|
2570
|
+
if (p !== NO$1)
|
|
2571
|
+
p._start(this);
|
|
2572
|
+
}
|
|
2573
|
+
};
|
|
2574
|
+
MemoryStream.prototype._stopNow = function () {
|
|
2575
|
+
this._has = false;
|
|
2576
|
+
_super.prototype._stopNow.call(this);
|
|
2577
|
+
};
|
|
2578
|
+
MemoryStream.prototype._x = function () {
|
|
2579
|
+
this._has = false;
|
|
2580
|
+
_super.prototype._x.call(this);
|
|
2581
|
+
};
|
|
2582
|
+
MemoryStream.prototype.map = function (project) {
|
|
2583
|
+
return this._map(project);
|
|
2584
|
+
};
|
|
2585
|
+
MemoryStream.prototype.mapTo = function (projectedValue) {
|
|
2586
|
+
return _super.prototype.mapTo.call(this, projectedValue);
|
|
2587
|
+
};
|
|
2588
|
+
MemoryStream.prototype.take = function (amount) {
|
|
2589
|
+
return _super.prototype.take.call(this, amount);
|
|
2590
|
+
};
|
|
2591
|
+
MemoryStream.prototype.endWhen = function (other) {
|
|
2592
|
+
return _super.prototype.endWhen.call(this, other);
|
|
2593
|
+
};
|
|
2594
|
+
MemoryStream.prototype.replaceError = function (replace) {
|
|
2595
|
+
return _super.prototype.replaceError.call(this, replace);
|
|
2596
|
+
};
|
|
2597
|
+
MemoryStream.prototype.remember = function () {
|
|
2598
|
+
return this;
|
|
2599
|
+
};
|
|
2600
|
+
MemoryStream.prototype.debug = function (labelOrSpy) {
|
|
2601
|
+
return _super.prototype.debug.call(this, labelOrSpy);
|
|
2602
|
+
};
|
|
2603
|
+
return MemoryStream;
|
|
2604
|
+
}(Stream));
|
|
2605
|
+
xstream.MemoryStream = MemoryStream;
|
|
2606
|
+
var xs = Stream;
|
|
2607
|
+
xstream.default = xs;
|
|
2608
|
+
|
|
2609
|
+
Object.defineProperty(dropRepeats$1, "__esModule", { value: true });
|
|
2610
|
+
dropRepeats$1.DropRepeatsOperator = void 0;
|
|
2611
|
+
var index_1$5 = xstream;
|
|
2612
|
+
var empty = {};
|
|
2613
|
+
var DropRepeatsOperator = /** @class */ (function () {
|
|
2614
|
+
function DropRepeatsOperator(ins, fn) {
|
|
2615
|
+
this.ins = ins;
|
|
2616
|
+
this.type = 'dropRepeats';
|
|
2617
|
+
this.out = null;
|
|
2618
|
+
this.v = empty;
|
|
2619
|
+
this.isEq = fn ? fn : function (x, y) { return x === y; };
|
|
2620
|
+
}
|
|
2621
|
+
DropRepeatsOperator.prototype._start = function (out) {
|
|
2622
|
+
this.out = out;
|
|
2623
|
+
this.ins._add(this);
|
|
2624
|
+
};
|
|
2625
|
+
DropRepeatsOperator.prototype._stop = function () {
|
|
2626
|
+
this.ins._remove(this);
|
|
2627
|
+
this.out = null;
|
|
2628
|
+
this.v = empty;
|
|
2629
|
+
};
|
|
2630
|
+
DropRepeatsOperator.prototype._n = function (t) {
|
|
2631
|
+
var u = this.out;
|
|
2632
|
+
if (!u)
|
|
2633
|
+
return;
|
|
2634
|
+
var v = this.v;
|
|
2635
|
+
if (v !== empty && this.isEq(t, v))
|
|
2636
|
+
return;
|
|
2637
|
+
this.v = t;
|
|
2638
|
+
u._n(t);
|
|
2639
|
+
};
|
|
2640
|
+
DropRepeatsOperator.prototype._e = function (err) {
|
|
2641
|
+
var u = this.out;
|
|
2642
|
+
if (!u)
|
|
2643
|
+
return;
|
|
2644
|
+
u._e(err);
|
|
2645
|
+
};
|
|
2646
|
+
DropRepeatsOperator.prototype._c = function () {
|
|
2647
|
+
var u = this.out;
|
|
2648
|
+
if (!u)
|
|
2649
|
+
return;
|
|
2650
|
+
u._c();
|
|
2651
|
+
};
|
|
2652
|
+
return DropRepeatsOperator;
|
|
2653
|
+
}());
|
|
2654
|
+
dropRepeats$1.DropRepeatsOperator = DropRepeatsOperator;
|
|
2655
|
+
/**
|
|
2656
|
+
* Drops consecutive duplicate values in a stream.
|
|
2657
|
+
*
|
|
2658
|
+
* Marble diagram:
|
|
2659
|
+
*
|
|
2660
|
+
* ```text
|
|
2661
|
+
* --1--2--1--1--1--2--3--4--3--3|
|
|
2662
|
+
* dropRepeats
|
|
2663
|
+
* --1--2--1--------2--3--4--3---|
|
|
2664
|
+
* ```
|
|
2665
|
+
*
|
|
2666
|
+
* Example:
|
|
2667
|
+
*
|
|
2668
|
+
* ```js
|
|
2669
|
+
* import dropRepeats from 'xstream/extra/dropRepeats'
|
|
2670
|
+
*
|
|
2671
|
+
* const stream = xs.of(1, 2, 1, 1, 1, 2, 3, 4, 3, 3)
|
|
2672
|
+
* .compose(dropRepeats())
|
|
2673
|
+
*
|
|
2674
|
+
* stream.addListener({
|
|
2675
|
+
* next: i => console.log(i),
|
|
2676
|
+
* error: err => console.error(err),
|
|
2677
|
+
* complete: () => console.log('completed')
|
|
2678
|
+
* })
|
|
2679
|
+
* ```
|
|
2680
|
+
*
|
|
2681
|
+
* ```text
|
|
2682
|
+
* > 1
|
|
2683
|
+
* > 2
|
|
2684
|
+
* > 1
|
|
2685
|
+
* > 2
|
|
2686
|
+
* > 3
|
|
2687
|
+
* > 4
|
|
2688
|
+
* > 3
|
|
2689
|
+
* > completed
|
|
2690
|
+
* ```
|
|
2691
|
+
*
|
|
2692
|
+
* Example with a custom isEqual function:
|
|
2693
|
+
*
|
|
2694
|
+
* ```js
|
|
2695
|
+
* import dropRepeats from 'xstream/extra/dropRepeats'
|
|
2696
|
+
*
|
|
2697
|
+
* const stream = xs.of('a', 'b', 'a', 'A', 'B', 'b')
|
|
2698
|
+
* .compose(dropRepeats((x, y) => x.toLowerCase() === y.toLowerCase()))
|
|
2699
|
+
*
|
|
2700
|
+
* stream.addListener({
|
|
2701
|
+
* next: i => console.log(i),
|
|
2702
|
+
* error: err => console.error(err),
|
|
2703
|
+
* complete: () => console.log('completed')
|
|
2704
|
+
* })
|
|
2705
|
+
* ```
|
|
2706
|
+
*
|
|
2707
|
+
* ```text
|
|
2708
|
+
* > a
|
|
2709
|
+
* > b
|
|
2710
|
+
* > a
|
|
2711
|
+
* > B
|
|
2712
|
+
* > completed
|
|
2713
|
+
* ```
|
|
2714
|
+
*
|
|
2715
|
+
* @param {Function} isEqual An optional function of type
|
|
2716
|
+
* `(x: T, y: T) => boolean` that takes an event from the input stream and
|
|
2717
|
+
* checks if it is equal to previous event, by returning a boolean.
|
|
2718
|
+
* @return {Stream}
|
|
2719
|
+
*/
|
|
2720
|
+
function dropRepeats(isEqual) {
|
|
2721
|
+
if (isEqual === void 0) { isEqual = void 0; }
|
|
2722
|
+
return function dropRepeatsOperator(ins) {
|
|
2723
|
+
return new index_1$5.Stream(new DropRepeatsOperator(ins, isEqual));
|
|
2724
|
+
};
|
|
2725
|
+
}
|
|
2726
|
+
var _default$5 = dropRepeats$1.default = dropRepeats;
|
|
2727
|
+
|
|
80
2728
|
function switchable(factories, name$, initial, opts={}) {
|
|
81
2729
|
const {
|
|
82
2730
|
switched=['DOM'],
|
|
@@ -85,13 +2733,13 @@ function switchable(factories, name$, initial, opts={}) {
|
|
|
85
2733
|
const nameType = typeof name$;
|
|
86
2734
|
|
|
87
2735
|
if (!name$) throw new Error(`Missing 'name$' parameter for switchable()`)
|
|
88
|
-
if (!(nameType === 'string' || nameType === 'function' || name$ instanceof Stream)) {
|
|
2736
|
+
if (!(nameType === 'string' || nameType === 'function' || name$ instanceof Stream$1)) {
|
|
89
2737
|
throw new Error(`Invalid 'name$' parameter for switchable(): expects Stream, String, or Function`)
|
|
90
2738
|
}
|
|
91
2739
|
|
|
92
|
-
if (name$ instanceof Stream) {
|
|
2740
|
+
if (name$ instanceof Stream$1) {
|
|
93
2741
|
const withInitial$ = name$
|
|
94
|
-
.compose(
|
|
2742
|
+
.compose(_default$5())
|
|
95
2743
|
.startWith(initial)
|
|
96
2744
|
.remember();
|
|
97
2745
|
return sources => _switchable(factories, sources, withInitial$, switched)
|
|
@@ -99,11 +2747,11 @@ function switchable(factories, name$, initial, opts={}) {
|
|
|
99
2747
|
const mapFunction = (nameType === 'function' && name$) || (state => state[name$]);
|
|
100
2748
|
return sources => {
|
|
101
2749
|
const state$ = sources && ((typeof stateSourceName === 'string' && sources[stateSourceName]) || sources.STATE || sources.state).stream;
|
|
102
|
-
if (!state$ instanceof Stream) throw new Error(`Could not find the state source: ${ stateSourceName }`)
|
|
2750
|
+
if (!state$ instanceof Stream$1) throw new Error(`Could not find the state source: ${ stateSourceName }`)
|
|
103
2751
|
const _name$ = state$
|
|
104
2752
|
.map(mapFunction)
|
|
105
2753
|
.filter(name => typeof name === 'string')
|
|
106
|
-
.compose(
|
|
2754
|
+
.compose(_default$5())
|
|
107
2755
|
.startWith(initial)
|
|
108
2756
|
.remember();
|
|
109
2757
|
return _switchable(factories, sources, _name$, switched, stateSourceName)
|
|
@@ -131,7 +2779,7 @@ function _switchable (factories, sources, name$, switched=['DOM'], stateSourceNa
|
|
|
131
2779
|
.map(([name, factory]) => {
|
|
132
2780
|
if (sources[stateSourceName]) {
|
|
133
2781
|
const state$ = sources[stateSourceName].stream;
|
|
134
|
-
const switched = xs.combine(name$, state$)
|
|
2782
|
+
const switched = xs$1.combine(name$, state$)
|
|
135
2783
|
.filter(([newComponentName, _]) => newComponentName == name)
|
|
136
2784
|
.map(([_, state]) => state)
|
|
137
2785
|
.remember();
|
|
@@ -148,7 +2796,7 @@ function _switchable (factories, sources, name$, switched=['DOM'], stateSourceNa
|
|
|
148
2796
|
obj[sinkName] = name$
|
|
149
2797
|
.map( newComponentName => {
|
|
150
2798
|
const sink = sinks.find(([componentName, _]) => componentName === newComponentName);
|
|
151
|
-
return (sink && sink[1][sinkName]) || xs.never()
|
|
2799
|
+
return (sink && sink[1][sinkName]) || xs$1.never()
|
|
152
2800
|
})
|
|
153
2801
|
.flatten()
|
|
154
2802
|
.remember()
|
|
@@ -156,7 +2804,7 @@ function _switchable (factories, sources, name$, switched=['DOM'], stateSourceNa
|
|
|
156
2804
|
} else {
|
|
157
2805
|
const definedSinks = sinks.filter(([_,sink]) => sink[sinkName] !== undefined)
|
|
158
2806
|
.map(([_,sink]) => sink[sinkName]);
|
|
159
|
-
obj[sinkName] = xs.merge(...definedSinks);
|
|
2807
|
+
obj[sinkName] = xs$1.merge(...definedSinks);
|
|
160
2808
|
}
|
|
161
2809
|
return obj
|
|
162
2810
|
}, {});
|
|
@@ -164,6 +2812,302 @@ function _switchable (factories, sources, name$, switched=['DOM'], stateSourceNa
|
|
|
164
2812
|
return switchedSinks
|
|
165
2813
|
}
|
|
166
2814
|
|
|
2815
|
+
var delay$1 = {};
|
|
2816
|
+
|
|
2817
|
+
Object.defineProperty(delay$1, "__esModule", { value: true });
|
|
2818
|
+
var index_1$4 = xstream;
|
|
2819
|
+
var DelayOperator = /** @class */ (function () {
|
|
2820
|
+
function DelayOperator(dt, ins) {
|
|
2821
|
+
this.dt = dt;
|
|
2822
|
+
this.ins = ins;
|
|
2823
|
+
this.type = 'delay';
|
|
2824
|
+
this.out = null;
|
|
2825
|
+
}
|
|
2826
|
+
DelayOperator.prototype._start = function (out) {
|
|
2827
|
+
this.out = out;
|
|
2828
|
+
this.ins._add(this);
|
|
2829
|
+
};
|
|
2830
|
+
DelayOperator.prototype._stop = function () {
|
|
2831
|
+
this.ins._remove(this);
|
|
2832
|
+
this.out = null;
|
|
2833
|
+
};
|
|
2834
|
+
DelayOperator.prototype._n = function (t) {
|
|
2835
|
+
var u = this.out;
|
|
2836
|
+
if (!u)
|
|
2837
|
+
return;
|
|
2838
|
+
var id = setInterval(function () {
|
|
2839
|
+
u._n(t);
|
|
2840
|
+
clearInterval(id);
|
|
2841
|
+
}, this.dt);
|
|
2842
|
+
};
|
|
2843
|
+
DelayOperator.prototype._e = function (err) {
|
|
2844
|
+
var u = this.out;
|
|
2845
|
+
if (!u)
|
|
2846
|
+
return;
|
|
2847
|
+
var id = setInterval(function () {
|
|
2848
|
+
u._e(err);
|
|
2849
|
+
clearInterval(id);
|
|
2850
|
+
}, this.dt);
|
|
2851
|
+
};
|
|
2852
|
+
DelayOperator.prototype._c = function () {
|
|
2853
|
+
var u = this.out;
|
|
2854
|
+
if (!u)
|
|
2855
|
+
return;
|
|
2856
|
+
var id = setInterval(function () {
|
|
2857
|
+
u._c();
|
|
2858
|
+
clearInterval(id);
|
|
2859
|
+
}, this.dt);
|
|
2860
|
+
};
|
|
2861
|
+
return DelayOperator;
|
|
2862
|
+
}());
|
|
2863
|
+
/**
|
|
2864
|
+
* Delays periodic events by a given time period.
|
|
2865
|
+
*
|
|
2866
|
+
* Marble diagram:
|
|
2867
|
+
*
|
|
2868
|
+
* ```text
|
|
2869
|
+
* 1----2--3--4----5|
|
|
2870
|
+
* delay(60)
|
|
2871
|
+
* ---1----2--3--4----5|
|
|
2872
|
+
* ```
|
|
2873
|
+
*
|
|
2874
|
+
* Example:
|
|
2875
|
+
*
|
|
2876
|
+
* ```js
|
|
2877
|
+
* import fromDiagram from 'xstream/extra/fromDiagram'
|
|
2878
|
+
* import delay from 'xstream/extra/delay'
|
|
2879
|
+
*
|
|
2880
|
+
* const stream = fromDiagram('1----2--3--4----5|')
|
|
2881
|
+
* .compose(delay(60))
|
|
2882
|
+
*
|
|
2883
|
+
* stream.addListener({
|
|
2884
|
+
* next: i => console.log(i),
|
|
2885
|
+
* error: err => console.error(err),
|
|
2886
|
+
* complete: () => console.log('completed')
|
|
2887
|
+
* })
|
|
2888
|
+
* ```
|
|
2889
|
+
*
|
|
2890
|
+
* ```text
|
|
2891
|
+
* > 1 (after 60 ms)
|
|
2892
|
+
* > 2 (after 160 ms)
|
|
2893
|
+
* > 3 (after 220 ms)
|
|
2894
|
+
* > 4 (after 280 ms)
|
|
2895
|
+
* > 5 (after 380 ms)
|
|
2896
|
+
* > completed
|
|
2897
|
+
* ```
|
|
2898
|
+
*
|
|
2899
|
+
* @param {number} period The amount of silence required in milliseconds.
|
|
2900
|
+
* @return {Stream}
|
|
2901
|
+
*/
|
|
2902
|
+
function delay(period) {
|
|
2903
|
+
return function delayOperator(ins) {
|
|
2904
|
+
return new index_1$4.Stream(new DelayOperator(period, ins));
|
|
2905
|
+
};
|
|
2906
|
+
}
|
|
2907
|
+
var _default$4 = delay$1.default = delay;
|
|
2908
|
+
|
|
2909
|
+
var concat$1 = {};
|
|
2910
|
+
|
|
2911
|
+
Object.defineProperty(concat$1, "__esModule", { value: true });
|
|
2912
|
+
var index_1$3 = xstream;
|
|
2913
|
+
var ConcatProducer = /** @class */ (function () {
|
|
2914
|
+
function ConcatProducer(streams) {
|
|
2915
|
+
this.streams = streams;
|
|
2916
|
+
this.type = 'concat';
|
|
2917
|
+
this.out = null;
|
|
2918
|
+
this.i = 0;
|
|
2919
|
+
}
|
|
2920
|
+
ConcatProducer.prototype._start = function (out) {
|
|
2921
|
+
this.out = out;
|
|
2922
|
+
this.streams[this.i]._add(this);
|
|
2923
|
+
};
|
|
2924
|
+
ConcatProducer.prototype._stop = function () {
|
|
2925
|
+
var streams = this.streams;
|
|
2926
|
+
if (this.i < streams.length) {
|
|
2927
|
+
streams[this.i]._remove(this);
|
|
2928
|
+
}
|
|
2929
|
+
this.i = 0;
|
|
2930
|
+
this.out = null;
|
|
2931
|
+
};
|
|
2932
|
+
ConcatProducer.prototype._n = function (t) {
|
|
2933
|
+
var u = this.out;
|
|
2934
|
+
if (!u)
|
|
2935
|
+
return;
|
|
2936
|
+
u._n(t);
|
|
2937
|
+
};
|
|
2938
|
+
ConcatProducer.prototype._e = function (err) {
|
|
2939
|
+
var u = this.out;
|
|
2940
|
+
if (!u)
|
|
2941
|
+
return;
|
|
2942
|
+
u._e(err);
|
|
2943
|
+
};
|
|
2944
|
+
ConcatProducer.prototype._c = function () {
|
|
2945
|
+
var u = this.out;
|
|
2946
|
+
if (!u)
|
|
2947
|
+
return;
|
|
2948
|
+
var streams = this.streams;
|
|
2949
|
+
streams[this.i]._remove(this);
|
|
2950
|
+
if (++this.i < streams.length) {
|
|
2951
|
+
streams[this.i]._add(this);
|
|
2952
|
+
}
|
|
2953
|
+
else {
|
|
2954
|
+
u._c();
|
|
2955
|
+
}
|
|
2956
|
+
};
|
|
2957
|
+
return ConcatProducer;
|
|
2958
|
+
}());
|
|
2959
|
+
/**
|
|
2960
|
+
* Puts one stream after the other. *concat* is a factory that takes multiple
|
|
2961
|
+
* streams as arguments, and starts the `n+1`-th stream only when the `n`-th
|
|
2962
|
+
* stream has completed. It concatenates those streams together.
|
|
2963
|
+
*
|
|
2964
|
+
* Marble diagram:
|
|
2965
|
+
*
|
|
2966
|
+
* ```text
|
|
2967
|
+
* --1--2---3---4-|
|
|
2968
|
+
* ...............--a-b-c--d-|
|
|
2969
|
+
* concat
|
|
2970
|
+
* --1--2---3---4---a-b-c--d-|
|
|
2971
|
+
* ```
|
|
2972
|
+
*
|
|
2973
|
+
* Example:
|
|
2974
|
+
*
|
|
2975
|
+
* ```js
|
|
2976
|
+
* import concat from 'xstream/extra/concat'
|
|
2977
|
+
*
|
|
2978
|
+
* const streamA = xs.of('a', 'b', 'c')
|
|
2979
|
+
* const streamB = xs.of(10, 20, 30)
|
|
2980
|
+
* const streamC = xs.of('X', 'Y', 'Z')
|
|
2981
|
+
*
|
|
2982
|
+
* const outputStream = concat(streamA, streamB, streamC)
|
|
2983
|
+
*
|
|
2984
|
+
* outputStream.addListener({
|
|
2985
|
+
* next: (x) => console.log(x),
|
|
2986
|
+
* error: (err) => console.error(err),
|
|
2987
|
+
* complete: () => console.log('concat completed'),
|
|
2988
|
+
* })
|
|
2989
|
+
* ```
|
|
2990
|
+
*
|
|
2991
|
+
* @factory true
|
|
2992
|
+
* @param {Stream} stream1 A stream to concatenate together with other streams.
|
|
2993
|
+
* @param {Stream} stream2 A stream to concatenate together with other streams. Two
|
|
2994
|
+
* or more streams may be given as arguments.
|
|
2995
|
+
* @return {Stream}
|
|
2996
|
+
*/
|
|
2997
|
+
function concat() {
|
|
2998
|
+
var streams = [];
|
|
2999
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3000
|
+
streams[_i] = arguments[_i];
|
|
3001
|
+
}
|
|
3002
|
+
return new index_1$3.Stream(new ConcatProducer(streams));
|
|
3003
|
+
}
|
|
3004
|
+
var _default$3 = concat$1.default = concat;
|
|
3005
|
+
|
|
3006
|
+
var debounce$1 = {};
|
|
3007
|
+
|
|
3008
|
+
Object.defineProperty(debounce$1, "__esModule", { value: true });
|
|
3009
|
+
var index_1$2 = xstream;
|
|
3010
|
+
var DebounceOperator = /** @class */ (function () {
|
|
3011
|
+
function DebounceOperator(dt, ins) {
|
|
3012
|
+
this.dt = dt;
|
|
3013
|
+
this.ins = ins;
|
|
3014
|
+
this.type = 'debounce';
|
|
3015
|
+
this.out = null;
|
|
3016
|
+
this.id = null;
|
|
3017
|
+
this.t = index_1$2.NO;
|
|
3018
|
+
}
|
|
3019
|
+
DebounceOperator.prototype._start = function (out) {
|
|
3020
|
+
this.out = out;
|
|
3021
|
+
this.ins._add(this);
|
|
3022
|
+
};
|
|
3023
|
+
DebounceOperator.prototype._stop = function () {
|
|
3024
|
+
this.ins._remove(this);
|
|
3025
|
+
this.out = null;
|
|
3026
|
+
this.clearInterval();
|
|
3027
|
+
};
|
|
3028
|
+
DebounceOperator.prototype.clearInterval = function () {
|
|
3029
|
+
var id = this.id;
|
|
3030
|
+
if (id !== null) {
|
|
3031
|
+
clearInterval(id);
|
|
3032
|
+
}
|
|
3033
|
+
this.id = null;
|
|
3034
|
+
};
|
|
3035
|
+
DebounceOperator.prototype._n = function (t) {
|
|
3036
|
+
var _this = this;
|
|
3037
|
+
var u = this.out;
|
|
3038
|
+
if (!u)
|
|
3039
|
+
return;
|
|
3040
|
+
this.clearInterval();
|
|
3041
|
+
this.t = t;
|
|
3042
|
+
this.id = setInterval(function () {
|
|
3043
|
+
_this.clearInterval();
|
|
3044
|
+
u._n(t);
|
|
3045
|
+
_this.t = index_1$2.NO;
|
|
3046
|
+
}, this.dt);
|
|
3047
|
+
};
|
|
3048
|
+
DebounceOperator.prototype._e = function (err) {
|
|
3049
|
+
var u = this.out;
|
|
3050
|
+
if (!u)
|
|
3051
|
+
return;
|
|
3052
|
+
this.clearInterval();
|
|
3053
|
+
u._e(err);
|
|
3054
|
+
};
|
|
3055
|
+
DebounceOperator.prototype._c = function () {
|
|
3056
|
+
var u = this.out;
|
|
3057
|
+
if (!u)
|
|
3058
|
+
return;
|
|
3059
|
+
this.clearInterval();
|
|
3060
|
+
if (this.t != index_1$2.NO)
|
|
3061
|
+
u._n(this.t);
|
|
3062
|
+
this.t = index_1$2.NO;
|
|
3063
|
+
u._c();
|
|
3064
|
+
};
|
|
3065
|
+
return DebounceOperator;
|
|
3066
|
+
}());
|
|
3067
|
+
/**
|
|
3068
|
+
* Delays events until a certain amount of silence has passed. If that timespan
|
|
3069
|
+
* of silence is not met the event is dropped.
|
|
3070
|
+
*
|
|
3071
|
+
* Marble diagram:
|
|
3072
|
+
*
|
|
3073
|
+
* ```text
|
|
3074
|
+
* --1----2--3--4----5|
|
|
3075
|
+
* debounce(60)
|
|
3076
|
+
* -----1----------4--|
|
|
3077
|
+
* ```
|
|
3078
|
+
*
|
|
3079
|
+
* Example:
|
|
3080
|
+
*
|
|
3081
|
+
* ```js
|
|
3082
|
+
* import fromDiagram from 'xstream/extra/fromDiagram'
|
|
3083
|
+
* import debounce from 'xstream/extra/debounce'
|
|
3084
|
+
*
|
|
3085
|
+
* const stream = fromDiagram('--1----2--3--4----5|')
|
|
3086
|
+
* .compose(debounce(60))
|
|
3087
|
+
*
|
|
3088
|
+
* stream.addListener({
|
|
3089
|
+
* next: i => console.log(i),
|
|
3090
|
+
* error: err => console.error(err),
|
|
3091
|
+
* complete: () => console.log('completed')
|
|
3092
|
+
* })
|
|
3093
|
+
* ```
|
|
3094
|
+
*
|
|
3095
|
+
* ```text
|
|
3096
|
+
* > 1
|
|
3097
|
+
* > 4
|
|
3098
|
+
* > completed
|
|
3099
|
+
* ```
|
|
3100
|
+
*
|
|
3101
|
+
* @param {number} period The amount of silence required in milliseconds.
|
|
3102
|
+
* @return {Stream}
|
|
3103
|
+
*/
|
|
3104
|
+
function debounce(period) {
|
|
3105
|
+
return function debounceOperator(ins) {
|
|
3106
|
+
return new index_1$2.Stream(new DebounceOperator(period, ins));
|
|
3107
|
+
};
|
|
3108
|
+
}
|
|
3109
|
+
var _default$2 = debounce$1.default = debounce;
|
|
3110
|
+
|
|
167
3111
|
// import syntax has bugs for xstream in Node context
|
|
168
3112
|
// this attempts to normalize to work in both Node and browser
|
|
169
3113
|
// if (!xs.never && xs.default && xs.default.never) {
|
|
@@ -292,7 +3236,7 @@ class Component {
|
|
|
292
3236
|
|
|
293
3237
|
if (IS_ROOT_COMPONENT && typeof this.intent === 'undefined' && typeof this.model === 'undefined') {
|
|
294
3238
|
this.initialState = initialState || true;
|
|
295
|
-
this.intent = _ => ({__NOOP_ACTION__:xs.never()});
|
|
3239
|
+
this.intent = _ => ({__NOOP_ACTION__:xs$1.never()});
|
|
296
3240
|
this.model = {
|
|
297
3241
|
__NOOP_ACTION__: state => state
|
|
298
3242
|
};
|
|
@@ -309,6 +3253,7 @@ class Component {
|
|
|
309
3253
|
this.initSendResponse$();
|
|
310
3254
|
this.initChildren$();
|
|
311
3255
|
this.initSubComponentSink$();
|
|
3256
|
+
this.initSubComponentsRendered$();
|
|
312
3257
|
this.initVdom$();
|
|
313
3258
|
this.initSinks();
|
|
314
3259
|
}
|
|
@@ -323,7 +3268,7 @@ class Component {
|
|
|
323
3268
|
|
|
324
3269
|
this.intent$ = this.intent(this.sources);
|
|
325
3270
|
|
|
326
|
-
if (!(this.intent$ instanceof Stream) && (typeof this.intent$ != 'object')) {
|
|
3271
|
+
if (!(this.intent$ instanceof Stream$1) && (typeof this.intent$ != 'object')) {
|
|
327
3272
|
throw new Error('Intent must return either an action$ stream or map of event streams')
|
|
328
3273
|
}
|
|
329
3274
|
}
|
|
@@ -332,34 +3277,34 @@ class Component {
|
|
|
332
3277
|
const requestSource = (this.sources && this.sources[this.requestSourceName]) || null;
|
|
333
3278
|
|
|
334
3279
|
if (!this.intent$) {
|
|
335
|
-
this.action$ = xs.never();
|
|
3280
|
+
this.action$ = xs$1.never();
|
|
336
3281
|
return
|
|
337
3282
|
}
|
|
338
3283
|
|
|
339
3284
|
let runner;
|
|
340
|
-
if (this.intent$ instanceof Stream) {
|
|
3285
|
+
if (this.intent$ instanceof Stream$1) {
|
|
341
3286
|
runner = this.intent$;
|
|
342
3287
|
} else {
|
|
343
3288
|
const mapped = Object.entries(this.intent$)
|
|
344
3289
|
.map(([type, data$]) => data$.map(data => ({type, data})));
|
|
345
|
-
runner = xs.merge(xs.never(), ...mapped);
|
|
3290
|
+
runner = xs$1.merge(xs$1.never(), ...mapped);
|
|
346
3291
|
}
|
|
347
3292
|
|
|
348
|
-
const action$ = ((runner instanceof Stream) ? runner : (runner.apply && runner(this.sources) || xs.never()));
|
|
349
|
-
const wrapped$ =
|
|
350
|
-
.compose(
|
|
3293
|
+
const action$ = ((runner instanceof Stream$1) ? runner : (runner.apply && runner(this.sources) || xs$1.never()));
|
|
3294
|
+
const wrapped$ = _default$3(xs$1.of({ type: BOOTSTRAP_ACTION }), action$)
|
|
3295
|
+
.compose(_default$4(10));
|
|
351
3296
|
|
|
352
3297
|
let initialApiData;
|
|
353
3298
|
if (requestSource && typeof requestSource.select == 'function') {
|
|
354
3299
|
initialApiData = requestSource.select('initial')
|
|
355
3300
|
.flatten();
|
|
356
3301
|
} else {
|
|
357
|
-
initialApiData = xs.never();
|
|
3302
|
+
initialApiData = xs$1.never();
|
|
358
3303
|
}
|
|
359
3304
|
|
|
360
3305
|
const hydrate$ = initialApiData.map(data => ({ type: HYDRATE_ACTION, data }));
|
|
361
3306
|
|
|
362
|
-
this.action$ = xs.merge(wrapped$, hydrate$)
|
|
3307
|
+
this.action$ = xs$1.merge(wrapped$, hydrate$)
|
|
363
3308
|
.compose(this.log(({ type }) => `Action triggered: <${ type }>`));
|
|
364
3309
|
}
|
|
365
3310
|
|
|
@@ -390,7 +3335,7 @@ class Component {
|
|
|
390
3335
|
const actionString = (actionType === 'function') ? '[ FUNCTION ]' : `< ${ action } >`;
|
|
391
3336
|
console.log(`[${ this.name }] Adding ${ this.requestSourceName } route:`, _method.toUpperCase(), `'${ route }' <${ actionString }>`);
|
|
392
3337
|
const route$ = router$[_method](route)
|
|
393
|
-
.compose(
|
|
3338
|
+
.compose(_default$5((a, b) => a.id == b.id))
|
|
394
3339
|
.map(req => {
|
|
395
3340
|
if (!req || !req.id) {
|
|
396
3341
|
throw new Error(`No id found in request: ${ routeString }`)
|
|
@@ -416,7 +3361,7 @@ class Component {
|
|
|
416
3361
|
if (actionType === 'function') {
|
|
417
3362
|
const enhancedState = this.addCalculated(this.currentState);
|
|
418
3363
|
const result = action(enhancedState, req);
|
|
419
|
-
return xs.of({ ...obj, data: result })
|
|
3364
|
+
return xs$1.of({ ...obj, data: result })
|
|
420
3365
|
} else {
|
|
421
3366
|
this.action$.shamefullySendNext(obj);
|
|
422
3367
|
|
|
@@ -426,7 +3371,7 @@ class Component {
|
|
|
426
3371
|
const selected$ = source[REQUEST_SELECTOR_METHOD](_reqId);
|
|
427
3372
|
return [ ...acc, selected$ ]
|
|
428
3373
|
}, []);
|
|
429
|
-
return xs.merge(...responses)
|
|
3374
|
+
return xs$1.merge(...responses)
|
|
430
3375
|
}
|
|
431
3376
|
} catch(err) {
|
|
432
3377
|
console.error(err);
|
|
@@ -434,11 +3379,11 @@ class Component {
|
|
|
434
3379
|
}).flatten();
|
|
435
3380
|
return [ ...acc, route$ ]
|
|
436
3381
|
}, []);
|
|
437
|
-
const mapped$ = xs.merge(...mapped);
|
|
3382
|
+
const mapped$ = xs$1.merge(...mapped);
|
|
438
3383
|
return [ ...acc, mapped$ ]
|
|
439
3384
|
}, []);
|
|
440
3385
|
|
|
441
|
-
this.response$ = xs.merge(...wrapped)
|
|
3386
|
+
this.response$ = xs$1.merge(...wrapped)
|
|
442
3387
|
.compose(this.log(res => {
|
|
443
3388
|
if (res._action) return `[${ this.requestSourceName }] response data received for Action: <${ res._action }>`
|
|
444
3389
|
return `[${ this.requestSourceName }] response data received from FUNCTION`
|
|
@@ -469,14 +3414,14 @@ class Component {
|
|
|
469
3414
|
initModel$() {
|
|
470
3415
|
if (typeof this.model == 'undefined') {
|
|
471
3416
|
this.model$ = this.sourceNames.reduce((a,s) => {
|
|
472
|
-
a[s] = xs.never();
|
|
3417
|
+
a[s] = xs$1.never();
|
|
473
3418
|
return a
|
|
474
3419
|
}, {});
|
|
475
3420
|
return
|
|
476
3421
|
}
|
|
477
3422
|
|
|
478
3423
|
const initial = { type: INITIALIZE_ACTION, data: this.initialState };
|
|
479
|
-
const shimmed$ = this.initialState ?
|
|
3424
|
+
const shimmed$ = this.initialState ? _default$3(xs$1.of(initial), this.action$).compose(_default$4(0)) : this.action$;
|
|
480
3425
|
const onState = this.makeOnAction(shimmed$, true, this.action$);
|
|
481
3426
|
const onNormal = this.makeOnAction(this.action$, false, this.action$);
|
|
482
3427
|
|
|
@@ -525,7 +3470,7 @@ class Component {
|
|
|
525
3470
|
|
|
526
3471
|
const model$ = Object.entries(reducers).reduce((acc, entry) => {
|
|
527
3472
|
const [sink, streams] = entry;
|
|
528
|
-
acc[sink] = xs.merge(xs.never(), ...streams);
|
|
3473
|
+
acc[sink] = xs$1.merge(xs$1.never(), ...streams);
|
|
529
3474
|
return acc
|
|
530
3475
|
}, {});
|
|
531
3476
|
|
|
@@ -544,7 +3489,7 @@ class Component {
|
|
|
544
3489
|
next: this.log(({ _reqId, _action }) => `Unhandled response for request: ${ _action } ${ _reqId }`)
|
|
545
3490
|
});
|
|
546
3491
|
}
|
|
547
|
-
this.sendResponse$ = xs.never();
|
|
3492
|
+
this.sendResponse$ = xs$1.never();
|
|
548
3493
|
return
|
|
549
3494
|
}
|
|
550
3495
|
|
|
@@ -563,352 +3508,98 @@ class Component {
|
|
|
563
3508
|
|
|
564
3509
|
const entries = Object.entries(out);
|
|
565
3510
|
const out$ = entries.reduce((acc, [command, response$]) => {
|
|
566
|
-
const mapped$ = response$.map(({ _reqId, _action, data }) => {
|
|
567
|
-
if (!_reqId) {
|
|
568
|
-
throw new Error(`No request id found for response for: ${ command }`)
|
|
569
|
-
}
|
|
570
|
-
return { _reqId, _action, command, data }
|
|
571
|
-
});
|
|
572
|
-
return [ ...acc, mapped$ ]
|
|
573
|
-
}, []);
|
|
574
|
-
|
|
575
|
-
this.sendResponse$ = xs.merge(...out$)
|
|
576
|
-
.compose(this.log(({ _reqId, _action }) => `[${ this.requestSourceName }] response sent for: <${ _action }>`));
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
initChildren$() {
|
|
580
|
-
const initial = this.sourceNames.reduce((acc, name) => {
|
|
581
|
-
if (name == this.DOMSourceName) {
|
|
582
|
-
acc[name] = {};
|
|
583
|
-
} else {
|
|
584
|
-
acc[name] = [];
|
|
585
|
-
}
|
|
586
|
-
return acc
|
|
587
|
-
}, {});
|
|
588
|
-
|
|
589
|
-
this.children$ = Object.entries(this.children).reduce((acc, [childName, childFactory]) => {
|
|
590
|
-
const child$ = childFactory(this.sources);
|
|
591
|
-
this.sourceNames.forEach(source => {
|
|
592
|
-
if (source == this.DOMSourceName) {
|
|
593
|
-
acc[source][childName] = child$[source];
|
|
594
|
-
} else {
|
|
595
|
-
acc[source].push(child$[source]);
|
|
596
|
-
}
|
|
597
|
-
});
|
|
598
|
-
return acc
|
|
599
|
-
}, initial);
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
initSubComponentSink$() {
|
|
603
|
-
const subComponentSink$ = xs.create({
|
|
604
|
-
start: listener => {
|
|
605
|
-
this.newSubComponentSinks = listener.next.bind(listener);
|
|
606
|
-
},
|
|
607
|
-
stop: _ => {
|
|
608
|
-
|
|
609
|
-
}
|
|
610
|
-
});
|
|
611
|
-
subComponentSink$.subscribe({ next: _ => _ });
|
|
612
|
-
this.subComponentSink$ = subComponentSink$.filter(sinks => Object.keys(sinks).length > 0);
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
initVdom$() {
|
|
616
|
-
if (typeof this.view != 'function') {
|
|
617
|
-
this.vdom$ = xs.of(null);
|
|
618
|
-
return
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
const state = this.sources[this.stateSourceName];
|
|
622
|
-
const renderParams = { ...this.children$[this.DOMSourceName] };
|
|
623
|
-
|
|
624
|
-
const enhancedState = state && state.isolateSource(state, { get: state => this.addCalculated(state) });
|
|
625
|
-
const stateStream = (enhancedState && enhancedState.stream) || xs.never();
|
|
626
|
-
|
|
627
|
-
renderParams.state = stateStream;
|
|
628
|
-
renderParams[this.stateSourceName] = stateStream;
|
|
629
|
-
|
|
630
|
-
if (this.sources.props$) {
|
|
631
|
-
renderParams.props = this.sources.props$;
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
if (this.sources.children$) {
|
|
635
|
-
renderParams.children = this.sources.children$;
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
const pulled = Object.entries(renderParams).reduce((acc, [name, stream]) => {
|
|
639
|
-
acc.names.push(name);
|
|
640
|
-
acc.streams.push(stream);
|
|
641
|
-
return acc
|
|
642
|
-
}, {names: [], streams: []});
|
|
643
|
-
|
|
644
|
-
const merged = xs.combine(...pulled.streams);
|
|
645
|
-
|
|
646
|
-
const throttled = merged
|
|
647
|
-
.compose(debounce(5))
|
|
648
|
-
.map(arr => {
|
|
649
|
-
return pulled.names.reduce((acc, name, index) => {
|
|
650
|
-
acc[name] = arr[index];
|
|
651
|
-
return acc
|
|
652
|
-
}, {})
|
|
653
|
-
});
|
|
654
|
-
|
|
655
|
-
const componentNames = Object.keys(this.components);
|
|
656
|
-
|
|
657
|
-
const subComponentRenderedProxy$ = xs.create();
|
|
658
|
-
const vDom$ = throttled.map((params) => params).map(this.view).map(vDom => vDom || { sel: 'div', data: {}, children: [] });
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
const componentInstances$ = vDom$
|
|
662
|
-
.fold((previousComponents, vDom) => {
|
|
663
|
-
const foundComponents = getComponents(vDom, componentNames);
|
|
664
|
-
const entries = Object.entries(foundComponents);
|
|
665
|
-
|
|
666
|
-
const rootEntry = { '::ROOT::': vDom };
|
|
667
|
-
|
|
668
|
-
if (entries.length === 0) {
|
|
669
|
-
return rootEntry
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
const sinkArrsByType = {};
|
|
673
|
-
|
|
674
|
-
const newComponents = entries.reduce((acc, [id, el]) => {
|
|
675
|
-
const componentName = el.sel;
|
|
676
|
-
const data = el.data;
|
|
677
|
-
const props = data.props || {};
|
|
678
|
-
const children = el.children || [];
|
|
679
|
-
const isCollection = data.isCollection || false;
|
|
680
|
-
const isSwitchable = data.isSwitchable || false;
|
|
681
|
-
|
|
682
|
-
if (previousComponents[id]) {
|
|
683
|
-
const entry = previousComponents[id];
|
|
684
|
-
acc[id] = entry;
|
|
685
|
-
entry.props$.shamefullySendNext(props);
|
|
686
|
-
entry.children$.shamefullySendNext(children);
|
|
687
|
-
return acc
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
const factory = componentName === 'sygnal-factory' ? props.sygnalFactory : (this.components[componentName] || props.sygnalFactory);
|
|
691
|
-
if (!factory && !isCollection && !isSwitchable) {
|
|
692
|
-
if (componentName === 'sygnal-factory') throw new Error(`Component not found on element with Capitalized selector and nameless function: JSX transpilation replaces selectors starting with upper case letters with functions in-scope with the same name, Sygnal cannot see the name of the resulting component.`)
|
|
693
|
-
throw new Error(`Component not found: ${ componentName }`)
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
const props$ = xs.create().startWith(props);
|
|
697
|
-
const children$ = xs.create().startWith(children);
|
|
698
|
-
let stateSource = new StateSource(this.sources[this.stateSourceName].stream.startWith(this.currentState));
|
|
699
|
-
let sink$;
|
|
700
|
-
let preventStateUpdates = true;
|
|
701
|
-
|
|
702
|
-
if (isCollection) {
|
|
703
|
-
let field, lense;
|
|
704
|
-
|
|
705
|
-
const stateGetter = state => {
|
|
706
|
-
const arr = state[field];
|
|
707
|
-
if (typeof arr === 'undefined') return
|
|
708
|
-
if (!Array.isArray(arr)) {
|
|
709
|
-
const label = typeof data.props.of === 'string' ? data.props.of : 'components';
|
|
710
|
-
console.warn(`Collection of ${ label } does not have a valid array in the 'for' property: expects either an array or a string of the name of an array property on the state`);
|
|
711
|
-
return []
|
|
712
|
-
}
|
|
713
|
-
return arr
|
|
714
|
-
};
|
|
715
|
-
|
|
716
|
-
if (typeof props.for === 'undefined') {
|
|
717
|
-
lense = {
|
|
718
|
-
get: state => {
|
|
719
|
-
if (!Array.isArray(state)) {
|
|
720
|
-
console.warn(`Collection sub-component of ${ this.name } has no 'for' attribute and the parent state is not an array: Provide a 'for' attribute with either an array or the name of a state property containing an array`);
|
|
721
|
-
return []
|
|
722
|
-
}
|
|
723
|
-
return state
|
|
724
|
-
},
|
|
725
|
-
set: (oldState, newState) => newState
|
|
726
|
-
};
|
|
727
|
-
preventStateUpdates = false;
|
|
728
|
-
} else if (typeof props.for === 'string') {
|
|
729
|
-
field = props.for;
|
|
730
|
-
lense = {
|
|
731
|
-
get: stateGetter,
|
|
732
|
-
set: (state, arr) => {
|
|
733
|
-
if (this.calculated && field in this.calculated) {
|
|
734
|
-
console.warn(`Collection sub-component of ${ this.name } attempted to update state on a calculated field '${ field }': Update ignored`);
|
|
735
|
-
return state
|
|
736
|
-
}
|
|
737
|
-
return { ...state, [field]: arr }
|
|
738
|
-
}
|
|
739
|
-
};
|
|
740
|
-
preventStateUpdates = false;
|
|
741
|
-
} else {
|
|
742
|
-
field = 'for';
|
|
743
|
-
stateSource = new StateSource(props$.remember());
|
|
744
|
-
lense = {
|
|
745
|
-
get: stateGetter,
|
|
746
|
-
set: (state, arr) => state
|
|
747
|
-
};
|
|
748
|
-
}
|
|
749
|
-
const sources = { ...this.sources, [this.stateSourceName]: stateSource, props$, children$ };
|
|
750
|
-
const factory = typeof data.props.of === 'function' ? data.props.of : this.components[data.props.of];
|
|
751
|
-
sink$ = collection(factory, lense, { container: null })(sources);
|
|
752
|
-
if (typeof sink$ !== 'object') {
|
|
753
|
-
throw new Error('Invalid sinks returned from component factory of collection element')
|
|
754
|
-
}
|
|
755
|
-
} else if (isSwitchable) {
|
|
756
|
-
const stateField = data.props.state;
|
|
757
|
-
let isolateSwitchable = false;
|
|
758
|
-
let lense;
|
|
759
|
-
if (typeof stateField === 'string') {
|
|
760
|
-
isolateSwitchable = true;
|
|
761
|
-
lense = {
|
|
762
|
-
get: state => {
|
|
763
|
-
return state[stateField]
|
|
764
|
-
},
|
|
765
|
-
set: (oldState, newState) => {
|
|
766
|
-
if (this.calculated && stateField in this.calculated) {
|
|
767
|
-
console.warn(`Switchable sub-component of ${ this.name } attempted to update state on a calculated field '${ stateField }': Update ignored`);
|
|
768
|
-
return oldState
|
|
769
|
-
}
|
|
770
|
-
return { ...oldState, [stateField]: newState }
|
|
771
|
-
}
|
|
772
|
-
};
|
|
773
|
-
preventStateUpdates = false;
|
|
774
|
-
} else if (typeof stateField === 'undefined') {
|
|
775
|
-
isolateSwitchable = true;
|
|
776
|
-
lense = {
|
|
777
|
-
get: state => state,
|
|
778
|
-
set: (oldState, newState) => newState
|
|
779
|
-
};
|
|
780
|
-
preventStateUpdates = false;
|
|
781
|
-
} else if (typeof stateField === 'object') {
|
|
782
|
-
stateSource = new StateSource(props$.map(props => props.state));
|
|
783
|
-
} else {
|
|
784
|
-
throw new Error(`Invalid state provided to collection sub-component of ${ this.name }: Expecting string, object, or none, but found ${ typeof stateField }`)
|
|
785
|
-
}
|
|
786
|
-
const switchableComponents = data.props.of;
|
|
787
|
-
const sources = { ...this.sources, [this.stateSourceName]: stateSource, props$, children$ };
|
|
788
|
-
if (isolateSwitchable) {
|
|
789
|
-
sink$ = isolate(switchable(switchableComponents, props$.map(props => props.current)), { [this.stateSourceName]: lense })(sources);
|
|
790
|
-
} else {
|
|
791
|
-
sink$ = switchable(switchableComponents, props$.map(props => props.current))(sources);
|
|
792
|
-
}
|
|
793
|
-
if (typeof sink$ !== 'object') {
|
|
794
|
-
throw new Error('Invalid sinks returned from component factory of switchable element')
|
|
795
|
-
}
|
|
796
|
-
} else {
|
|
797
|
-
const { state: stateProp, sygnalFactory, id, ...sanitizedProps } = props;
|
|
798
|
-
if (typeof stateProp === 'undefined' && (typeof sanitizedProps !== 'object' || Object.keys(sanitizedProps).length === 0)) {
|
|
799
|
-
const sources = { ...this.sources, [this.stateSourceName]: stateSource, props$: xs.never().startWith(null), children$ };
|
|
800
|
-
sink$ = factory(sources);
|
|
801
|
-
preventStateUpdates = false;
|
|
802
|
-
} else {
|
|
803
|
-
const lense = (props) => {
|
|
804
|
-
const state = props.state;
|
|
805
|
-
if (typeof state === 'undefined') return props
|
|
806
|
-
if (typeof state !== 'object') return state
|
|
807
|
-
|
|
808
|
-
const copy = { ...props };
|
|
809
|
-
delete copy.state;
|
|
810
|
-
return { ...copy, ...state }
|
|
811
|
-
};
|
|
812
|
-
stateSource = new StateSource(props$.map(lense));
|
|
813
|
-
const sources = { ...this.sources, [this.stateSourceName]: stateSource, props$, children$ };
|
|
814
|
-
sink$ = factory(sources);
|
|
815
|
-
}
|
|
816
|
-
if (typeof sink$ !== 'object') {
|
|
817
|
-
const name = componentName === 'sygnal-factory' ? 'custom element' : componentName;
|
|
818
|
-
throw new Error('Invalid sinks returned from component factory:', name)
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
if (preventStateUpdates) {
|
|
823
|
-
const originalStateSink = sink$[this.stateSourceName];
|
|
824
|
-
sink$[this.stateSourceName] = originalStateSink.filter(state => {
|
|
825
|
-
console.warn('State update attempt from component with inderect link to state: Components with state set through HTML properties/attributes cannot update application state directly');
|
|
826
|
-
return false
|
|
827
|
-
});
|
|
828
|
-
}
|
|
3511
|
+
const mapped$ = response$.map(({ _reqId, _action, data }) => {
|
|
3512
|
+
if (!_reqId) {
|
|
3513
|
+
throw new Error(`No request id found for response for: ${ command }`)
|
|
3514
|
+
}
|
|
3515
|
+
return { _reqId, _action, command, data }
|
|
3516
|
+
});
|
|
3517
|
+
return [ ...acc, mapped$ ]
|
|
3518
|
+
}, []);
|
|
829
3519
|
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
const bb = JSON.stringify(b);
|
|
834
|
-
return aa === bb
|
|
835
|
-
};
|
|
836
|
-
sink$[this.DOMSourceName] = stateSource.stream.compose(dropRepeats$1(repeatChecker)).map(state => {
|
|
837
|
-
subComponentRenderedProxy$.shamefullySendNext(null);
|
|
838
|
-
return originalDOMSink
|
|
839
|
-
}).compose(debounce(10)).flatten().remember();
|
|
840
|
-
acc[id] = { sink$, props$, children$ };
|
|
841
|
-
|
|
842
|
-
Object.entries(sink$).map(([name, stream]) => {
|
|
843
|
-
sinkArrsByType[name] ||= [];
|
|
844
|
-
if (name !== this.DOMSourceName) sinkArrsByType[name].push(stream);
|
|
845
|
-
});
|
|
3520
|
+
this.sendResponse$ = xs$1.merge(...out$)
|
|
3521
|
+
.compose(this.log(({ _reqId, _action }) => `[${ this.requestSourceName }] response sent for: <${ _action }>`));
|
|
3522
|
+
}
|
|
846
3523
|
|
|
847
|
-
|
|
848
|
-
|
|
3524
|
+
initChildren$() {
|
|
3525
|
+
const initial = this.sourceNames.reduce((acc, name) => {
|
|
3526
|
+
if (name == this.DOMSourceName) {
|
|
3527
|
+
acc[name] = {};
|
|
3528
|
+
} else {
|
|
3529
|
+
acc[name] = [];
|
|
3530
|
+
}
|
|
3531
|
+
return acc
|
|
3532
|
+
}, {});
|
|
849
3533
|
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
3534
|
+
this.children$ = Object.entries(this.children).reduce((acc, [childName, childFactory]) => {
|
|
3535
|
+
const child$ = childFactory(this.sources);
|
|
3536
|
+
this.sourceNames.forEach(source => {
|
|
3537
|
+
if (source == this.DOMSourceName) {
|
|
3538
|
+
acc[source][childName] = child$[source];
|
|
3539
|
+
} else {
|
|
3540
|
+
acc[source].push(child$[source]);
|
|
3541
|
+
}
|
|
3542
|
+
});
|
|
3543
|
+
return acc
|
|
3544
|
+
}, initial);
|
|
3545
|
+
}
|
|
855
3546
|
|
|
856
|
-
|
|
3547
|
+
initSubComponentSink$() {
|
|
3548
|
+
const subComponentSink$ = xs$1.create({
|
|
3549
|
+
start: listener => {
|
|
3550
|
+
this.newSubComponentSinks = listener.next.bind(listener);
|
|
3551
|
+
},
|
|
3552
|
+
stop: _ => {
|
|
857
3553
|
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
3554
|
+
}
|
|
3555
|
+
});
|
|
3556
|
+
subComponentSink$.subscribe({ next: _ => _ });
|
|
3557
|
+
this.subComponentSink$ = subComponentSink$.filter(sinks => Object.keys(sinks).length > 0);
|
|
3558
|
+
}
|
|
861
3559
|
|
|
3560
|
+
initSubComponentsRendered$() {
|
|
3561
|
+
const stream = xs$1.create({
|
|
3562
|
+
start: (listener) => {
|
|
3563
|
+
this.subComponentsRendered = listener.next.bind(listener);
|
|
3564
|
+
},
|
|
3565
|
+
stop: _ => {
|
|
862
3566
|
|
|
863
|
-
|
|
3567
|
+
}
|
|
3568
|
+
});
|
|
3569
|
+
this.subComponentsRendered$ = stream.startWith(null);
|
|
3570
|
+
}
|
|
864
3571
|
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
3572
|
+
initVdom$() {
|
|
3573
|
+
if (typeof this.view != 'function') {
|
|
3574
|
+
this.vdom$ = xs$1.of(null);
|
|
3575
|
+
return
|
|
3576
|
+
}
|
|
868
3577
|
|
|
869
|
-
|
|
870
|
-
return xs.of(root)
|
|
871
|
-
}
|
|
3578
|
+
const renderParameters$ = this.collectRenderParameters();
|
|
872
3579
|
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
3580
|
+
this.vdom$ = renderParameters$
|
|
3581
|
+
.map(this.view)
|
|
3582
|
+
.map(vDom => vDom || { sel: 'div', data: {}, children: [] })
|
|
3583
|
+
.compose(this.instantiateSubComponents.bind(this))
|
|
3584
|
+
.filter(val => val !== undefined)
|
|
3585
|
+
.compose(this.renderVdom.bind(this));
|
|
878
3586
|
|
|
879
|
-
if (vdom$.length === 0) return xs.of(root)
|
|
880
|
-
|
|
881
|
-
return xs.combine(...vdom$).compose(debounce(5)).map(vdoms => {
|
|
882
|
-
const withIds = vdoms.reduce((acc, vdom, index) => {
|
|
883
|
-
acc[ids[index]] = vdom;
|
|
884
|
-
return acc
|
|
885
|
-
}, {});
|
|
886
|
-
const rootCopy = deepCopyVdom(root);
|
|
887
|
-
const injected = injectComponents(rootCopy, withIds, componentNames);
|
|
888
|
-
return injected
|
|
889
|
-
})
|
|
890
|
-
})
|
|
891
|
-
.flatten()
|
|
892
|
-
.filter(val => !!val)
|
|
893
|
-
.compose(debounce(5))
|
|
894
|
-
.remember()
|
|
895
|
-
.compose(this.log('View Rendered'));
|
|
896
3587
|
}
|
|
897
3588
|
|
|
898
3589
|
initSinks() {
|
|
899
3590
|
this.sinks = this.sourceNames.reduce((acc, name) => {
|
|
900
3591
|
if (name == this.DOMSourceName) return acc
|
|
901
|
-
const subComponentSink$ = this.subComponentSink$ ? this.subComponentSink$.map(sinks => sinks[name]).filter(sink => !!sink).flatten() : xs.never();
|
|
3592
|
+
const subComponentSink$ = this.subComponentSink$ ? this.subComponentSink$.map(sinks => sinks[name]).filter(sink => !!sink).flatten() : xs$1.never();
|
|
902
3593
|
if (name === this.stateSourceName) {
|
|
903
|
-
acc[name] = xs.merge((this.model$[name] || xs.never()), subComponentSink$, this.sources[this.stateSourceName].stream.filter(_ => false), ...this.children$[name]);
|
|
3594
|
+
acc[name] = xs$1.merge((this.model$[name] || xs$1.never()), subComponentSink$, this.sources[this.stateSourceName].stream.filter(_ => false), ...this.children$[name]);
|
|
904
3595
|
} else {
|
|
905
|
-
acc[name] = xs.merge((this.model$[name] || xs.never()), subComponentSink$, ...this.children$[name]);
|
|
3596
|
+
acc[name] = xs$1.merge((this.model$[name] || xs$1.never()), subComponentSink$, ...this.children$[name]);
|
|
906
3597
|
}
|
|
907
3598
|
return acc
|
|
908
3599
|
}, {});
|
|
909
3600
|
|
|
910
3601
|
this.sinks[this.DOMSourceName] = this.vdom$;
|
|
911
|
-
this.sinks[this.requestSourceName] = xs.merge(this.sendResponse$ ,this.sinks[this.requestSourceName]);
|
|
3602
|
+
this.sinks[this.requestSourceName] = xs$1.merge(this.sendResponse$ ,this.sinks[this.requestSourceName]);
|
|
912
3603
|
}
|
|
913
3604
|
|
|
914
3605
|
makeOnAction(action$, isStateSink=true, rootAction$) {
|
|
@@ -995,6 +3686,335 @@ class Component {
|
|
|
995
3686
|
return copy
|
|
996
3687
|
}
|
|
997
3688
|
|
|
3689
|
+
collectRenderParameters() {
|
|
3690
|
+
const state = this.sources[this.stateSourceName];
|
|
3691
|
+
const renderParams = { ...this.children$[this.DOMSourceName] };
|
|
3692
|
+
|
|
3693
|
+
const enhancedState = state && state.isolateSource(state, { get: state => this.addCalculated(state) });
|
|
3694
|
+
const stateStream = (enhancedState && enhancedState.stream) || xs$1.never();
|
|
3695
|
+
|
|
3696
|
+
renderParams.state = stateStream;
|
|
3697
|
+
renderParams[this.stateSourceName] = stateStream;
|
|
3698
|
+
|
|
3699
|
+
if (this.sources.props$) {
|
|
3700
|
+
renderParams.props = this.sources.props$;
|
|
3701
|
+
}
|
|
3702
|
+
|
|
3703
|
+
if (this.sources.children$) {
|
|
3704
|
+
renderParams.children = this.sources.children$;
|
|
3705
|
+
}
|
|
3706
|
+
|
|
3707
|
+
const names = [];
|
|
3708
|
+
const streams = [];
|
|
3709
|
+
|
|
3710
|
+
Object.entries(renderParams).forEach(([name, stream]) => {
|
|
3711
|
+
names.push(name);
|
|
3712
|
+
streams.push(stream);
|
|
3713
|
+
});
|
|
3714
|
+
|
|
3715
|
+
const combined = xs$1.combine(...streams)
|
|
3716
|
+
// map the streams from an array back to an object with the render parameter names as the keys
|
|
3717
|
+
.map(arr => {
|
|
3718
|
+
return names.reduce((acc, name, index) => {
|
|
3719
|
+
acc[name] = arr[index];
|
|
3720
|
+
return acc
|
|
3721
|
+
}, {})
|
|
3722
|
+
});
|
|
3723
|
+
|
|
3724
|
+
return combined
|
|
3725
|
+
}
|
|
3726
|
+
|
|
3727
|
+
instantiateSubComponents(vDom$) {
|
|
3728
|
+
return vDom$.fold((previousComponents, vDom) => {
|
|
3729
|
+
const componentNames = Object.keys(this.components);
|
|
3730
|
+
const foundComponents = getComponents(vDom, componentNames);
|
|
3731
|
+
const entries = Object.entries(foundComponents);
|
|
3732
|
+
|
|
3733
|
+
const rootEntry = { '::ROOT::': vDom };
|
|
3734
|
+
|
|
3735
|
+
if (entries.length === 0) {
|
|
3736
|
+
return rootEntry
|
|
3737
|
+
}
|
|
3738
|
+
|
|
3739
|
+
const sinkArrsByType = {};
|
|
3740
|
+
|
|
3741
|
+
const newComponents = entries.reduce((acc, [id, el]) => {
|
|
3742
|
+
const data = el.data;
|
|
3743
|
+
const props = data.props || {};
|
|
3744
|
+
const children = el.children || [];
|
|
3745
|
+
|
|
3746
|
+
const isCollection = data.isCollection || false;
|
|
3747
|
+
const isSwitchable = data.isSwitchable || false;
|
|
3748
|
+
|
|
3749
|
+
if (previousComponents[id]) {
|
|
3750
|
+
const entry = previousComponents[id];
|
|
3751
|
+
acc[id] = entry;
|
|
3752
|
+
entry.props$.shamefullySendNext(props);
|
|
3753
|
+
entry.children$.shamefullySendNext(children);
|
|
3754
|
+
return acc
|
|
3755
|
+
}
|
|
3756
|
+
|
|
3757
|
+
const props$ = xs$1.create().startWith(props);
|
|
3758
|
+
const children$ = xs$1.create().startWith(children);
|
|
3759
|
+
|
|
3760
|
+
let instantiator;
|
|
3761
|
+
|
|
3762
|
+
if (isCollection) {
|
|
3763
|
+
instantiator = this.instantiateCollection.bind(this);
|
|
3764
|
+
} else if (isSwitchable) {
|
|
3765
|
+
instantiator = this.instantiateSwitchable.bind(this);
|
|
3766
|
+
} else {
|
|
3767
|
+
instantiator = this.instantiateCustomComponent.bind(this);
|
|
3768
|
+
}
|
|
3769
|
+
|
|
3770
|
+
const { sink$, preventStateUpdates } = instantiator(el, props$, children$);
|
|
3771
|
+
|
|
3772
|
+
if (preventStateUpdates) {
|
|
3773
|
+
const originalStateSink = sink$[this.stateSourceName];
|
|
3774
|
+
sink$[this.stateSourceName] = originalStateSink.filter(state => {
|
|
3775
|
+
console.warn('State update attempt from component with inderect link to state: Components with state set through HTML properties/attributes cannot update application state directly');
|
|
3776
|
+
return false
|
|
3777
|
+
});
|
|
3778
|
+
}
|
|
3779
|
+
|
|
3780
|
+
sink$[this.DOMSourceName] = this.makeCoordinatedSubComponentDomSink(sink$[this.DOMSourceName]);
|
|
3781
|
+
|
|
3782
|
+
acc[id] = { sink$, props$, children$ };
|
|
3783
|
+
|
|
3784
|
+
Object.entries(sink$).map(([name, stream]) => {
|
|
3785
|
+
sinkArrsByType[name] ||= [];
|
|
3786
|
+
if (name !== this.DOMSourceName) sinkArrsByType[name].push(stream);
|
|
3787
|
+
});
|
|
3788
|
+
|
|
3789
|
+
return acc
|
|
3790
|
+
}, rootEntry);
|
|
3791
|
+
|
|
3792
|
+
const mergedSinksByType = Object.entries(sinkArrsByType).reduce((acc, [name, streamArr]) => {
|
|
3793
|
+
if (streamArr.length === 0) return acc
|
|
3794
|
+
acc[name] = streamArr.length === 1 ? streamArr[0] : xs$1.merge(...streamArr);
|
|
3795
|
+
return acc
|
|
3796
|
+
}, {});
|
|
3797
|
+
|
|
3798
|
+
this.newSubComponentSinks(mergedSinksByType);
|
|
3799
|
+
|
|
3800
|
+
return newComponents
|
|
3801
|
+
}, {})
|
|
3802
|
+
}
|
|
3803
|
+
|
|
3804
|
+
makeCoordinatedSubComponentDomSink(domSink$) {
|
|
3805
|
+
const remembered$ = domSink$.remember();
|
|
3806
|
+
const repeatChecker = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
3807
|
+
|
|
3808
|
+
const coordinated = this.sources[this.stateSourceName].stream
|
|
3809
|
+
.compose(_default$5(repeatChecker))
|
|
3810
|
+
.map(state => remembered$)
|
|
3811
|
+
.compose(_default$2(10))
|
|
3812
|
+
.flatten()
|
|
3813
|
+
.debug(_ => this.subComponentsRendered())
|
|
3814
|
+
.remember();
|
|
3815
|
+
|
|
3816
|
+
return coordinated
|
|
3817
|
+
}
|
|
3818
|
+
|
|
3819
|
+
instantiateCollection(el, props$, children$) {
|
|
3820
|
+
const data = el.data;
|
|
3821
|
+
const props = data.props || {};
|
|
3822
|
+
el.children || [];
|
|
3823
|
+
let stateSource = new StateSource(this.sources[this.stateSourceName].stream.startWith(this.currentState));
|
|
3824
|
+
|
|
3825
|
+
let preventStateUpdates = false;
|
|
3826
|
+
let sink$, field, lense;
|
|
3827
|
+
|
|
3828
|
+
const stateGetter = state => {
|
|
3829
|
+
const arr = state[field];
|
|
3830
|
+
if (typeof arr === 'undefined') return
|
|
3831
|
+
if (!Array.isArray(arr)) {
|
|
3832
|
+
const label = typeof props.of === 'string' ? props.of : 'components';
|
|
3833
|
+
console.warn(`Collection of ${ label } does not have a valid array in the 'for' property: expects either an array or a string of the name of an array property on the state`);
|
|
3834
|
+
return []
|
|
3835
|
+
}
|
|
3836
|
+
return arr
|
|
3837
|
+
};
|
|
3838
|
+
|
|
3839
|
+
if (typeof props.for === 'undefined') {
|
|
3840
|
+
lense = {
|
|
3841
|
+
get: state => {
|
|
3842
|
+
if (!Array.isArray(state)) {
|
|
3843
|
+
console.warn(`Collection sub-component of ${ this.name } has no 'for' attribute and the parent state is not an array: Provide a 'for' attribute with either an array or the name of a state property containing an array`);
|
|
3844
|
+
return []
|
|
3845
|
+
}
|
|
3846
|
+
return state
|
|
3847
|
+
},
|
|
3848
|
+
set: (oldState, newState) => newState
|
|
3849
|
+
};
|
|
3850
|
+
} else if (typeof props.for === 'string') {
|
|
3851
|
+
field = props.for;
|
|
3852
|
+
lense = {
|
|
3853
|
+
get: stateGetter,
|
|
3854
|
+
set: (state, arr) => {
|
|
3855
|
+
if (this.calculated && field in this.calculated) {
|
|
3856
|
+
console.warn(`Collection sub-component of ${ this.name } attempted to update state on a calculated field '${ field }': Update ignored`);
|
|
3857
|
+
return state
|
|
3858
|
+
}
|
|
3859
|
+
return { ...state, [field]: arr }
|
|
3860
|
+
}
|
|
3861
|
+
};
|
|
3862
|
+
} else {
|
|
3863
|
+
field = 'for';
|
|
3864
|
+
stateSource = new StateSource(props$.remember());
|
|
3865
|
+
lense = {
|
|
3866
|
+
get: stateGetter,
|
|
3867
|
+
set: (state, arr) => state
|
|
3868
|
+
};
|
|
3869
|
+
preventStateUpdates = true;
|
|
3870
|
+
}
|
|
3871
|
+
const sources = { ...this.sources, [this.stateSourceName]: stateSource, props$, children$ };
|
|
3872
|
+
const factory = typeof props.of === 'function' ? props.of : this.components[props.of];
|
|
3873
|
+
sink$ = collection(factory, lense, { container: null })(sources);
|
|
3874
|
+
if (typeof sink$ !== 'object') {
|
|
3875
|
+
throw new Error('Invalid sinks returned from component factory of collection element')
|
|
3876
|
+
}
|
|
3877
|
+
return { sink$, preventStateUpdates }
|
|
3878
|
+
}
|
|
3879
|
+
|
|
3880
|
+
instantiateSwitchable(el, props$, children$) {
|
|
3881
|
+
const data = el.data;
|
|
3882
|
+
const props = data.props || {};
|
|
3883
|
+
el.children || [];
|
|
3884
|
+
let stateSource = new StateSource(this.sources[this.stateSourceName].stream.startWith(this.currentState));
|
|
3885
|
+
|
|
3886
|
+
const stateField = props.state;
|
|
3887
|
+
let preventStateUpdates = false;
|
|
3888
|
+
let isolateSwitchable = false;
|
|
3889
|
+
let sink$, lense;
|
|
3890
|
+
|
|
3891
|
+
if (typeof stateField === 'string') {
|
|
3892
|
+
isolateSwitchable = true;
|
|
3893
|
+
lense = {
|
|
3894
|
+
get: state => {
|
|
3895
|
+
return state[stateField]
|
|
3896
|
+
},
|
|
3897
|
+
set: (oldState, newState) => {
|
|
3898
|
+
if (this.calculated && stateField in this.calculated) {
|
|
3899
|
+
console.warn(`Switchable sub-component of ${ this.name } attempted to update state on a calculated field '${ stateField }': Update ignored`);
|
|
3900
|
+
return oldState
|
|
3901
|
+
}
|
|
3902
|
+
return { ...oldState, [stateField]: newState }
|
|
3903
|
+
}
|
|
3904
|
+
};
|
|
3905
|
+
preventStateUpdates = false;
|
|
3906
|
+
} else if (typeof stateField === 'undefined') {
|
|
3907
|
+
isolateSwitchable = true;
|
|
3908
|
+
lense = {
|
|
3909
|
+
get: state => state,
|
|
3910
|
+
set: (oldState, newState) => newState
|
|
3911
|
+
};
|
|
3912
|
+
preventStateUpdates = false;
|
|
3913
|
+
} else if (typeof stateField === 'object') {
|
|
3914
|
+
stateSource = new StateSource(props$.map(props => props.state));
|
|
3915
|
+
} else {
|
|
3916
|
+
throw new Error(`Invalid state provided to collection sub-component of ${ this.name }: Expecting string, object, or none, but found ${ typeof stateField }`)
|
|
3917
|
+
}
|
|
3918
|
+
|
|
3919
|
+
const switchableComponents = data.props.of;
|
|
3920
|
+
const sources = { ...this.sources, [this.stateSourceName]: stateSource, props$, children$ };
|
|
3921
|
+
if (isolateSwitchable) {
|
|
3922
|
+
sink$ = isolate(switchable(switchableComponents, props$.map(props => props.current)), { [this.stateSourceName]: lense })(sources);
|
|
3923
|
+
} else {
|
|
3924
|
+
sink$ = switchable(switchableComponents, props$.map(props => props.current))(sources);
|
|
3925
|
+
}
|
|
3926
|
+
|
|
3927
|
+
if (typeof sink$ !== 'object') {
|
|
3928
|
+
throw new Error('Invalid sinks returned from component factory of switchable element')
|
|
3929
|
+
}
|
|
3930
|
+
|
|
3931
|
+
return { sink$, preventStateUpdates }
|
|
3932
|
+
}
|
|
3933
|
+
|
|
3934
|
+
instantiateCustomComponent(el, props$, children$) {
|
|
3935
|
+
const componentName = el.sel;
|
|
3936
|
+
const data = el.data;
|
|
3937
|
+
const props = data.props || {};
|
|
3938
|
+
el.children || [];
|
|
3939
|
+
let stateSource = new StateSource(this.sources[this.stateSourceName].stream.startWith(this.currentState));
|
|
3940
|
+
|
|
3941
|
+
const factory = componentName === 'sygnal-factory' ? props.sygnalFactory : (this.components[componentName] || props.sygnalFactory);
|
|
3942
|
+
if (!factory && !isCollection && !isSwitchable) {
|
|
3943
|
+
if (componentName === 'sygnal-factory') throw new Error(`Component not found on element with Capitalized selector and nameless function: JSX transpilation replaces selectors starting with upper case letters with functions in-scope with the same name, Sygnal cannot see the name of the resulting component.`)
|
|
3944
|
+
throw new Error(`Component not found: ${ componentName }`)
|
|
3945
|
+
}
|
|
3946
|
+
|
|
3947
|
+
let preventStateUpdates = false;
|
|
3948
|
+
let sink$;
|
|
3949
|
+
|
|
3950
|
+
const { state: stateProp, sygnalFactory, id, ...sanitizedProps } = props;
|
|
3951
|
+
if (typeof stateProp === 'undefined' && (typeof sanitizedProps !== 'object' || Object.keys(sanitizedProps).length === 0)) {
|
|
3952
|
+
const sources = { ...this.sources, [this.stateSourceName]: stateSource, props$: xs$1.never().startWith(null), children$ };
|
|
3953
|
+
sink$ = factory(sources);
|
|
3954
|
+
preventStateUpdates = false;
|
|
3955
|
+
} else {
|
|
3956
|
+
const lense = (props) => {
|
|
3957
|
+
const state = props.state;
|
|
3958
|
+
if (typeof state === 'undefined') return props
|
|
3959
|
+
if (typeof state !== 'object') return state
|
|
3960
|
+
|
|
3961
|
+
const copy = { ...props };
|
|
3962
|
+
delete copy.state;
|
|
3963
|
+
return { ...copy, ...state }
|
|
3964
|
+
};
|
|
3965
|
+
stateSource = new StateSource(props$.map(lense));
|
|
3966
|
+
const sources = { ...this.sources, [this.stateSourceName]: stateSource, props$, children$ };
|
|
3967
|
+
sink$ = factory(sources);
|
|
3968
|
+
}
|
|
3969
|
+
|
|
3970
|
+
if (typeof sink$ !== 'object') {
|
|
3971
|
+
const name = componentName === 'sygnal-factory' ? 'custom element' : componentName;
|
|
3972
|
+
throw new Error('Invalid sinks returned from component factory:', name)
|
|
3973
|
+
}
|
|
3974
|
+
|
|
3975
|
+
return { sink$, preventStateUpdates }
|
|
3976
|
+
}
|
|
3977
|
+
|
|
3978
|
+
renderVdom(componentInstances$) {
|
|
3979
|
+
return xs$1.combine(this.subComponentsRendered$, componentInstances$)
|
|
3980
|
+
.compose(_default$2(5))
|
|
3981
|
+
.map(([_, components]) => {
|
|
3982
|
+
const componentNames = Object.keys(this.components);
|
|
3983
|
+
|
|
3984
|
+
const root = components['::ROOT::'];
|
|
3985
|
+
const entries = Object.entries(components).filter(([id]) => id !== '::ROOT::');
|
|
3986
|
+
|
|
3987
|
+
if (entries.length === 0) {
|
|
3988
|
+
return xs$1.of(root)
|
|
3989
|
+
}
|
|
3990
|
+
|
|
3991
|
+
const ids = [];
|
|
3992
|
+
const vdom$ = entries
|
|
3993
|
+
.map(([id, val]) => {
|
|
3994
|
+
ids.push(id);
|
|
3995
|
+
return val.sink$[this.DOMSourceName].startWith(undefined)
|
|
3996
|
+
});
|
|
3997
|
+
|
|
3998
|
+
if (vdom$.length === 0) return xs$1.of(root)
|
|
3999
|
+
|
|
4000
|
+
return xs$1.combine(...vdom$)
|
|
4001
|
+
.compose(_default$2(10))
|
|
4002
|
+
.map(vdoms => {
|
|
4003
|
+
const withIds = vdoms.reduce((acc, vdom, index) => {
|
|
4004
|
+
acc[ids[index]] = vdom;
|
|
4005
|
+
return acc
|
|
4006
|
+
}, {});
|
|
4007
|
+
const rootCopy = deepCopyVdom(root);
|
|
4008
|
+
const injected = injectComponents(rootCopy, withIds, componentNames);
|
|
4009
|
+
return injected
|
|
4010
|
+
})
|
|
4011
|
+
})
|
|
4012
|
+
.flatten()
|
|
4013
|
+
.filter(val => !!val)
|
|
4014
|
+
.remember()
|
|
4015
|
+
.compose(this.log('View Rendered'))
|
|
4016
|
+
}
|
|
4017
|
+
|
|
998
4018
|
}
|
|
999
4019
|
|
|
1000
4020
|
|
|
@@ -1143,7 +4163,7 @@ function processForm(form, options={}) {
|
|
|
1143
4163
|
|
|
1144
4164
|
const eventStream$ = events.map(event => form.events(event));
|
|
1145
4165
|
|
|
1146
|
-
const merged$ = xs.merge(...eventStream$);
|
|
4166
|
+
const merged$ = xs$1.merge(...eventStream$);
|
|
1147
4167
|
|
|
1148
4168
|
return merged$.map((e) => {
|
|
1149
4169
|
if (preventDefault) e.preventDefault();
|
|
@@ -1164,6 +4184,34 @@ function processForm(form, options={}) {
|
|
|
1164
4184
|
})
|
|
1165
4185
|
}
|
|
1166
4186
|
|
|
4187
|
+
var adapt$1 = {};
|
|
4188
|
+
|
|
4189
|
+
Object.defineProperty(adapt$1, "__esModule", { value: true });
|
|
4190
|
+
function getGlobal() {
|
|
4191
|
+
var globalObj;
|
|
4192
|
+
if (typeof window !== 'undefined') {
|
|
4193
|
+
globalObj = window;
|
|
4194
|
+
}
|
|
4195
|
+
else if (typeof commonjsGlobal !== 'undefined') {
|
|
4196
|
+
globalObj = commonjsGlobal;
|
|
4197
|
+
}
|
|
4198
|
+
else {
|
|
4199
|
+
globalObj = this;
|
|
4200
|
+
}
|
|
4201
|
+
globalObj.Cyclejs = globalObj.Cyclejs || {};
|
|
4202
|
+
globalObj = globalObj.Cyclejs;
|
|
4203
|
+
globalObj.adaptStream = globalObj.adaptStream || (function (x) { return x; });
|
|
4204
|
+
return globalObj;
|
|
4205
|
+
}
|
|
4206
|
+
function setAdapt(f) {
|
|
4207
|
+
getGlobal().adaptStream = f;
|
|
4208
|
+
}
|
|
4209
|
+
adapt$1.setAdapt = setAdapt;
|
|
4210
|
+
function adapt(stream) {
|
|
4211
|
+
return getGlobal().adaptStream(stream);
|
|
4212
|
+
}
|
|
4213
|
+
var adapt_2 = adapt$1.adapt = adapt;
|
|
4214
|
+
|
|
1167
4215
|
function eventBusDriver(out$) {
|
|
1168
4216
|
const events = new EventTarget();
|
|
1169
4217
|
|
|
@@ -1176,7 +4224,7 @@ function eventBusDriver(out$) {
|
|
|
1176
4224
|
const all = !type;
|
|
1177
4225
|
const _type = (Array.isArray(type)) ? type : [type];
|
|
1178
4226
|
let cb;
|
|
1179
|
-
const in$ = xs.create({
|
|
4227
|
+
const in$ = xs$1.create({
|
|
1180
4228
|
start: (listener) => {
|
|
1181
4229
|
cb = ({detail: event}) => {
|
|
1182
4230
|
const data = (event && event.data) || null;
|
|
@@ -1187,7 +4235,7 @@ function eventBusDriver(out$) {
|
|
|
1187
4235
|
stop: _ => events.removeEventListener('data', cb)
|
|
1188
4236
|
});
|
|
1189
4237
|
|
|
1190
|
-
return
|
|
4238
|
+
return adapt_2(in$)
|
|
1191
4239
|
}
|
|
1192
4240
|
}
|
|
1193
4241
|
}
|
|
@@ -1297,4 +4345,288 @@ function classes_processObject(obj) {
|
|
|
1297
4345
|
return ret
|
|
1298
4346
|
}
|
|
1299
4347
|
|
|
1300
|
-
|
|
4348
|
+
var throttle$1 = {};
|
|
4349
|
+
|
|
4350
|
+
Object.defineProperty(throttle$1, "__esModule", { value: true });
|
|
4351
|
+
var index_1$1 = xstream;
|
|
4352
|
+
var ThrottleOperator = /** @class */ (function () {
|
|
4353
|
+
function ThrottleOperator(dt, ins) {
|
|
4354
|
+
this.dt = dt;
|
|
4355
|
+
this.ins = ins;
|
|
4356
|
+
this.type = 'throttle';
|
|
4357
|
+
this.out = null;
|
|
4358
|
+
this.id = null;
|
|
4359
|
+
}
|
|
4360
|
+
ThrottleOperator.prototype._start = function (out) {
|
|
4361
|
+
this.out = out;
|
|
4362
|
+
this.ins._add(this);
|
|
4363
|
+
};
|
|
4364
|
+
ThrottleOperator.prototype._stop = function () {
|
|
4365
|
+
this.ins._remove(this);
|
|
4366
|
+
this.out = null;
|
|
4367
|
+
this.id = null;
|
|
4368
|
+
};
|
|
4369
|
+
ThrottleOperator.prototype.clearInterval = function () {
|
|
4370
|
+
var id = this.id;
|
|
4371
|
+
if (id !== null) {
|
|
4372
|
+
clearInterval(id);
|
|
4373
|
+
}
|
|
4374
|
+
this.id = null;
|
|
4375
|
+
};
|
|
4376
|
+
ThrottleOperator.prototype._n = function (t) {
|
|
4377
|
+
var _this = this;
|
|
4378
|
+
var u = this.out;
|
|
4379
|
+
if (!u)
|
|
4380
|
+
return;
|
|
4381
|
+
if (this.id)
|
|
4382
|
+
return;
|
|
4383
|
+
u._n(t);
|
|
4384
|
+
this.id = setInterval(function () {
|
|
4385
|
+
_this.clearInterval();
|
|
4386
|
+
}, this.dt);
|
|
4387
|
+
};
|
|
4388
|
+
ThrottleOperator.prototype._e = function (err) {
|
|
4389
|
+
var u = this.out;
|
|
4390
|
+
if (!u)
|
|
4391
|
+
return;
|
|
4392
|
+
this.clearInterval();
|
|
4393
|
+
u._e(err);
|
|
4394
|
+
};
|
|
4395
|
+
ThrottleOperator.prototype._c = function () {
|
|
4396
|
+
var u = this.out;
|
|
4397
|
+
if (!u)
|
|
4398
|
+
return;
|
|
4399
|
+
this.clearInterval();
|
|
4400
|
+
u._c();
|
|
4401
|
+
};
|
|
4402
|
+
return ThrottleOperator;
|
|
4403
|
+
}());
|
|
4404
|
+
/**
|
|
4405
|
+
* Emits event and drops subsequent events until a certain amount of silence has passed.
|
|
4406
|
+
*
|
|
4407
|
+
* Marble diagram:
|
|
4408
|
+
*
|
|
4409
|
+
* ```text
|
|
4410
|
+
* --1-2-----3--4----5|
|
|
4411
|
+
* throttle(60)
|
|
4412
|
+
* --1-------3-------5-|
|
|
4413
|
+
* ```
|
|
4414
|
+
*
|
|
4415
|
+
* Example:
|
|
4416
|
+
*
|
|
4417
|
+
* ```js
|
|
4418
|
+
* import fromDiagram from 'xstream/extra/fromDiagram'
|
|
4419
|
+
* import throttle from 'xstream/extra/throttle'
|
|
4420
|
+
*
|
|
4421
|
+
* const stream = fromDiagram('--1-2-----3--4----5|')
|
|
4422
|
+
* .compose(throttle(60))
|
|
4423
|
+
*
|
|
4424
|
+
* stream.addListener({
|
|
4425
|
+
* next: i => console.log(i),
|
|
4426
|
+
* error: err => console.error(err),
|
|
4427
|
+
* complete: () => console.log('completed')
|
|
4428
|
+
* })
|
|
4429
|
+
* ```
|
|
4430
|
+
*
|
|
4431
|
+
* ```text
|
|
4432
|
+
* > 1
|
|
4433
|
+
* > 3
|
|
4434
|
+
* > 5
|
|
4435
|
+
* > completed
|
|
4436
|
+
* ```
|
|
4437
|
+
*
|
|
4438
|
+
* @param {number} period The amount of silence required in milliseconds.
|
|
4439
|
+
* @return {Stream}
|
|
4440
|
+
*/
|
|
4441
|
+
function throttle(period) {
|
|
4442
|
+
return function throttleOperator(ins) {
|
|
4443
|
+
return new index_1$1.Stream(new ThrottleOperator(period, ins));
|
|
4444
|
+
};
|
|
4445
|
+
}
|
|
4446
|
+
var _default$1 = throttle$1.default = throttle;
|
|
4447
|
+
|
|
4448
|
+
var sampleCombine$1 = {};
|
|
4449
|
+
|
|
4450
|
+
var __spreadArrays = (commonjsGlobal && commonjsGlobal.__spreadArrays) || function () {
|
|
4451
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
4452
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
4453
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
4454
|
+
r[k] = a[j];
|
|
4455
|
+
return r;
|
|
4456
|
+
};
|
|
4457
|
+
Object.defineProperty(sampleCombine$1, "__esModule", { value: true });
|
|
4458
|
+
sampleCombine$1.SampleCombineOperator = sampleCombine$1.SampleCombineListener = void 0;
|
|
4459
|
+
var index_1 = xstream;
|
|
4460
|
+
var NO = {};
|
|
4461
|
+
var SampleCombineListener = /** @class */ (function () {
|
|
4462
|
+
function SampleCombineListener(i, p) {
|
|
4463
|
+
this.i = i;
|
|
4464
|
+
this.p = p;
|
|
4465
|
+
p.ils[i] = this;
|
|
4466
|
+
}
|
|
4467
|
+
SampleCombineListener.prototype._n = function (t) {
|
|
4468
|
+
var p = this.p;
|
|
4469
|
+
if (p.out === NO)
|
|
4470
|
+
return;
|
|
4471
|
+
p.up(t, this.i);
|
|
4472
|
+
};
|
|
4473
|
+
SampleCombineListener.prototype._e = function (err) {
|
|
4474
|
+
this.p._e(err);
|
|
4475
|
+
};
|
|
4476
|
+
SampleCombineListener.prototype._c = function () {
|
|
4477
|
+
this.p.down(this.i, this);
|
|
4478
|
+
};
|
|
4479
|
+
return SampleCombineListener;
|
|
4480
|
+
}());
|
|
4481
|
+
sampleCombine$1.SampleCombineListener = SampleCombineListener;
|
|
4482
|
+
var SampleCombineOperator = /** @class */ (function () {
|
|
4483
|
+
function SampleCombineOperator(ins, streams) {
|
|
4484
|
+
this.type = 'sampleCombine';
|
|
4485
|
+
this.ins = ins;
|
|
4486
|
+
this.others = streams;
|
|
4487
|
+
this.out = NO;
|
|
4488
|
+
this.ils = [];
|
|
4489
|
+
this.Nn = 0;
|
|
4490
|
+
this.vals = [];
|
|
4491
|
+
}
|
|
4492
|
+
SampleCombineOperator.prototype._start = function (out) {
|
|
4493
|
+
this.out = out;
|
|
4494
|
+
var s = this.others;
|
|
4495
|
+
var n = this.Nn = s.length;
|
|
4496
|
+
var vals = this.vals = new Array(n);
|
|
4497
|
+
for (var i = 0; i < n; i++) {
|
|
4498
|
+
vals[i] = NO;
|
|
4499
|
+
s[i]._add(new SampleCombineListener(i, this));
|
|
4500
|
+
}
|
|
4501
|
+
this.ins._add(this);
|
|
4502
|
+
};
|
|
4503
|
+
SampleCombineOperator.prototype._stop = function () {
|
|
4504
|
+
var s = this.others;
|
|
4505
|
+
var n = s.length;
|
|
4506
|
+
var ils = this.ils;
|
|
4507
|
+
this.ins._remove(this);
|
|
4508
|
+
for (var i = 0; i < n; i++) {
|
|
4509
|
+
s[i]._remove(ils[i]);
|
|
4510
|
+
}
|
|
4511
|
+
this.out = NO;
|
|
4512
|
+
this.vals = [];
|
|
4513
|
+
this.ils = [];
|
|
4514
|
+
};
|
|
4515
|
+
SampleCombineOperator.prototype._n = function (t) {
|
|
4516
|
+
var out = this.out;
|
|
4517
|
+
if (out === NO)
|
|
4518
|
+
return;
|
|
4519
|
+
if (this.Nn > 0)
|
|
4520
|
+
return;
|
|
4521
|
+
out._n(__spreadArrays([t], this.vals));
|
|
4522
|
+
};
|
|
4523
|
+
SampleCombineOperator.prototype._e = function (err) {
|
|
4524
|
+
var out = this.out;
|
|
4525
|
+
if (out === NO)
|
|
4526
|
+
return;
|
|
4527
|
+
out._e(err);
|
|
4528
|
+
};
|
|
4529
|
+
SampleCombineOperator.prototype._c = function () {
|
|
4530
|
+
var out = this.out;
|
|
4531
|
+
if (out === NO)
|
|
4532
|
+
return;
|
|
4533
|
+
out._c();
|
|
4534
|
+
};
|
|
4535
|
+
SampleCombineOperator.prototype.up = function (t, i) {
|
|
4536
|
+
var v = this.vals[i];
|
|
4537
|
+
if (this.Nn > 0 && v === NO) {
|
|
4538
|
+
this.Nn--;
|
|
4539
|
+
}
|
|
4540
|
+
this.vals[i] = t;
|
|
4541
|
+
};
|
|
4542
|
+
SampleCombineOperator.prototype.down = function (i, l) {
|
|
4543
|
+
this.others[i]._remove(l);
|
|
4544
|
+
};
|
|
4545
|
+
return SampleCombineOperator;
|
|
4546
|
+
}());
|
|
4547
|
+
sampleCombine$1.SampleCombineOperator = SampleCombineOperator;
|
|
4548
|
+
var sampleCombine;
|
|
4549
|
+
/**
|
|
4550
|
+
*
|
|
4551
|
+
* Combines a source stream with multiple other streams. The result stream
|
|
4552
|
+
* will emit the latest events from all input streams, but only when the
|
|
4553
|
+
* source stream emits.
|
|
4554
|
+
*
|
|
4555
|
+
* If the source, or any input stream, throws an error, the result stream
|
|
4556
|
+
* will propagate the error. If any input streams end, their final emitted
|
|
4557
|
+
* value will remain in the array of any subsequent events from the result
|
|
4558
|
+
* stream.
|
|
4559
|
+
*
|
|
4560
|
+
* The result stream will only complete upon completion of the source stream.
|
|
4561
|
+
*
|
|
4562
|
+
* Marble diagram:
|
|
4563
|
+
*
|
|
4564
|
+
* ```text
|
|
4565
|
+
* --1----2-----3--------4--- (source)
|
|
4566
|
+
* ----a-----b-----c--d------ (other)
|
|
4567
|
+
* sampleCombine
|
|
4568
|
+
* -------2a----3b-------4d--
|
|
4569
|
+
* ```
|
|
4570
|
+
*
|
|
4571
|
+
* Examples:
|
|
4572
|
+
*
|
|
4573
|
+
* ```js
|
|
4574
|
+
* import sampleCombine from 'xstream/extra/sampleCombine'
|
|
4575
|
+
* import xs from 'xstream'
|
|
4576
|
+
*
|
|
4577
|
+
* const sampler = xs.periodic(1000).take(3)
|
|
4578
|
+
* const other = xs.periodic(100)
|
|
4579
|
+
*
|
|
4580
|
+
* const stream = sampler.compose(sampleCombine(other))
|
|
4581
|
+
*
|
|
4582
|
+
* stream.addListener({
|
|
4583
|
+
* next: i => console.log(i),
|
|
4584
|
+
* error: err => console.error(err),
|
|
4585
|
+
* complete: () => console.log('completed')
|
|
4586
|
+
* })
|
|
4587
|
+
* ```
|
|
4588
|
+
*
|
|
4589
|
+
* ```text
|
|
4590
|
+
* > [0, 8]
|
|
4591
|
+
* > [1, 18]
|
|
4592
|
+
* > [2, 28]
|
|
4593
|
+
* ```
|
|
4594
|
+
*
|
|
4595
|
+
* ```js
|
|
4596
|
+
* import sampleCombine from 'xstream/extra/sampleCombine'
|
|
4597
|
+
* import xs from 'xstream'
|
|
4598
|
+
*
|
|
4599
|
+
* const sampler = xs.periodic(1000).take(3)
|
|
4600
|
+
* const other = xs.periodic(100).take(2)
|
|
4601
|
+
*
|
|
4602
|
+
* const stream = sampler.compose(sampleCombine(other))
|
|
4603
|
+
*
|
|
4604
|
+
* stream.addListener({
|
|
4605
|
+
* next: i => console.log(i),
|
|
4606
|
+
* error: err => console.error(err),
|
|
4607
|
+
* complete: () => console.log('completed')
|
|
4608
|
+
* })
|
|
4609
|
+
* ```
|
|
4610
|
+
*
|
|
4611
|
+
* ```text
|
|
4612
|
+
* > [0, 1]
|
|
4613
|
+
* > [1, 1]
|
|
4614
|
+
* > [2, 1]
|
|
4615
|
+
* ```
|
|
4616
|
+
*
|
|
4617
|
+
* @param {...Stream} streams One or more streams to combine with the sampler
|
|
4618
|
+
* stream.
|
|
4619
|
+
* @return {Stream}
|
|
4620
|
+
*/
|
|
4621
|
+
sampleCombine = function sampleCombine() {
|
|
4622
|
+
var streams = [];
|
|
4623
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
4624
|
+
streams[_i] = arguments[_i];
|
|
4625
|
+
}
|
|
4626
|
+
return function sampleCombineOperator(sampler) {
|
|
4627
|
+
return new index_1.Stream(new SampleCombineOperator(sampler, streams));
|
|
4628
|
+
};
|
|
4629
|
+
};
|
|
4630
|
+
var _default = sampleCombine$1.default = sampleCombine;
|
|
4631
|
+
|
|
4632
|
+
export { ABORT, classes, collection, component, _default$2 as debounce, _default$4 as delay, _default$5 as dropRepeats, processForm, run, _default as sampleCombine, switchable, _default$1 as throttle };
|