sygnal 2.5.0 → 2.6.1

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