sygnal 4.5.0 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/astro/client.cjs.js +3684 -103
- package/dist/astro/client.mjs +3683 -80
- package/dist/index.cjs.js +908 -40
- package/dist/index.d.ts +522 -19
- package/dist/index.esm.js +901 -41
- package/dist/jsx-dev-runtime.cjs.js +43 -4
- package/dist/jsx-dev-runtime.esm.js +43 -4
- package/dist/jsx-runtime.cjs.js +43 -4
- package/dist/jsx-runtime.esm.js +43 -4
- package/dist/jsx.cjs.js +43 -4
- package/dist/jsx.esm.js +43 -4
- package/dist/sygnal.min.js +1 -1
- package/package.json +2 -2
- package/src/astro/client.ts +2 -0
- package/src/component.ts +453 -34
- package/src/cycle/dom/DocumentDOMSource.ts +31 -4
- package/src/cycle/state/Collection.ts +7 -1
- package/src/extra/ref.ts +39 -0
- package/src/extra/run.ts +2 -0
- package/src/index.d.ts +32 -1
- package/src/index.ts +6 -0
- package/src/lazy.ts +48 -0
- package/src/portal.ts +11 -0
- package/src/pragma/index.ts +41 -4
- package/src/suspense.ts +11 -0
- package/src/transition.ts +11 -0
package/dist/astro/client.cjs.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var xs$1 = require('xstream');
|
|
4
|
-
var dropRepeats$2 = require('xstream/extra/dropRepeats');
|
|
5
|
-
var concat$1 = require('xstream/extra/concat');
|
|
6
3
|
var h = require('snabbdom/build/h');
|
|
7
4
|
var init = require('snabbdom/build/init');
|
|
8
5
|
var tovnode = require('snabbdom/build/tovnode');
|
|
@@ -12,35 +9,2601 @@ var _class = require('snabbdom/build/modules/class');
|
|
|
12
9
|
var props = require('snabbdom/build/modules/props');
|
|
13
10
|
var attributes = require('snabbdom/build/modules/attributes');
|
|
14
11
|
var dataset = require('snabbdom/build/modules/dataset');
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
12
|
+
|
|
13
|
+
function _mergeNamespaces(n, m) {
|
|
14
|
+
m.forEach(function (e) {
|
|
15
|
+
e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
|
|
16
|
+
if (k !== 'default' && !(k in n)) {
|
|
17
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
18
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () { return e[k]; }
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
29
|
+
|
|
30
|
+
var xstream = {};
|
|
31
|
+
|
|
32
|
+
var ponyfill$1 = {};
|
|
33
|
+
|
|
34
|
+
(function (exports) {
|
|
35
|
+
|
|
36
|
+
Object.defineProperty(exports, "__esModule", {
|
|
37
|
+
value: true
|
|
38
|
+
});
|
|
39
|
+
exports['default'] = symbolObservablePonyfill;
|
|
40
|
+
function symbolObservablePonyfill(root) {
|
|
41
|
+
var result;
|
|
42
|
+
var _Symbol = root.Symbol;
|
|
43
|
+
|
|
44
|
+
if (typeof _Symbol === 'function') {
|
|
45
|
+
if (_Symbol.observable) {
|
|
46
|
+
result = _Symbol.observable;
|
|
47
|
+
} else {
|
|
48
|
+
|
|
49
|
+
// This just needs to be something that won't trample other user's Symbol.for use
|
|
50
|
+
// It also will guide people to the source of their issues, if this is problematic.
|
|
51
|
+
// META: It's a resource locator!
|
|
52
|
+
result = _Symbol['for']('https://github.com/benlesh/symbol-observable');
|
|
53
|
+
try {
|
|
54
|
+
_Symbol.observable = result;
|
|
55
|
+
} catch (err) {
|
|
56
|
+
// Do nothing. In some environments, users have frozen `Symbol` for security reasons,
|
|
57
|
+
// if it is frozen assigning to it will throw. In this case, we don't care, because
|
|
58
|
+
// they will need to use the returned value from the ponyfill.
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
result = '@@observable';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return result;
|
|
66
|
+
}} (ponyfill$1));
|
|
67
|
+
|
|
68
|
+
var ponyfill = ponyfill$1;
|
|
69
|
+
|
|
70
|
+
var toStr$2 = Object.prototype.toString;
|
|
71
|
+
|
|
72
|
+
var isArguments = function isArguments(value) {
|
|
73
|
+
var str = toStr$2.call(value);
|
|
74
|
+
var isArgs = str === '[object Arguments]';
|
|
75
|
+
if (!isArgs) {
|
|
76
|
+
isArgs = str !== '[object Array]' &&
|
|
77
|
+
value !== null &&
|
|
78
|
+
typeof value === 'object' &&
|
|
79
|
+
typeof value.length === 'number' &&
|
|
80
|
+
value.length >= 0 &&
|
|
81
|
+
toStr$2.call(value.callee) === '[object Function]';
|
|
82
|
+
}
|
|
83
|
+
return isArgs;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
var implementation$5;
|
|
87
|
+
var hasRequiredImplementation;
|
|
88
|
+
|
|
89
|
+
function requireImplementation () {
|
|
90
|
+
if (hasRequiredImplementation) return implementation$5;
|
|
91
|
+
hasRequiredImplementation = 1;
|
|
92
|
+
|
|
93
|
+
var keysShim;
|
|
94
|
+
if (!Object.keys) {
|
|
95
|
+
// modified from https://github.com/es-shims/es5-shim
|
|
96
|
+
var has = Object.prototype.hasOwnProperty;
|
|
97
|
+
var toStr = Object.prototype.toString;
|
|
98
|
+
var isArgs = isArguments; // eslint-disable-line global-require
|
|
99
|
+
var isEnumerable = Object.prototype.propertyIsEnumerable;
|
|
100
|
+
var hasDontEnumBug = !isEnumerable.call({ toString: null }, 'toString');
|
|
101
|
+
var hasProtoEnumBug = isEnumerable.call(function () {}, 'prototype');
|
|
102
|
+
var dontEnums = [
|
|
103
|
+
'toString',
|
|
104
|
+
'toLocaleString',
|
|
105
|
+
'valueOf',
|
|
106
|
+
'hasOwnProperty',
|
|
107
|
+
'isPrototypeOf',
|
|
108
|
+
'propertyIsEnumerable',
|
|
109
|
+
'constructor'
|
|
110
|
+
];
|
|
111
|
+
var equalsConstructorPrototype = function (o) {
|
|
112
|
+
var ctor = o.constructor;
|
|
113
|
+
return ctor && ctor.prototype === o;
|
|
114
|
+
};
|
|
115
|
+
var excludedKeys = {
|
|
116
|
+
$applicationCache: true,
|
|
117
|
+
$console: true,
|
|
118
|
+
$external: true,
|
|
119
|
+
$frame: true,
|
|
120
|
+
$frameElement: true,
|
|
121
|
+
$frames: true,
|
|
122
|
+
$innerHeight: true,
|
|
123
|
+
$innerWidth: true,
|
|
124
|
+
$onmozfullscreenchange: true,
|
|
125
|
+
$onmozfullscreenerror: true,
|
|
126
|
+
$outerHeight: true,
|
|
127
|
+
$outerWidth: true,
|
|
128
|
+
$pageXOffset: true,
|
|
129
|
+
$pageYOffset: true,
|
|
130
|
+
$parent: true,
|
|
131
|
+
$scrollLeft: true,
|
|
132
|
+
$scrollTop: true,
|
|
133
|
+
$scrollX: true,
|
|
134
|
+
$scrollY: true,
|
|
135
|
+
$self: true,
|
|
136
|
+
$webkitIndexedDB: true,
|
|
137
|
+
$webkitStorageInfo: true,
|
|
138
|
+
$window: true
|
|
139
|
+
};
|
|
140
|
+
var hasAutomationEqualityBug = (function () {
|
|
141
|
+
/* global window */
|
|
142
|
+
if (typeof window === 'undefined') { return false; }
|
|
143
|
+
for (var k in window) {
|
|
144
|
+
try {
|
|
145
|
+
if (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') {
|
|
146
|
+
try {
|
|
147
|
+
equalsConstructorPrototype(window[k]);
|
|
148
|
+
} catch (e) {
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
} catch (e) {
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return false;
|
|
157
|
+
}());
|
|
158
|
+
var equalsConstructorPrototypeIfNotBuggy = function (o) {
|
|
159
|
+
/* global window */
|
|
160
|
+
if (typeof window === 'undefined' || !hasAutomationEqualityBug) {
|
|
161
|
+
return equalsConstructorPrototype(o);
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
return equalsConstructorPrototype(o);
|
|
165
|
+
} catch (e) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
keysShim = function keys(object) {
|
|
171
|
+
var isObject = object !== null && typeof object === 'object';
|
|
172
|
+
var isFunction = toStr.call(object) === '[object Function]';
|
|
173
|
+
var isArguments = isArgs(object);
|
|
174
|
+
var isString = isObject && toStr.call(object) === '[object String]';
|
|
175
|
+
var theKeys = [];
|
|
176
|
+
|
|
177
|
+
if (!isObject && !isFunction && !isArguments) {
|
|
178
|
+
throw new TypeError('Object.keys called on a non-object');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
var skipProto = hasProtoEnumBug && isFunction;
|
|
182
|
+
if (isString && object.length > 0 && !has.call(object, 0)) {
|
|
183
|
+
for (var i = 0; i < object.length; ++i) {
|
|
184
|
+
theKeys.push(String(i));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (isArguments && object.length > 0) {
|
|
189
|
+
for (var j = 0; j < object.length; ++j) {
|
|
190
|
+
theKeys.push(String(j));
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
for (var name in object) {
|
|
194
|
+
if (!(skipProto && name === 'prototype') && has.call(object, name)) {
|
|
195
|
+
theKeys.push(String(name));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (hasDontEnumBug) {
|
|
201
|
+
var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
|
|
202
|
+
|
|
203
|
+
for (var k = 0; k < dontEnums.length; ++k) {
|
|
204
|
+
if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) {
|
|
205
|
+
theKeys.push(dontEnums[k]);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return theKeys;
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
implementation$5 = keysShim;
|
|
213
|
+
return implementation$5;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
var slice$1 = Array.prototype.slice;
|
|
217
|
+
var isArgs = isArguments;
|
|
218
|
+
|
|
219
|
+
var origKeys = Object.keys;
|
|
220
|
+
var keysShim = origKeys ? function keys(o) { return origKeys(o); } : requireImplementation();
|
|
221
|
+
|
|
222
|
+
var originalKeys = Object.keys;
|
|
223
|
+
|
|
224
|
+
keysShim.shim = function shimObjectKeys() {
|
|
225
|
+
if (Object.keys) {
|
|
226
|
+
var keysWorksWithArguments = (function () {
|
|
227
|
+
// Safari 5.0 bug
|
|
228
|
+
var args = Object.keys(arguments);
|
|
229
|
+
return args && args.length === arguments.length;
|
|
230
|
+
}(1, 2));
|
|
231
|
+
if (!keysWorksWithArguments) {
|
|
232
|
+
Object.keys = function keys(object) { // eslint-disable-line func-name-matching
|
|
233
|
+
if (isArgs(object)) {
|
|
234
|
+
return originalKeys(slice$1.call(object));
|
|
235
|
+
}
|
|
236
|
+
return originalKeys(object);
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
} else {
|
|
240
|
+
Object.keys = keysShim;
|
|
241
|
+
}
|
|
242
|
+
return Object.keys || keysShim;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
var objectKeys = keysShim;
|
|
246
|
+
|
|
247
|
+
/* eslint complexity: [2, 18], max-statements: [2, 33] */
|
|
248
|
+
var shams = function hasSymbols() {
|
|
249
|
+
if (typeof Symbol !== 'function' || typeof Object.getOwnPropertySymbols !== 'function') { return false; }
|
|
250
|
+
if (typeof Symbol.iterator === 'symbol') { return true; }
|
|
251
|
+
|
|
252
|
+
var obj = {};
|
|
253
|
+
var sym = Symbol('test');
|
|
254
|
+
var symObj = Object(sym);
|
|
255
|
+
if (typeof sym === 'string') { return false; }
|
|
256
|
+
|
|
257
|
+
if (Object.prototype.toString.call(sym) !== '[object Symbol]') { return false; }
|
|
258
|
+
if (Object.prototype.toString.call(symObj) !== '[object Symbol]') { return false; }
|
|
259
|
+
|
|
260
|
+
// temp disabled per https://github.com/ljharb/object.assign/issues/17
|
|
261
|
+
// if (sym instanceof Symbol) { return false; }
|
|
262
|
+
// temp disabled per https://github.com/WebReflection/get-own-property-symbols/issues/4
|
|
263
|
+
// if (!(symObj instanceof Symbol)) { return false; }
|
|
264
|
+
|
|
265
|
+
// if (typeof Symbol.prototype.toString !== 'function') { return false; }
|
|
266
|
+
// if (String(sym) !== Symbol.prototype.toString.call(sym)) { return false; }
|
|
267
|
+
|
|
268
|
+
var symVal = 42;
|
|
269
|
+
obj[sym] = symVal;
|
|
270
|
+
for (sym in obj) { return false; } // eslint-disable-line no-restricted-syntax, no-unreachable-loop
|
|
271
|
+
if (typeof Object.keys === 'function' && Object.keys(obj).length !== 0) { return false; }
|
|
272
|
+
|
|
273
|
+
if (typeof Object.getOwnPropertyNames === 'function' && Object.getOwnPropertyNames(obj).length !== 0) { return false; }
|
|
274
|
+
|
|
275
|
+
var syms = Object.getOwnPropertySymbols(obj);
|
|
276
|
+
if (syms.length !== 1 || syms[0] !== sym) { return false; }
|
|
277
|
+
|
|
278
|
+
if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) { return false; }
|
|
279
|
+
|
|
280
|
+
if (typeof Object.getOwnPropertyDescriptor === 'function') {
|
|
281
|
+
var descriptor = Object.getOwnPropertyDescriptor(obj, sym);
|
|
282
|
+
if (descriptor.value !== symVal || descriptor.enumerable !== true) { return false; }
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return true;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
var origSymbol = typeof Symbol !== 'undefined' && Symbol;
|
|
289
|
+
var hasSymbolSham = shams;
|
|
290
|
+
|
|
291
|
+
var hasSymbols$2 = function hasNativeSymbols() {
|
|
292
|
+
if (typeof origSymbol !== 'function') { return false; }
|
|
293
|
+
if (typeof Symbol !== 'function') { return false; }
|
|
294
|
+
if (typeof origSymbol('foo') !== 'symbol') { return false; }
|
|
295
|
+
if (typeof Symbol('bar') !== 'symbol') { return false; }
|
|
296
|
+
|
|
297
|
+
return hasSymbolSham();
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
var test = {
|
|
301
|
+
foo: {}
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
var $Object = Object;
|
|
305
|
+
|
|
306
|
+
var hasProto$1 = function hasProto() {
|
|
307
|
+
return { __proto__: test }.foo === test.foo && !({ __proto__: null } instanceof $Object);
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
/* eslint no-invalid-this: 1 */
|
|
311
|
+
|
|
312
|
+
var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible ';
|
|
313
|
+
var slice = Array.prototype.slice;
|
|
314
|
+
var toStr$1 = Object.prototype.toString;
|
|
315
|
+
var funcType = '[object Function]';
|
|
316
|
+
|
|
317
|
+
var implementation$4 = function bind(that) {
|
|
318
|
+
var target = this;
|
|
319
|
+
if (typeof target !== 'function' || toStr$1.call(target) !== funcType) {
|
|
320
|
+
throw new TypeError(ERROR_MESSAGE + target);
|
|
321
|
+
}
|
|
322
|
+
var args = slice.call(arguments, 1);
|
|
323
|
+
|
|
324
|
+
var bound;
|
|
325
|
+
var binder = function () {
|
|
326
|
+
if (this instanceof bound) {
|
|
327
|
+
var result = target.apply(
|
|
328
|
+
this,
|
|
329
|
+
args.concat(slice.call(arguments))
|
|
330
|
+
);
|
|
331
|
+
if (Object(result) === result) {
|
|
332
|
+
return result;
|
|
333
|
+
}
|
|
334
|
+
return this;
|
|
335
|
+
} else {
|
|
336
|
+
return target.apply(
|
|
337
|
+
that,
|
|
338
|
+
args.concat(slice.call(arguments))
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
var boundLength = Math.max(0, target.length - args.length);
|
|
344
|
+
var boundArgs = [];
|
|
345
|
+
for (var i = 0; i < boundLength; i++) {
|
|
346
|
+
boundArgs.push('$' + i);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this,arguments); }')(binder);
|
|
350
|
+
|
|
351
|
+
if (target.prototype) {
|
|
352
|
+
var Empty = function Empty() {};
|
|
353
|
+
Empty.prototype = target.prototype;
|
|
354
|
+
bound.prototype = new Empty();
|
|
355
|
+
Empty.prototype = null;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
return bound;
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
var implementation$3 = implementation$4;
|
|
362
|
+
|
|
363
|
+
var functionBind = Function.prototype.bind || implementation$3;
|
|
364
|
+
|
|
365
|
+
var bind$1 = functionBind;
|
|
366
|
+
|
|
367
|
+
var src = bind$1.call(Function.call, Object.prototype.hasOwnProperty);
|
|
368
|
+
|
|
369
|
+
var undefined$1;
|
|
370
|
+
|
|
371
|
+
var $SyntaxError = SyntaxError;
|
|
372
|
+
var $Function = Function;
|
|
373
|
+
var $TypeError = TypeError;
|
|
374
|
+
|
|
375
|
+
// eslint-disable-next-line consistent-return
|
|
376
|
+
var getEvalledConstructor = function (expressionSyntax) {
|
|
377
|
+
try {
|
|
378
|
+
return $Function('"use strict"; return (' + expressionSyntax + ').constructor;')();
|
|
379
|
+
} catch (e) {}
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
var $gOPD = Object.getOwnPropertyDescriptor;
|
|
383
|
+
if ($gOPD) {
|
|
384
|
+
try {
|
|
385
|
+
$gOPD({}, '');
|
|
386
|
+
} catch (e) {
|
|
387
|
+
$gOPD = null; // this is IE 8, which has a broken gOPD
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
var throwTypeError = function () {
|
|
392
|
+
throw new $TypeError();
|
|
393
|
+
};
|
|
394
|
+
var ThrowTypeError = $gOPD
|
|
395
|
+
? (function () {
|
|
396
|
+
try {
|
|
397
|
+
// eslint-disable-next-line no-unused-expressions, no-caller, no-restricted-properties
|
|
398
|
+
arguments.callee; // IE 8 does not throw here
|
|
399
|
+
return throwTypeError;
|
|
400
|
+
} catch (calleeThrows) {
|
|
401
|
+
try {
|
|
402
|
+
// IE 8 throws on Object.getOwnPropertyDescriptor(arguments, '')
|
|
403
|
+
return $gOPD(arguments, 'callee').get;
|
|
404
|
+
} catch (gOPDthrows) {
|
|
405
|
+
return throwTypeError;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}())
|
|
409
|
+
: throwTypeError;
|
|
410
|
+
|
|
411
|
+
var hasSymbols$1 = hasSymbols$2();
|
|
412
|
+
var hasProto = hasProto$1();
|
|
413
|
+
|
|
414
|
+
var getProto = Object.getPrototypeOf || (
|
|
415
|
+
hasProto
|
|
416
|
+
? function (x) { return x.__proto__; } // eslint-disable-line no-proto
|
|
417
|
+
: null
|
|
418
|
+
);
|
|
419
|
+
|
|
420
|
+
var needsEval = {};
|
|
421
|
+
|
|
422
|
+
var TypedArray = typeof Uint8Array === 'undefined' || !getProto ? undefined$1 : getProto(Uint8Array);
|
|
423
|
+
|
|
424
|
+
var INTRINSICS = {
|
|
425
|
+
'%AggregateError%': typeof AggregateError === 'undefined' ? undefined$1 : AggregateError,
|
|
426
|
+
'%Array%': Array,
|
|
427
|
+
'%ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined$1 : ArrayBuffer,
|
|
428
|
+
'%ArrayIteratorPrototype%': hasSymbols$1 && getProto ? getProto([][Symbol.iterator]()) : undefined$1,
|
|
429
|
+
'%AsyncFromSyncIteratorPrototype%': undefined$1,
|
|
430
|
+
'%AsyncFunction%': needsEval,
|
|
431
|
+
'%AsyncGenerator%': needsEval,
|
|
432
|
+
'%AsyncGeneratorFunction%': needsEval,
|
|
433
|
+
'%AsyncIteratorPrototype%': needsEval,
|
|
434
|
+
'%Atomics%': typeof Atomics === 'undefined' ? undefined$1 : Atomics,
|
|
435
|
+
'%BigInt%': typeof BigInt === 'undefined' ? undefined$1 : BigInt,
|
|
436
|
+
'%BigInt64Array%': typeof BigInt64Array === 'undefined' ? undefined$1 : BigInt64Array,
|
|
437
|
+
'%BigUint64Array%': typeof BigUint64Array === 'undefined' ? undefined$1 : BigUint64Array,
|
|
438
|
+
'%Boolean%': Boolean,
|
|
439
|
+
'%DataView%': typeof DataView === 'undefined' ? undefined$1 : DataView,
|
|
440
|
+
'%Date%': Date,
|
|
441
|
+
'%decodeURI%': decodeURI,
|
|
442
|
+
'%decodeURIComponent%': decodeURIComponent,
|
|
443
|
+
'%encodeURI%': encodeURI,
|
|
444
|
+
'%encodeURIComponent%': encodeURIComponent,
|
|
445
|
+
'%Error%': Error,
|
|
446
|
+
'%eval%': eval, // eslint-disable-line no-eval
|
|
447
|
+
'%EvalError%': EvalError,
|
|
448
|
+
'%Float32Array%': typeof Float32Array === 'undefined' ? undefined$1 : Float32Array,
|
|
449
|
+
'%Float64Array%': typeof Float64Array === 'undefined' ? undefined$1 : Float64Array,
|
|
450
|
+
'%FinalizationRegistry%': typeof FinalizationRegistry === 'undefined' ? undefined$1 : FinalizationRegistry,
|
|
451
|
+
'%Function%': $Function,
|
|
452
|
+
'%GeneratorFunction%': needsEval,
|
|
453
|
+
'%Int8Array%': typeof Int8Array === 'undefined' ? undefined$1 : Int8Array,
|
|
454
|
+
'%Int16Array%': typeof Int16Array === 'undefined' ? undefined$1 : Int16Array,
|
|
455
|
+
'%Int32Array%': typeof Int32Array === 'undefined' ? undefined$1 : Int32Array,
|
|
456
|
+
'%isFinite%': isFinite,
|
|
457
|
+
'%isNaN%': isNaN,
|
|
458
|
+
'%IteratorPrototype%': hasSymbols$1 && getProto ? getProto(getProto([][Symbol.iterator]())) : undefined$1,
|
|
459
|
+
'%JSON%': typeof JSON === 'object' ? JSON : undefined$1,
|
|
460
|
+
'%Map%': typeof Map === 'undefined' ? undefined$1 : Map,
|
|
461
|
+
'%MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols$1 || !getProto ? undefined$1 : getProto(new Map()[Symbol.iterator]()),
|
|
462
|
+
'%Math%': Math,
|
|
463
|
+
'%Number%': Number,
|
|
464
|
+
'%Object%': Object,
|
|
465
|
+
'%parseFloat%': parseFloat,
|
|
466
|
+
'%parseInt%': parseInt,
|
|
467
|
+
'%Promise%': typeof Promise === 'undefined' ? undefined$1 : Promise,
|
|
468
|
+
'%Proxy%': typeof Proxy === 'undefined' ? undefined$1 : Proxy,
|
|
469
|
+
'%RangeError%': RangeError,
|
|
470
|
+
'%ReferenceError%': ReferenceError,
|
|
471
|
+
'%Reflect%': typeof Reflect === 'undefined' ? undefined$1 : Reflect,
|
|
472
|
+
'%RegExp%': RegExp,
|
|
473
|
+
'%Set%': typeof Set === 'undefined' ? undefined$1 : Set,
|
|
474
|
+
'%SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols$1 || !getProto ? undefined$1 : getProto(new Set()[Symbol.iterator]()),
|
|
475
|
+
'%SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined$1 : SharedArrayBuffer,
|
|
476
|
+
'%String%': String,
|
|
477
|
+
'%StringIteratorPrototype%': hasSymbols$1 && getProto ? getProto(''[Symbol.iterator]()) : undefined$1,
|
|
478
|
+
'%Symbol%': hasSymbols$1 ? Symbol : undefined$1,
|
|
479
|
+
'%SyntaxError%': $SyntaxError,
|
|
480
|
+
'%ThrowTypeError%': ThrowTypeError,
|
|
481
|
+
'%TypedArray%': TypedArray,
|
|
482
|
+
'%TypeError%': $TypeError,
|
|
483
|
+
'%Uint8Array%': typeof Uint8Array === 'undefined' ? undefined$1 : Uint8Array,
|
|
484
|
+
'%Uint8ClampedArray%': typeof Uint8ClampedArray === 'undefined' ? undefined$1 : Uint8ClampedArray,
|
|
485
|
+
'%Uint16Array%': typeof Uint16Array === 'undefined' ? undefined$1 : Uint16Array,
|
|
486
|
+
'%Uint32Array%': typeof Uint32Array === 'undefined' ? undefined$1 : Uint32Array,
|
|
487
|
+
'%URIError%': URIError,
|
|
488
|
+
'%WeakMap%': typeof WeakMap === 'undefined' ? undefined$1 : WeakMap,
|
|
489
|
+
'%WeakRef%': typeof WeakRef === 'undefined' ? undefined$1 : WeakRef,
|
|
490
|
+
'%WeakSet%': typeof WeakSet === 'undefined' ? undefined$1 : WeakSet
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
if (getProto) {
|
|
494
|
+
try {
|
|
495
|
+
null.error; // eslint-disable-line no-unused-expressions
|
|
496
|
+
} catch (e) {
|
|
497
|
+
// https://github.com/tc39/proposal-shadowrealm/pull/384#issuecomment-1364264229
|
|
498
|
+
var errorProto = getProto(getProto(e));
|
|
499
|
+
INTRINSICS['%Error.prototype%'] = errorProto;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
var doEval = function doEval(name) {
|
|
504
|
+
var value;
|
|
505
|
+
if (name === '%AsyncFunction%') {
|
|
506
|
+
value = getEvalledConstructor('async function () {}');
|
|
507
|
+
} else if (name === '%GeneratorFunction%') {
|
|
508
|
+
value = getEvalledConstructor('function* () {}');
|
|
509
|
+
} else if (name === '%AsyncGeneratorFunction%') {
|
|
510
|
+
value = getEvalledConstructor('async function* () {}');
|
|
511
|
+
} else if (name === '%AsyncGenerator%') {
|
|
512
|
+
var fn = doEval('%AsyncGeneratorFunction%');
|
|
513
|
+
if (fn) {
|
|
514
|
+
value = fn.prototype;
|
|
515
|
+
}
|
|
516
|
+
} else if (name === '%AsyncIteratorPrototype%') {
|
|
517
|
+
var gen = doEval('%AsyncGenerator%');
|
|
518
|
+
if (gen && getProto) {
|
|
519
|
+
value = getProto(gen.prototype);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
INTRINSICS[name] = value;
|
|
524
|
+
|
|
525
|
+
return value;
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
var LEGACY_ALIASES = {
|
|
529
|
+
'%ArrayBufferPrototype%': ['ArrayBuffer', 'prototype'],
|
|
530
|
+
'%ArrayPrototype%': ['Array', 'prototype'],
|
|
531
|
+
'%ArrayProto_entries%': ['Array', 'prototype', 'entries'],
|
|
532
|
+
'%ArrayProto_forEach%': ['Array', 'prototype', 'forEach'],
|
|
533
|
+
'%ArrayProto_keys%': ['Array', 'prototype', 'keys'],
|
|
534
|
+
'%ArrayProto_values%': ['Array', 'prototype', 'values'],
|
|
535
|
+
'%AsyncFunctionPrototype%': ['AsyncFunction', 'prototype'],
|
|
536
|
+
'%AsyncGenerator%': ['AsyncGeneratorFunction', 'prototype'],
|
|
537
|
+
'%AsyncGeneratorPrototype%': ['AsyncGeneratorFunction', 'prototype', 'prototype'],
|
|
538
|
+
'%BooleanPrototype%': ['Boolean', 'prototype'],
|
|
539
|
+
'%DataViewPrototype%': ['DataView', 'prototype'],
|
|
540
|
+
'%DatePrototype%': ['Date', 'prototype'],
|
|
541
|
+
'%ErrorPrototype%': ['Error', 'prototype'],
|
|
542
|
+
'%EvalErrorPrototype%': ['EvalError', 'prototype'],
|
|
543
|
+
'%Float32ArrayPrototype%': ['Float32Array', 'prototype'],
|
|
544
|
+
'%Float64ArrayPrototype%': ['Float64Array', 'prototype'],
|
|
545
|
+
'%FunctionPrototype%': ['Function', 'prototype'],
|
|
546
|
+
'%Generator%': ['GeneratorFunction', 'prototype'],
|
|
547
|
+
'%GeneratorPrototype%': ['GeneratorFunction', 'prototype', 'prototype'],
|
|
548
|
+
'%Int8ArrayPrototype%': ['Int8Array', 'prototype'],
|
|
549
|
+
'%Int16ArrayPrototype%': ['Int16Array', 'prototype'],
|
|
550
|
+
'%Int32ArrayPrototype%': ['Int32Array', 'prototype'],
|
|
551
|
+
'%JSONParse%': ['JSON', 'parse'],
|
|
552
|
+
'%JSONStringify%': ['JSON', 'stringify'],
|
|
553
|
+
'%MapPrototype%': ['Map', 'prototype'],
|
|
554
|
+
'%NumberPrototype%': ['Number', 'prototype'],
|
|
555
|
+
'%ObjectPrototype%': ['Object', 'prototype'],
|
|
556
|
+
'%ObjProto_toString%': ['Object', 'prototype', 'toString'],
|
|
557
|
+
'%ObjProto_valueOf%': ['Object', 'prototype', 'valueOf'],
|
|
558
|
+
'%PromisePrototype%': ['Promise', 'prototype'],
|
|
559
|
+
'%PromiseProto_then%': ['Promise', 'prototype', 'then'],
|
|
560
|
+
'%Promise_all%': ['Promise', 'all'],
|
|
561
|
+
'%Promise_reject%': ['Promise', 'reject'],
|
|
562
|
+
'%Promise_resolve%': ['Promise', 'resolve'],
|
|
563
|
+
'%RangeErrorPrototype%': ['RangeError', 'prototype'],
|
|
564
|
+
'%ReferenceErrorPrototype%': ['ReferenceError', 'prototype'],
|
|
565
|
+
'%RegExpPrototype%': ['RegExp', 'prototype'],
|
|
566
|
+
'%SetPrototype%': ['Set', 'prototype'],
|
|
567
|
+
'%SharedArrayBufferPrototype%': ['SharedArrayBuffer', 'prototype'],
|
|
568
|
+
'%StringPrototype%': ['String', 'prototype'],
|
|
569
|
+
'%SymbolPrototype%': ['Symbol', 'prototype'],
|
|
570
|
+
'%SyntaxErrorPrototype%': ['SyntaxError', 'prototype'],
|
|
571
|
+
'%TypedArrayPrototype%': ['TypedArray', 'prototype'],
|
|
572
|
+
'%TypeErrorPrototype%': ['TypeError', 'prototype'],
|
|
573
|
+
'%Uint8ArrayPrototype%': ['Uint8Array', 'prototype'],
|
|
574
|
+
'%Uint8ClampedArrayPrototype%': ['Uint8ClampedArray', 'prototype'],
|
|
575
|
+
'%Uint16ArrayPrototype%': ['Uint16Array', 'prototype'],
|
|
576
|
+
'%Uint32ArrayPrototype%': ['Uint32Array', 'prototype'],
|
|
577
|
+
'%URIErrorPrototype%': ['URIError', 'prototype'],
|
|
578
|
+
'%WeakMapPrototype%': ['WeakMap', 'prototype'],
|
|
579
|
+
'%WeakSetPrototype%': ['WeakSet', 'prototype']
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
var bind = functionBind;
|
|
583
|
+
var hasOwn = src;
|
|
584
|
+
var $concat = bind.call(Function.call, Array.prototype.concat);
|
|
585
|
+
var $spliceApply = bind.call(Function.apply, Array.prototype.splice);
|
|
586
|
+
var $replace = bind.call(Function.call, String.prototype.replace);
|
|
587
|
+
var $strSlice = bind.call(Function.call, String.prototype.slice);
|
|
588
|
+
var $exec = bind.call(Function.call, RegExp.prototype.exec);
|
|
589
|
+
|
|
590
|
+
/* adapted from https://github.com/lodash/lodash/blob/4.17.15/dist/lodash.js#L6735-L6744 */
|
|
591
|
+
var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g;
|
|
592
|
+
var reEscapeChar = /\\(\\)?/g; /** Used to match backslashes in property paths. */
|
|
593
|
+
var stringToPath = function stringToPath(string) {
|
|
594
|
+
var first = $strSlice(string, 0, 1);
|
|
595
|
+
var last = $strSlice(string, -1);
|
|
596
|
+
if (first === '%' && last !== '%') {
|
|
597
|
+
throw new $SyntaxError('invalid intrinsic syntax, expected closing `%`');
|
|
598
|
+
} else if (last === '%' && first !== '%') {
|
|
599
|
+
throw new $SyntaxError('invalid intrinsic syntax, expected opening `%`');
|
|
600
|
+
}
|
|
601
|
+
var result = [];
|
|
602
|
+
$replace(string, rePropName, function (match, number, quote, subString) {
|
|
603
|
+
result[result.length] = quote ? $replace(subString, reEscapeChar, '$1') : number || match;
|
|
604
|
+
});
|
|
605
|
+
return result;
|
|
606
|
+
};
|
|
607
|
+
/* end adaptation */
|
|
608
|
+
|
|
609
|
+
var getBaseIntrinsic = function getBaseIntrinsic(name, allowMissing) {
|
|
610
|
+
var intrinsicName = name;
|
|
611
|
+
var alias;
|
|
612
|
+
if (hasOwn(LEGACY_ALIASES, intrinsicName)) {
|
|
613
|
+
alias = LEGACY_ALIASES[intrinsicName];
|
|
614
|
+
intrinsicName = '%' + alias[0] + '%';
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
if (hasOwn(INTRINSICS, intrinsicName)) {
|
|
618
|
+
var value = INTRINSICS[intrinsicName];
|
|
619
|
+
if (value === needsEval) {
|
|
620
|
+
value = doEval(intrinsicName);
|
|
621
|
+
}
|
|
622
|
+
if (typeof value === 'undefined' && !allowMissing) {
|
|
623
|
+
throw new $TypeError('intrinsic ' + name + ' exists, but is not available. Please file an issue!');
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
return {
|
|
627
|
+
alias: alias,
|
|
628
|
+
name: intrinsicName,
|
|
629
|
+
value: value
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
throw new $SyntaxError('intrinsic ' + name + ' does not exist!');
|
|
634
|
+
};
|
|
635
|
+
|
|
636
|
+
var getIntrinsic = function GetIntrinsic(name, allowMissing) {
|
|
637
|
+
if (typeof name !== 'string' || name.length === 0) {
|
|
638
|
+
throw new $TypeError('intrinsic name must be a non-empty string');
|
|
639
|
+
}
|
|
640
|
+
if (arguments.length > 1 && typeof allowMissing !== 'boolean') {
|
|
641
|
+
throw new $TypeError('"allowMissing" argument must be a boolean');
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
if ($exec(/^%?[^%]*%?$/, name) === null) {
|
|
645
|
+
throw new $SyntaxError('`%` may not be present anywhere but at the beginning and end of the intrinsic name');
|
|
646
|
+
}
|
|
647
|
+
var parts = stringToPath(name);
|
|
648
|
+
var intrinsicBaseName = parts.length > 0 ? parts[0] : '';
|
|
649
|
+
|
|
650
|
+
var intrinsic = getBaseIntrinsic('%' + intrinsicBaseName + '%', allowMissing);
|
|
651
|
+
var intrinsicRealName = intrinsic.name;
|
|
652
|
+
var value = intrinsic.value;
|
|
653
|
+
var skipFurtherCaching = false;
|
|
654
|
+
|
|
655
|
+
var alias = intrinsic.alias;
|
|
656
|
+
if (alias) {
|
|
657
|
+
intrinsicBaseName = alias[0];
|
|
658
|
+
$spliceApply(parts, $concat([0, 1], alias));
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
for (var i = 1, isOwn = true; i < parts.length; i += 1) {
|
|
662
|
+
var part = parts[i];
|
|
663
|
+
var first = $strSlice(part, 0, 1);
|
|
664
|
+
var last = $strSlice(part, -1);
|
|
665
|
+
if (
|
|
666
|
+
(
|
|
667
|
+
(first === '"' || first === "'" || first === '`')
|
|
668
|
+
|| (last === '"' || last === "'" || last === '`')
|
|
669
|
+
)
|
|
670
|
+
&& first !== last
|
|
671
|
+
) {
|
|
672
|
+
throw new $SyntaxError('property names with quotes must have matching quotes');
|
|
673
|
+
}
|
|
674
|
+
if (part === 'constructor' || !isOwn) {
|
|
675
|
+
skipFurtherCaching = true;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
intrinsicBaseName += '.' + part;
|
|
679
|
+
intrinsicRealName = '%' + intrinsicBaseName + '%';
|
|
680
|
+
|
|
681
|
+
if (hasOwn(INTRINSICS, intrinsicRealName)) {
|
|
682
|
+
value = INTRINSICS[intrinsicRealName];
|
|
683
|
+
} else if (value != null) {
|
|
684
|
+
if (!(part in value)) {
|
|
685
|
+
if (!allowMissing) {
|
|
686
|
+
throw new $TypeError('base intrinsic for ' + name + ' exists, but the property is not available.');
|
|
687
|
+
}
|
|
688
|
+
return void undefined$1;
|
|
689
|
+
}
|
|
690
|
+
if ($gOPD && (i + 1) >= parts.length) {
|
|
691
|
+
var desc = $gOPD(value, part);
|
|
692
|
+
isOwn = !!desc;
|
|
693
|
+
|
|
694
|
+
// By convention, when a data property is converted to an accessor
|
|
695
|
+
// property to emulate a data property that does not suffer from
|
|
696
|
+
// the override mistake, that accessor's getter is marked with
|
|
697
|
+
// an `originalValue` property. Here, when we detect this, we
|
|
698
|
+
// uphold the illusion by pretending to see that original data
|
|
699
|
+
// property, i.e., returning the value rather than the getter
|
|
700
|
+
// itself.
|
|
701
|
+
if (isOwn && 'get' in desc && !('originalValue' in desc.get)) {
|
|
702
|
+
value = desc.get;
|
|
703
|
+
} else {
|
|
704
|
+
value = value[part];
|
|
705
|
+
}
|
|
706
|
+
} else {
|
|
707
|
+
isOwn = hasOwn(value, part);
|
|
708
|
+
value = value[part];
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
if (isOwn && !skipFurtherCaching) {
|
|
712
|
+
INTRINSICS[intrinsicRealName] = value;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
return value;
|
|
717
|
+
};
|
|
718
|
+
|
|
719
|
+
var GetIntrinsic = getIntrinsic;
|
|
720
|
+
|
|
721
|
+
var $defineProperty = GetIntrinsic('%Object.defineProperty%', true);
|
|
722
|
+
|
|
723
|
+
var hasPropertyDescriptors$1 = function hasPropertyDescriptors() {
|
|
724
|
+
if ($defineProperty) {
|
|
725
|
+
try {
|
|
726
|
+
$defineProperty({}, 'a', { value: 1 });
|
|
727
|
+
return true;
|
|
728
|
+
} catch (e) {
|
|
729
|
+
// IE 8 has a broken defineProperty
|
|
730
|
+
return false;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
return false;
|
|
734
|
+
};
|
|
735
|
+
|
|
736
|
+
hasPropertyDescriptors$1.hasArrayLengthDefineBug = function hasArrayLengthDefineBug() {
|
|
737
|
+
// node v0.6 has a bug where array lengths can be Set but not Defined
|
|
738
|
+
if (!hasPropertyDescriptors$1()) {
|
|
739
|
+
return null;
|
|
740
|
+
}
|
|
741
|
+
try {
|
|
742
|
+
return $defineProperty([], 'length', { value: 1 }).length !== 1;
|
|
743
|
+
} catch (e) {
|
|
744
|
+
// In Firefox 4-22, defining length on an array throws an exception.
|
|
745
|
+
return true;
|
|
746
|
+
}
|
|
747
|
+
};
|
|
748
|
+
|
|
749
|
+
var hasPropertyDescriptors_1 = hasPropertyDescriptors$1;
|
|
750
|
+
|
|
751
|
+
var keys = objectKeys;
|
|
752
|
+
var hasSymbols = typeof Symbol === 'function' && typeof Symbol('foo') === 'symbol';
|
|
753
|
+
|
|
754
|
+
var toStr = Object.prototype.toString;
|
|
755
|
+
var concat$3 = Array.prototype.concat;
|
|
756
|
+
var origDefineProperty = Object.defineProperty;
|
|
757
|
+
|
|
758
|
+
var isFunction = function (fn) {
|
|
759
|
+
return typeof fn === 'function' && toStr.call(fn) === '[object Function]';
|
|
760
|
+
};
|
|
761
|
+
|
|
762
|
+
var hasPropertyDescriptors = hasPropertyDescriptors_1();
|
|
763
|
+
|
|
764
|
+
var supportsDescriptors = origDefineProperty && hasPropertyDescriptors;
|
|
765
|
+
|
|
766
|
+
var defineProperty = function (object, name, value, predicate) {
|
|
767
|
+
if (name in object) {
|
|
768
|
+
if (predicate === true) {
|
|
769
|
+
if (object[name] === value) {
|
|
770
|
+
return;
|
|
771
|
+
}
|
|
772
|
+
} else if (!isFunction(predicate) || !predicate()) {
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
if (supportsDescriptors) {
|
|
777
|
+
origDefineProperty(object, name, {
|
|
778
|
+
configurable: true,
|
|
779
|
+
enumerable: false,
|
|
780
|
+
value: value,
|
|
781
|
+
writable: true
|
|
782
|
+
});
|
|
783
|
+
} else {
|
|
784
|
+
object[name] = value; // eslint-disable-line no-param-reassign
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
|
|
788
|
+
var defineProperties$1 = function (object, map) {
|
|
789
|
+
var predicates = arguments.length > 2 ? arguments[2] : {};
|
|
790
|
+
var props = keys(map);
|
|
791
|
+
if (hasSymbols) {
|
|
792
|
+
props = concat$3.call(props, Object.getOwnPropertySymbols(map));
|
|
793
|
+
}
|
|
794
|
+
for (var i = 0; i < props.length; i += 1) {
|
|
795
|
+
defineProperty(object, props[i], map[props[i]], predicates[props[i]]);
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
|
|
799
|
+
defineProperties$1.supportsDescriptors = !!supportsDescriptors;
|
|
800
|
+
|
|
801
|
+
var defineProperties_1 = defineProperties$1;
|
|
802
|
+
|
|
803
|
+
var implementation$2 = commonjsGlobal;
|
|
804
|
+
|
|
805
|
+
var implementation$1 = implementation$2;
|
|
806
|
+
|
|
807
|
+
var polyfill$1 = function getPolyfill() {
|
|
808
|
+
if (typeof commonjsGlobal !== 'object' || !commonjsGlobal || commonjsGlobal.Math !== Math || commonjsGlobal.Array !== Array) {
|
|
809
|
+
return implementation$1;
|
|
810
|
+
}
|
|
811
|
+
return commonjsGlobal;
|
|
812
|
+
};
|
|
813
|
+
|
|
814
|
+
var define = defineProperties_1;
|
|
815
|
+
var getPolyfill$1 = polyfill$1;
|
|
816
|
+
|
|
817
|
+
var shim$1 = function shimGlobal() {
|
|
818
|
+
var polyfill = getPolyfill$1();
|
|
819
|
+
if (define.supportsDescriptors) {
|
|
820
|
+
var descriptor = Object.getOwnPropertyDescriptor(polyfill, 'globalThis');
|
|
821
|
+
if (!descriptor || (descriptor.configurable && (descriptor.enumerable || !descriptor.writable || globalThis !== polyfill))) { // eslint-disable-line max-len
|
|
822
|
+
Object.defineProperty(polyfill, 'globalThis', {
|
|
823
|
+
configurable: true,
|
|
824
|
+
enumerable: false,
|
|
825
|
+
value: polyfill,
|
|
826
|
+
writable: true
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
} else if (typeof globalThis !== 'object' || globalThis !== polyfill) {
|
|
830
|
+
polyfill.globalThis = polyfill;
|
|
831
|
+
}
|
|
832
|
+
return polyfill;
|
|
833
|
+
};
|
|
834
|
+
|
|
835
|
+
var defineProperties = defineProperties_1;
|
|
836
|
+
|
|
837
|
+
var implementation = implementation$2;
|
|
838
|
+
var getPolyfill = polyfill$1;
|
|
839
|
+
var shim = shim$1;
|
|
840
|
+
|
|
841
|
+
var polyfill = getPolyfill();
|
|
842
|
+
|
|
843
|
+
var getGlobal$1 = function () { return polyfill; };
|
|
844
|
+
|
|
845
|
+
defineProperties(getGlobal$1, {
|
|
846
|
+
getPolyfill: getPolyfill,
|
|
847
|
+
implementation: implementation,
|
|
848
|
+
shim: shim
|
|
849
|
+
});
|
|
850
|
+
|
|
851
|
+
var globalthis = getGlobal$1;
|
|
852
|
+
|
|
853
|
+
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
854
|
+
var extendStatics = function (d, b) {
|
|
855
|
+
extendStatics = Object.setPrototypeOf ||
|
|
856
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
857
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
858
|
+
return extendStatics(d, b);
|
|
859
|
+
};
|
|
860
|
+
return function (d, b) {
|
|
861
|
+
extendStatics(d, b);
|
|
862
|
+
function __() { this.constructor = d; }
|
|
863
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
864
|
+
};
|
|
865
|
+
})();
|
|
866
|
+
Object.defineProperty(xstream, "__esModule", { value: true });
|
|
867
|
+
var NO_IL_1 = xstream.NO_IL = NO_1 = xstream.NO = MemoryStream_1 = xstream.MemoryStream = Stream_1 = xstream.Stream = void 0;
|
|
868
|
+
var ponyfill_1 = ponyfill;
|
|
869
|
+
var globalthis_1 = globalthis;
|
|
870
|
+
var $$observable = ponyfill_1.default(globalthis_1.getPolyfill());
|
|
871
|
+
var NO$1 = {};
|
|
872
|
+
var NO_1 = xstream.NO = NO$1;
|
|
873
|
+
function noop() { }
|
|
874
|
+
function cp(a) {
|
|
875
|
+
var l = a.length;
|
|
876
|
+
var b = Array(l);
|
|
877
|
+
for (var i = 0; i < l; ++i)
|
|
878
|
+
b[i] = a[i];
|
|
879
|
+
return b;
|
|
880
|
+
}
|
|
881
|
+
function and(f1, f2) {
|
|
882
|
+
return function andFn(t) {
|
|
883
|
+
return f1(t) && f2(t);
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
function _try(c, t, u) {
|
|
887
|
+
try {
|
|
888
|
+
return c.f(t);
|
|
889
|
+
}
|
|
890
|
+
catch (e) {
|
|
891
|
+
u._e(e);
|
|
892
|
+
return NO$1;
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
var NO_IL = {
|
|
896
|
+
_n: noop,
|
|
897
|
+
_e: noop,
|
|
898
|
+
_c: noop,
|
|
899
|
+
};
|
|
900
|
+
NO_IL_1 = xstream.NO_IL = NO_IL;
|
|
901
|
+
// mutates the input
|
|
902
|
+
function internalizeProducer(producer) {
|
|
903
|
+
producer._start = function _start(il) {
|
|
904
|
+
il.next = il._n;
|
|
905
|
+
il.error = il._e;
|
|
906
|
+
il.complete = il._c;
|
|
907
|
+
this.start(il);
|
|
908
|
+
};
|
|
909
|
+
producer._stop = producer.stop;
|
|
910
|
+
}
|
|
911
|
+
var StreamSub = /** @class */ (function () {
|
|
912
|
+
function StreamSub(_stream, _listener) {
|
|
913
|
+
this._stream = _stream;
|
|
914
|
+
this._listener = _listener;
|
|
915
|
+
}
|
|
916
|
+
StreamSub.prototype.unsubscribe = function () {
|
|
917
|
+
this._stream._remove(this._listener);
|
|
918
|
+
};
|
|
919
|
+
return StreamSub;
|
|
920
|
+
}());
|
|
921
|
+
var Observer = /** @class */ (function () {
|
|
922
|
+
function Observer(_listener) {
|
|
923
|
+
this._listener = _listener;
|
|
924
|
+
}
|
|
925
|
+
Observer.prototype.next = function (value) {
|
|
926
|
+
this._listener._n(value);
|
|
927
|
+
};
|
|
928
|
+
Observer.prototype.error = function (err) {
|
|
929
|
+
this._listener._e(err);
|
|
930
|
+
};
|
|
931
|
+
Observer.prototype.complete = function () {
|
|
932
|
+
this._listener._c();
|
|
933
|
+
};
|
|
934
|
+
return Observer;
|
|
935
|
+
}());
|
|
936
|
+
var FromObservable = /** @class */ (function () {
|
|
937
|
+
function FromObservable(observable) {
|
|
938
|
+
this.type = 'fromObservable';
|
|
939
|
+
this.ins = observable;
|
|
940
|
+
this.active = false;
|
|
941
|
+
}
|
|
942
|
+
FromObservable.prototype._start = function (out) {
|
|
943
|
+
this.out = out;
|
|
944
|
+
this.active = true;
|
|
945
|
+
this._sub = this.ins.subscribe(new Observer(out));
|
|
946
|
+
if (!this.active)
|
|
947
|
+
this._sub.unsubscribe();
|
|
948
|
+
};
|
|
949
|
+
FromObservable.prototype._stop = function () {
|
|
950
|
+
if (this._sub)
|
|
951
|
+
this._sub.unsubscribe();
|
|
952
|
+
this.active = false;
|
|
953
|
+
};
|
|
954
|
+
return FromObservable;
|
|
955
|
+
}());
|
|
956
|
+
var Merge = /** @class */ (function () {
|
|
957
|
+
function Merge(insArr) {
|
|
958
|
+
this.type = 'merge';
|
|
959
|
+
this.insArr = insArr;
|
|
960
|
+
this.out = NO$1;
|
|
961
|
+
this.ac = 0;
|
|
962
|
+
}
|
|
963
|
+
Merge.prototype._start = function (out) {
|
|
964
|
+
this.out = out;
|
|
965
|
+
var s = this.insArr;
|
|
966
|
+
var L = s.length;
|
|
967
|
+
this.ac = L;
|
|
968
|
+
for (var i = 0; i < L; i++)
|
|
969
|
+
s[i]._add(this);
|
|
970
|
+
};
|
|
971
|
+
Merge.prototype._stop = function () {
|
|
972
|
+
var s = this.insArr;
|
|
973
|
+
var L = s.length;
|
|
974
|
+
for (var i = 0; i < L; i++)
|
|
975
|
+
s[i]._remove(this);
|
|
976
|
+
this.out = NO$1;
|
|
977
|
+
};
|
|
978
|
+
Merge.prototype._n = function (t) {
|
|
979
|
+
var u = this.out;
|
|
980
|
+
if (u === NO$1)
|
|
981
|
+
return;
|
|
982
|
+
u._n(t);
|
|
983
|
+
};
|
|
984
|
+
Merge.prototype._e = function (err) {
|
|
985
|
+
var u = this.out;
|
|
986
|
+
if (u === NO$1)
|
|
987
|
+
return;
|
|
988
|
+
u._e(err);
|
|
989
|
+
};
|
|
990
|
+
Merge.prototype._c = function () {
|
|
991
|
+
if (--this.ac <= 0) {
|
|
992
|
+
var u = this.out;
|
|
993
|
+
if (u === NO$1)
|
|
994
|
+
return;
|
|
995
|
+
u._c();
|
|
996
|
+
}
|
|
997
|
+
};
|
|
998
|
+
return Merge;
|
|
999
|
+
}());
|
|
1000
|
+
var CombineListener = /** @class */ (function () {
|
|
1001
|
+
function CombineListener(i, out, p) {
|
|
1002
|
+
this.i = i;
|
|
1003
|
+
this.out = out;
|
|
1004
|
+
this.p = p;
|
|
1005
|
+
p.ils.push(this);
|
|
1006
|
+
}
|
|
1007
|
+
CombineListener.prototype._n = function (t) {
|
|
1008
|
+
var p = this.p, out = this.out;
|
|
1009
|
+
if (out === NO$1)
|
|
1010
|
+
return;
|
|
1011
|
+
if (p.up(t, this.i)) {
|
|
1012
|
+
var b = cp(p.vals);
|
|
1013
|
+
out._n(b);
|
|
1014
|
+
}
|
|
1015
|
+
};
|
|
1016
|
+
CombineListener.prototype._e = function (err) {
|
|
1017
|
+
var out = this.out;
|
|
1018
|
+
if (out === NO$1)
|
|
1019
|
+
return;
|
|
1020
|
+
out._e(err);
|
|
1021
|
+
};
|
|
1022
|
+
CombineListener.prototype._c = function () {
|
|
1023
|
+
var p = this.p;
|
|
1024
|
+
if (p.out === NO$1)
|
|
1025
|
+
return;
|
|
1026
|
+
if (--p.Nc === 0)
|
|
1027
|
+
p.out._c();
|
|
1028
|
+
};
|
|
1029
|
+
return CombineListener;
|
|
1030
|
+
}());
|
|
1031
|
+
var Combine = /** @class */ (function () {
|
|
1032
|
+
function Combine(insArr) {
|
|
1033
|
+
this.type = 'combine';
|
|
1034
|
+
this.insArr = insArr;
|
|
1035
|
+
this.out = NO$1;
|
|
1036
|
+
this.ils = [];
|
|
1037
|
+
this.Nc = this.Nn = 0;
|
|
1038
|
+
this.vals = [];
|
|
1039
|
+
}
|
|
1040
|
+
Combine.prototype.up = function (t, i) {
|
|
1041
|
+
var v = this.vals[i];
|
|
1042
|
+
var Nn = !this.Nn ? 0 : v === NO$1 ? --this.Nn : this.Nn;
|
|
1043
|
+
this.vals[i] = t;
|
|
1044
|
+
return Nn === 0;
|
|
1045
|
+
};
|
|
1046
|
+
Combine.prototype._start = function (out) {
|
|
1047
|
+
this.out = out;
|
|
1048
|
+
var s = this.insArr;
|
|
1049
|
+
var n = this.Nc = this.Nn = s.length;
|
|
1050
|
+
var vals = this.vals = new Array(n);
|
|
1051
|
+
if (n === 0) {
|
|
1052
|
+
out._n([]);
|
|
1053
|
+
out._c();
|
|
1054
|
+
}
|
|
1055
|
+
else {
|
|
1056
|
+
for (var i = 0; i < n; i++) {
|
|
1057
|
+
vals[i] = NO$1;
|
|
1058
|
+
s[i]._add(new CombineListener(i, out, this));
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
Combine.prototype._stop = function () {
|
|
1063
|
+
var s = this.insArr;
|
|
1064
|
+
var n = s.length;
|
|
1065
|
+
var ils = this.ils;
|
|
1066
|
+
for (var i = 0; i < n; i++)
|
|
1067
|
+
s[i]._remove(ils[i]);
|
|
1068
|
+
this.out = NO$1;
|
|
1069
|
+
this.ils = [];
|
|
1070
|
+
this.vals = [];
|
|
1071
|
+
};
|
|
1072
|
+
return Combine;
|
|
1073
|
+
}());
|
|
1074
|
+
var FromArray = /** @class */ (function () {
|
|
1075
|
+
function FromArray(a) {
|
|
1076
|
+
this.type = 'fromArray';
|
|
1077
|
+
this.a = a;
|
|
1078
|
+
}
|
|
1079
|
+
FromArray.prototype._start = function (out) {
|
|
1080
|
+
var a = this.a;
|
|
1081
|
+
for (var i = 0, n = a.length; i < n; i++)
|
|
1082
|
+
out._n(a[i]);
|
|
1083
|
+
out._c();
|
|
1084
|
+
};
|
|
1085
|
+
FromArray.prototype._stop = function () {
|
|
1086
|
+
};
|
|
1087
|
+
return FromArray;
|
|
1088
|
+
}());
|
|
1089
|
+
var FromPromise = /** @class */ (function () {
|
|
1090
|
+
function FromPromise(p) {
|
|
1091
|
+
this.type = 'fromPromise';
|
|
1092
|
+
this.on = false;
|
|
1093
|
+
this.p = p;
|
|
1094
|
+
}
|
|
1095
|
+
FromPromise.prototype._start = function (out) {
|
|
1096
|
+
var prod = this;
|
|
1097
|
+
this.on = true;
|
|
1098
|
+
this.p.then(function (v) {
|
|
1099
|
+
if (prod.on) {
|
|
1100
|
+
out._n(v);
|
|
1101
|
+
out._c();
|
|
1102
|
+
}
|
|
1103
|
+
}, function (e) {
|
|
1104
|
+
out._e(e);
|
|
1105
|
+
}).then(noop, function (err) {
|
|
1106
|
+
setTimeout(function () { throw err; });
|
|
1107
|
+
});
|
|
1108
|
+
};
|
|
1109
|
+
FromPromise.prototype._stop = function () {
|
|
1110
|
+
this.on = false;
|
|
1111
|
+
};
|
|
1112
|
+
return FromPromise;
|
|
1113
|
+
}());
|
|
1114
|
+
var Periodic = /** @class */ (function () {
|
|
1115
|
+
function Periodic(period) {
|
|
1116
|
+
this.type = 'periodic';
|
|
1117
|
+
this.period = period;
|
|
1118
|
+
this.intervalID = -1;
|
|
1119
|
+
this.i = 0;
|
|
1120
|
+
}
|
|
1121
|
+
Periodic.prototype._start = function (out) {
|
|
1122
|
+
var self = this;
|
|
1123
|
+
function intervalHandler() { out._n(self.i++); }
|
|
1124
|
+
this.intervalID = setInterval(intervalHandler, this.period);
|
|
1125
|
+
};
|
|
1126
|
+
Periodic.prototype._stop = function () {
|
|
1127
|
+
if (this.intervalID !== -1)
|
|
1128
|
+
clearInterval(this.intervalID);
|
|
1129
|
+
this.intervalID = -1;
|
|
1130
|
+
this.i = 0;
|
|
1131
|
+
};
|
|
1132
|
+
return Periodic;
|
|
1133
|
+
}());
|
|
1134
|
+
var Debug = /** @class */ (function () {
|
|
1135
|
+
function Debug(ins, arg) {
|
|
1136
|
+
this.type = 'debug';
|
|
1137
|
+
this.ins = ins;
|
|
1138
|
+
this.out = NO$1;
|
|
1139
|
+
this.s = noop;
|
|
1140
|
+
this.l = '';
|
|
1141
|
+
if (typeof arg === 'string')
|
|
1142
|
+
this.l = arg;
|
|
1143
|
+
else if (typeof arg === 'function')
|
|
1144
|
+
this.s = arg;
|
|
1145
|
+
}
|
|
1146
|
+
Debug.prototype._start = function (out) {
|
|
1147
|
+
this.out = out;
|
|
1148
|
+
this.ins._add(this);
|
|
1149
|
+
};
|
|
1150
|
+
Debug.prototype._stop = function () {
|
|
1151
|
+
this.ins._remove(this);
|
|
1152
|
+
this.out = NO$1;
|
|
1153
|
+
};
|
|
1154
|
+
Debug.prototype._n = function (t) {
|
|
1155
|
+
var u = this.out;
|
|
1156
|
+
if (u === NO$1)
|
|
1157
|
+
return;
|
|
1158
|
+
var s = this.s, l = this.l;
|
|
1159
|
+
if (s !== noop) {
|
|
1160
|
+
try {
|
|
1161
|
+
s(t);
|
|
1162
|
+
}
|
|
1163
|
+
catch (e) {
|
|
1164
|
+
u._e(e);
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
else if (l)
|
|
1168
|
+
console.log(l + ':', t);
|
|
1169
|
+
else
|
|
1170
|
+
console.log(t);
|
|
1171
|
+
u._n(t);
|
|
1172
|
+
};
|
|
1173
|
+
Debug.prototype._e = function (err) {
|
|
1174
|
+
var u = this.out;
|
|
1175
|
+
if (u === NO$1)
|
|
1176
|
+
return;
|
|
1177
|
+
u._e(err);
|
|
1178
|
+
};
|
|
1179
|
+
Debug.prototype._c = function () {
|
|
1180
|
+
var u = this.out;
|
|
1181
|
+
if (u === NO$1)
|
|
1182
|
+
return;
|
|
1183
|
+
u._c();
|
|
1184
|
+
};
|
|
1185
|
+
return Debug;
|
|
1186
|
+
}());
|
|
1187
|
+
var Drop = /** @class */ (function () {
|
|
1188
|
+
function Drop(max, ins) {
|
|
1189
|
+
this.type = 'drop';
|
|
1190
|
+
this.ins = ins;
|
|
1191
|
+
this.out = NO$1;
|
|
1192
|
+
this.max = max;
|
|
1193
|
+
this.dropped = 0;
|
|
1194
|
+
}
|
|
1195
|
+
Drop.prototype._start = function (out) {
|
|
1196
|
+
this.out = out;
|
|
1197
|
+
this.dropped = 0;
|
|
1198
|
+
this.ins._add(this);
|
|
1199
|
+
};
|
|
1200
|
+
Drop.prototype._stop = function () {
|
|
1201
|
+
this.ins._remove(this);
|
|
1202
|
+
this.out = NO$1;
|
|
1203
|
+
};
|
|
1204
|
+
Drop.prototype._n = function (t) {
|
|
1205
|
+
var u = this.out;
|
|
1206
|
+
if (u === NO$1)
|
|
1207
|
+
return;
|
|
1208
|
+
if (this.dropped++ >= this.max)
|
|
1209
|
+
u._n(t);
|
|
1210
|
+
};
|
|
1211
|
+
Drop.prototype._e = function (err) {
|
|
1212
|
+
var u = this.out;
|
|
1213
|
+
if (u === NO$1)
|
|
1214
|
+
return;
|
|
1215
|
+
u._e(err);
|
|
1216
|
+
};
|
|
1217
|
+
Drop.prototype._c = function () {
|
|
1218
|
+
var u = this.out;
|
|
1219
|
+
if (u === NO$1)
|
|
1220
|
+
return;
|
|
1221
|
+
u._c();
|
|
1222
|
+
};
|
|
1223
|
+
return Drop;
|
|
1224
|
+
}());
|
|
1225
|
+
var EndWhenListener = /** @class */ (function () {
|
|
1226
|
+
function EndWhenListener(out, op) {
|
|
1227
|
+
this.out = out;
|
|
1228
|
+
this.op = op;
|
|
1229
|
+
}
|
|
1230
|
+
EndWhenListener.prototype._n = function () {
|
|
1231
|
+
this.op.end();
|
|
1232
|
+
};
|
|
1233
|
+
EndWhenListener.prototype._e = function (err) {
|
|
1234
|
+
this.out._e(err);
|
|
1235
|
+
};
|
|
1236
|
+
EndWhenListener.prototype._c = function () {
|
|
1237
|
+
this.op.end();
|
|
1238
|
+
};
|
|
1239
|
+
return EndWhenListener;
|
|
1240
|
+
}());
|
|
1241
|
+
var EndWhen = /** @class */ (function () {
|
|
1242
|
+
function EndWhen(o, ins) {
|
|
1243
|
+
this.type = 'endWhen';
|
|
1244
|
+
this.ins = ins;
|
|
1245
|
+
this.out = NO$1;
|
|
1246
|
+
this.o = o;
|
|
1247
|
+
this.oil = NO_IL;
|
|
1248
|
+
}
|
|
1249
|
+
EndWhen.prototype._start = function (out) {
|
|
1250
|
+
this.out = out;
|
|
1251
|
+
this.o._add(this.oil = new EndWhenListener(out, this));
|
|
1252
|
+
this.ins._add(this);
|
|
1253
|
+
};
|
|
1254
|
+
EndWhen.prototype._stop = function () {
|
|
1255
|
+
this.ins._remove(this);
|
|
1256
|
+
this.o._remove(this.oil);
|
|
1257
|
+
this.out = NO$1;
|
|
1258
|
+
this.oil = NO_IL;
|
|
1259
|
+
};
|
|
1260
|
+
EndWhen.prototype.end = function () {
|
|
1261
|
+
var u = this.out;
|
|
1262
|
+
if (u === NO$1)
|
|
1263
|
+
return;
|
|
1264
|
+
u._c();
|
|
1265
|
+
};
|
|
1266
|
+
EndWhen.prototype._n = function (t) {
|
|
1267
|
+
var u = this.out;
|
|
1268
|
+
if (u === NO$1)
|
|
1269
|
+
return;
|
|
1270
|
+
u._n(t);
|
|
1271
|
+
};
|
|
1272
|
+
EndWhen.prototype._e = function (err) {
|
|
1273
|
+
var u = this.out;
|
|
1274
|
+
if (u === NO$1)
|
|
1275
|
+
return;
|
|
1276
|
+
u._e(err);
|
|
1277
|
+
};
|
|
1278
|
+
EndWhen.prototype._c = function () {
|
|
1279
|
+
this.end();
|
|
1280
|
+
};
|
|
1281
|
+
return EndWhen;
|
|
1282
|
+
}());
|
|
1283
|
+
var Filter = /** @class */ (function () {
|
|
1284
|
+
function Filter(passes, ins) {
|
|
1285
|
+
this.type = 'filter';
|
|
1286
|
+
this.ins = ins;
|
|
1287
|
+
this.out = NO$1;
|
|
1288
|
+
this.f = passes;
|
|
1289
|
+
}
|
|
1290
|
+
Filter.prototype._start = function (out) {
|
|
1291
|
+
this.out = out;
|
|
1292
|
+
this.ins._add(this);
|
|
1293
|
+
};
|
|
1294
|
+
Filter.prototype._stop = function () {
|
|
1295
|
+
this.ins._remove(this);
|
|
1296
|
+
this.out = NO$1;
|
|
1297
|
+
};
|
|
1298
|
+
Filter.prototype._n = function (t) {
|
|
1299
|
+
var u = this.out;
|
|
1300
|
+
if (u === NO$1)
|
|
1301
|
+
return;
|
|
1302
|
+
var r = _try(this, t, u);
|
|
1303
|
+
if (r === NO$1 || !r)
|
|
1304
|
+
return;
|
|
1305
|
+
u._n(t);
|
|
1306
|
+
};
|
|
1307
|
+
Filter.prototype._e = function (err) {
|
|
1308
|
+
var u = this.out;
|
|
1309
|
+
if (u === NO$1)
|
|
1310
|
+
return;
|
|
1311
|
+
u._e(err);
|
|
1312
|
+
};
|
|
1313
|
+
Filter.prototype._c = function () {
|
|
1314
|
+
var u = this.out;
|
|
1315
|
+
if (u === NO$1)
|
|
1316
|
+
return;
|
|
1317
|
+
u._c();
|
|
1318
|
+
};
|
|
1319
|
+
return Filter;
|
|
1320
|
+
}());
|
|
1321
|
+
var FlattenListener = /** @class */ (function () {
|
|
1322
|
+
function FlattenListener(out, op) {
|
|
1323
|
+
this.out = out;
|
|
1324
|
+
this.op = op;
|
|
1325
|
+
}
|
|
1326
|
+
FlattenListener.prototype._n = function (t) {
|
|
1327
|
+
this.out._n(t);
|
|
1328
|
+
};
|
|
1329
|
+
FlattenListener.prototype._e = function (err) {
|
|
1330
|
+
this.out._e(err);
|
|
1331
|
+
};
|
|
1332
|
+
FlattenListener.prototype._c = function () {
|
|
1333
|
+
this.op.inner = NO$1;
|
|
1334
|
+
this.op.less();
|
|
1335
|
+
};
|
|
1336
|
+
return FlattenListener;
|
|
1337
|
+
}());
|
|
1338
|
+
var Flatten = /** @class */ (function () {
|
|
1339
|
+
function Flatten(ins) {
|
|
1340
|
+
this.type = 'flatten';
|
|
1341
|
+
this.ins = ins;
|
|
1342
|
+
this.out = NO$1;
|
|
1343
|
+
this.open = true;
|
|
1344
|
+
this.inner = NO$1;
|
|
1345
|
+
this.il = NO_IL;
|
|
1346
|
+
}
|
|
1347
|
+
Flatten.prototype._start = function (out) {
|
|
1348
|
+
this.out = out;
|
|
1349
|
+
this.open = true;
|
|
1350
|
+
this.inner = NO$1;
|
|
1351
|
+
this.il = NO_IL;
|
|
1352
|
+
this.ins._add(this);
|
|
1353
|
+
};
|
|
1354
|
+
Flatten.prototype._stop = function () {
|
|
1355
|
+
this.ins._remove(this);
|
|
1356
|
+
if (this.inner !== NO$1)
|
|
1357
|
+
this.inner._remove(this.il);
|
|
1358
|
+
this.out = NO$1;
|
|
1359
|
+
this.open = true;
|
|
1360
|
+
this.inner = NO$1;
|
|
1361
|
+
this.il = NO_IL;
|
|
1362
|
+
};
|
|
1363
|
+
Flatten.prototype.less = function () {
|
|
1364
|
+
var u = this.out;
|
|
1365
|
+
if (u === NO$1)
|
|
1366
|
+
return;
|
|
1367
|
+
if (!this.open && this.inner === NO$1)
|
|
1368
|
+
u._c();
|
|
1369
|
+
};
|
|
1370
|
+
Flatten.prototype._n = function (s) {
|
|
1371
|
+
var u = this.out;
|
|
1372
|
+
if (u === NO$1)
|
|
1373
|
+
return;
|
|
1374
|
+
var _a = this, inner = _a.inner, il = _a.il;
|
|
1375
|
+
if (inner !== NO$1 && il !== NO_IL)
|
|
1376
|
+
inner._remove(il);
|
|
1377
|
+
(this.inner = s)._add(this.il = new FlattenListener(u, this));
|
|
1378
|
+
};
|
|
1379
|
+
Flatten.prototype._e = function (err) {
|
|
1380
|
+
var u = this.out;
|
|
1381
|
+
if (u === NO$1)
|
|
1382
|
+
return;
|
|
1383
|
+
u._e(err);
|
|
1384
|
+
};
|
|
1385
|
+
Flatten.prototype._c = function () {
|
|
1386
|
+
this.open = false;
|
|
1387
|
+
this.less();
|
|
1388
|
+
};
|
|
1389
|
+
return Flatten;
|
|
1390
|
+
}());
|
|
1391
|
+
var Fold = /** @class */ (function () {
|
|
1392
|
+
function Fold(f, seed, ins) {
|
|
1393
|
+
var _this = this;
|
|
1394
|
+
this.type = 'fold';
|
|
1395
|
+
this.ins = ins;
|
|
1396
|
+
this.out = NO$1;
|
|
1397
|
+
this.f = function (t) { return f(_this.acc, t); };
|
|
1398
|
+
this.acc = this.seed = seed;
|
|
1399
|
+
}
|
|
1400
|
+
Fold.prototype._start = function (out) {
|
|
1401
|
+
this.out = out;
|
|
1402
|
+
this.acc = this.seed;
|
|
1403
|
+
out._n(this.acc);
|
|
1404
|
+
this.ins._add(this);
|
|
1405
|
+
};
|
|
1406
|
+
Fold.prototype._stop = function () {
|
|
1407
|
+
this.ins._remove(this);
|
|
1408
|
+
this.out = NO$1;
|
|
1409
|
+
this.acc = this.seed;
|
|
1410
|
+
};
|
|
1411
|
+
Fold.prototype._n = function (t) {
|
|
1412
|
+
var u = this.out;
|
|
1413
|
+
if (u === NO$1)
|
|
1414
|
+
return;
|
|
1415
|
+
var r = _try(this, t, u);
|
|
1416
|
+
if (r === NO$1)
|
|
1417
|
+
return;
|
|
1418
|
+
u._n(this.acc = r);
|
|
1419
|
+
};
|
|
1420
|
+
Fold.prototype._e = function (err) {
|
|
1421
|
+
var u = this.out;
|
|
1422
|
+
if (u === NO$1)
|
|
1423
|
+
return;
|
|
1424
|
+
u._e(err);
|
|
1425
|
+
};
|
|
1426
|
+
Fold.prototype._c = function () {
|
|
1427
|
+
var u = this.out;
|
|
1428
|
+
if (u === NO$1)
|
|
1429
|
+
return;
|
|
1430
|
+
u._c();
|
|
1431
|
+
};
|
|
1432
|
+
return Fold;
|
|
1433
|
+
}());
|
|
1434
|
+
var Last = /** @class */ (function () {
|
|
1435
|
+
function Last(ins) {
|
|
1436
|
+
this.type = 'last';
|
|
1437
|
+
this.ins = ins;
|
|
1438
|
+
this.out = NO$1;
|
|
1439
|
+
this.has = false;
|
|
1440
|
+
this.val = NO$1;
|
|
1441
|
+
}
|
|
1442
|
+
Last.prototype._start = function (out) {
|
|
1443
|
+
this.out = out;
|
|
1444
|
+
this.has = false;
|
|
1445
|
+
this.ins._add(this);
|
|
1446
|
+
};
|
|
1447
|
+
Last.prototype._stop = function () {
|
|
1448
|
+
this.ins._remove(this);
|
|
1449
|
+
this.out = NO$1;
|
|
1450
|
+
this.val = NO$1;
|
|
1451
|
+
};
|
|
1452
|
+
Last.prototype._n = function (t) {
|
|
1453
|
+
this.has = true;
|
|
1454
|
+
this.val = t;
|
|
1455
|
+
};
|
|
1456
|
+
Last.prototype._e = function (err) {
|
|
1457
|
+
var u = this.out;
|
|
1458
|
+
if (u === NO$1)
|
|
1459
|
+
return;
|
|
1460
|
+
u._e(err);
|
|
1461
|
+
};
|
|
1462
|
+
Last.prototype._c = function () {
|
|
1463
|
+
var u = this.out;
|
|
1464
|
+
if (u === NO$1)
|
|
1465
|
+
return;
|
|
1466
|
+
if (this.has) {
|
|
1467
|
+
u._n(this.val);
|
|
1468
|
+
u._c();
|
|
1469
|
+
}
|
|
1470
|
+
else
|
|
1471
|
+
u._e(new Error('last() failed because input stream completed'));
|
|
1472
|
+
};
|
|
1473
|
+
return Last;
|
|
1474
|
+
}());
|
|
1475
|
+
var MapOp = /** @class */ (function () {
|
|
1476
|
+
function MapOp(project, ins) {
|
|
1477
|
+
this.type = 'map';
|
|
1478
|
+
this.ins = ins;
|
|
1479
|
+
this.out = NO$1;
|
|
1480
|
+
this.f = project;
|
|
1481
|
+
}
|
|
1482
|
+
MapOp.prototype._start = function (out) {
|
|
1483
|
+
this.out = out;
|
|
1484
|
+
this.ins._add(this);
|
|
1485
|
+
};
|
|
1486
|
+
MapOp.prototype._stop = function () {
|
|
1487
|
+
this.ins._remove(this);
|
|
1488
|
+
this.out = NO$1;
|
|
1489
|
+
};
|
|
1490
|
+
MapOp.prototype._n = function (t) {
|
|
1491
|
+
var u = this.out;
|
|
1492
|
+
if (u === NO$1)
|
|
1493
|
+
return;
|
|
1494
|
+
var r = _try(this, t, u);
|
|
1495
|
+
if (r === NO$1)
|
|
1496
|
+
return;
|
|
1497
|
+
u._n(r);
|
|
1498
|
+
};
|
|
1499
|
+
MapOp.prototype._e = function (err) {
|
|
1500
|
+
var u = this.out;
|
|
1501
|
+
if (u === NO$1)
|
|
1502
|
+
return;
|
|
1503
|
+
u._e(err);
|
|
1504
|
+
};
|
|
1505
|
+
MapOp.prototype._c = function () {
|
|
1506
|
+
var u = this.out;
|
|
1507
|
+
if (u === NO$1)
|
|
1508
|
+
return;
|
|
1509
|
+
u._c();
|
|
1510
|
+
};
|
|
1511
|
+
return MapOp;
|
|
1512
|
+
}());
|
|
1513
|
+
var Remember = /** @class */ (function () {
|
|
1514
|
+
function Remember(ins) {
|
|
1515
|
+
this.type = 'remember';
|
|
1516
|
+
this.ins = ins;
|
|
1517
|
+
this.out = NO$1;
|
|
1518
|
+
}
|
|
1519
|
+
Remember.prototype._start = function (out) {
|
|
1520
|
+
this.out = out;
|
|
1521
|
+
this.ins._add(out);
|
|
1522
|
+
};
|
|
1523
|
+
Remember.prototype._stop = function () {
|
|
1524
|
+
this.ins._remove(this.out);
|
|
1525
|
+
this.out = NO$1;
|
|
1526
|
+
};
|
|
1527
|
+
return Remember;
|
|
1528
|
+
}());
|
|
1529
|
+
var ReplaceError = /** @class */ (function () {
|
|
1530
|
+
function ReplaceError(replacer, ins) {
|
|
1531
|
+
this.type = 'replaceError';
|
|
1532
|
+
this.ins = ins;
|
|
1533
|
+
this.out = NO$1;
|
|
1534
|
+
this.f = replacer;
|
|
1535
|
+
}
|
|
1536
|
+
ReplaceError.prototype._start = function (out) {
|
|
1537
|
+
this.out = out;
|
|
1538
|
+
this.ins._add(this);
|
|
1539
|
+
};
|
|
1540
|
+
ReplaceError.prototype._stop = function () {
|
|
1541
|
+
this.ins._remove(this);
|
|
1542
|
+
this.out = NO$1;
|
|
1543
|
+
};
|
|
1544
|
+
ReplaceError.prototype._n = function (t) {
|
|
1545
|
+
var u = this.out;
|
|
1546
|
+
if (u === NO$1)
|
|
1547
|
+
return;
|
|
1548
|
+
u._n(t);
|
|
1549
|
+
};
|
|
1550
|
+
ReplaceError.prototype._e = function (err) {
|
|
1551
|
+
var u = this.out;
|
|
1552
|
+
if (u === NO$1)
|
|
1553
|
+
return;
|
|
1554
|
+
try {
|
|
1555
|
+
this.ins._remove(this);
|
|
1556
|
+
(this.ins = this.f(err))._add(this);
|
|
1557
|
+
}
|
|
1558
|
+
catch (e) {
|
|
1559
|
+
u._e(e);
|
|
1560
|
+
}
|
|
1561
|
+
};
|
|
1562
|
+
ReplaceError.prototype._c = function () {
|
|
1563
|
+
var u = this.out;
|
|
1564
|
+
if (u === NO$1)
|
|
1565
|
+
return;
|
|
1566
|
+
u._c();
|
|
1567
|
+
};
|
|
1568
|
+
return ReplaceError;
|
|
1569
|
+
}());
|
|
1570
|
+
var StartWith = /** @class */ (function () {
|
|
1571
|
+
function StartWith(ins, val) {
|
|
1572
|
+
this.type = 'startWith';
|
|
1573
|
+
this.ins = ins;
|
|
1574
|
+
this.out = NO$1;
|
|
1575
|
+
this.val = val;
|
|
1576
|
+
}
|
|
1577
|
+
StartWith.prototype._start = function (out) {
|
|
1578
|
+
this.out = out;
|
|
1579
|
+
this.out._n(this.val);
|
|
1580
|
+
this.ins._add(out);
|
|
1581
|
+
};
|
|
1582
|
+
StartWith.prototype._stop = function () {
|
|
1583
|
+
this.ins._remove(this.out);
|
|
1584
|
+
this.out = NO$1;
|
|
1585
|
+
};
|
|
1586
|
+
return StartWith;
|
|
1587
|
+
}());
|
|
1588
|
+
var Take = /** @class */ (function () {
|
|
1589
|
+
function Take(max, ins) {
|
|
1590
|
+
this.type = 'take';
|
|
1591
|
+
this.ins = ins;
|
|
1592
|
+
this.out = NO$1;
|
|
1593
|
+
this.max = max;
|
|
1594
|
+
this.taken = 0;
|
|
1595
|
+
}
|
|
1596
|
+
Take.prototype._start = function (out) {
|
|
1597
|
+
this.out = out;
|
|
1598
|
+
this.taken = 0;
|
|
1599
|
+
if (this.max <= 0)
|
|
1600
|
+
out._c();
|
|
1601
|
+
else
|
|
1602
|
+
this.ins._add(this);
|
|
1603
|
+
};
|
|
1604
|
+
Take.prototype._stop = function () {
|
|
1605
|
+
this.ins._remove(this);
|
|
1606
|
+
this.out = NO$1;
|
|
1607
|
+
};
|
|
1608
|
+
Take.prototype._n = function (t) {
|
|
1609
|
+
var u = this.out;
|
|
1610
|
+
if (u === NO$1)
|
|
1611
|
+
return;
|
|
1612
|
+
var m = ++this.taken;
|
|
1613
|
+
if (m < this.max)
|
|
1614
|
+
u._n(t);
|
|
1615
|
+
else if (m === this.max) {
|
|
1616
|
+
u._n(t);
|
|
1617
|
+
u._c();
|
|
1618
|
+
}
|
|
1619
|
+
};
|
|
1620
|
+
Take.prototype._e = function (err) {
|
|
1621
|
+
var u = this.out;
|
|
1622
|
+
if (u === NO$1)
|
|
1623
|
+
return;
|
|
1624
|
+
u._e(err);
|
|
1625
|
+
};
|
|
1626
|
+
Take.prototype._c = function () {
|
|
1627
|
+
var u = this.out;
|
|
1628
|
+
if (u === NO$1)
|
|
1629
|
+
return;
|
|
1630
|
+
u._c();
|
|
1631
|
+
};
|
|
1632
|
+
return Take;
|
|
1633
|
+
}());
|
|
1634
|
+
var Stream$1 = /** @class */ (function () {
|
|
1635
|
+
function Stream(producer) {
|
|
1636
|
+
this._prod = producer || NO$1;
|
|
1637
|
+
this._ils = [];
|
|
1638
|
+
this._stopID = NO$1;
|
|
1639
|
+
this._dl = NO$1;
|
|
1640
|
+
this._d = false;
|
|
1641
|
+
this._target = null;
|
|
1642
|
+
this._err = NO$1;
|
|
1643
|
+
}
|
|
1644
|
+
Stream.prototype._n = function (t) {
|
|
1645
|
+
var a = this._ils;
|
|
1646
|
+
var L = a.length;
|
|
1647
|
+
if (this._d)
|
|
1648
|
+
this._dl._n(t);
|
|
1649
|
+
if (L == 1)
|
|
1650
|
+
a[0]._n(t);
|
|
1651
|
+
else if (L == 0)
|
|
1652
|
+
return;
|
|
1653
|
+
else {
|
|
1654
|
+
var b = cp(a);
|
|
1655
|
+
for (var i = 0; i < L; i++)
|
|
1656
|
+
b[i]._n(t);
|
|
1657
|
+
}
|
|
1658
|
+
};
|
|
1659
|
+
Stream.prototype._e = function (err) {
|
|
1660
|
+
if (this._err !== NO$1)
|
|
1661
|
+
return;
|
|
1662
|
+
this._err = err;
|
|
1663
|
+
var a = this._ils;
|
|
1664
|
+
var L = a.length;
|
|
1665
|
+
this._x();
|
|
1666
|
+
if (this._d)
|
|
1667
|
+
this._dl._e(err);
|
|
1668
|
+
if (L == 1)
|
|
1669
|
+
a[0]._e(err);
|
|
1670
|
+
else if (L == 0)
|
|
1671
|
+
return;
|
|
1672
|
+
else {
|
|
1673
|
+
var b = cp(a);
|
|
1674
|
+
for (var i = 0; i < L; i++)
|
|
1675
|
+
b[i]._e(err);
|
|
1676
|
+
}
|
|
1677
|
+
if (!this._d && L == 0)
|
|
1678
|
+
throw this._err;
|
|
1679
|
+
};
|
|
1680
|
+
Stream.prototype._c = function () {
|
|
1681
|
+
var a = this._ils;
|
|
1682
|
+
var L = a.length;
|
|
1683
|
+
this._x();
|
|
1684
|
+
if (this._d)
|
|
1685
|
+
this._dl._c();
|
|
1686
|
+
if (L == 1)
|
|
1687
|
+
a[0]._c();
|
|
1688
|
+
else if (L == 0)
|
|
1689
|
+
return;
|
|
1690
|
+
else {
|
|
1691
|
+
var b = cp(a);
|
|
1692
|
+
for (var i = 0; i < L; i++)
|
|
1693
|
+
b[i]._c();
|
|
1694
|
+
}
|
|
1695
|
+
};
|
|
1696
|
+
Stream.prototype._x = function () {
|
|
1697
|
+
if (this._ils.length === 0)
|
|
1698
|
+
return;
|
|
1699
|
+
if (this._prod !== NO$1)
|
|
1700
|
+
this._prod._stop();
|
|
1701
|
+
this._err = NO$1;
|
|
1702
|
+
this._ils = [];
|
|
1703
|
+
};
|
|
1704
|
+
Stream.prototype._stopNow = function () {
|
|
1705
|
+
// WARNING: code that calls this method should
|
|
1706
|
+
// first check if this._prod is valid (not `NO`)
|
|
1707
|
+
this._prod._stop();
|
|
1708
|
+
this._err = NO$1;
|
|
1709
|
+
this._stopID = NO$1;
|
|
1710
|
+
};
|
|
1711
|
+
Stream.prototype._add = function (il) {
|
|
1712
|
+
var ta = this._target;
|
|
1713
|
+
if (ta)
|
|
1714
|
+
return ta._add(il);
|
|
1715
|
+
var a = this._ils;
|
|
1716
|
+
a.push(il);
|
|
1717
|
+
if (a.length > 1)
|
|
1718
|
+
return;
|
|
1719
|
+
if (this._stopID !== NO$1) {
|
|
1720
|
+
clearTimeout(this._stopID);
|
|
1721
|
+
this._stopID = NO$1;
|
|
1722
|
+
}
|
|
1723
|
+
else {
|
|
1724
|
+
var p = this._prod;
|
|
1725
|
+
if (p !== NO$1)
|
|
1726
|
+
p._start(this);
|
|
1727
|
+
}
|
|
1728
|
+
};
|
|
1729
|
+
Stream.prototype._remove = function (il) {
|
|
1730
|
+
var _this = this;
|
|
1731
|
+
var ta = this._target;
|
|
1732
|
+
if (ta)
|
|
1733
|
+
return ta._remove(il);
|
|
1734
|
+
var a = this._ils;
|
|
1735
|
+
var i = a.indexOf(il);
|
|
1736
|
+
if (i > -1) {
|
|
1737
|
+
a.splice(i, 1);
|
|
1738
|
+
if (this._prod !== NO$1 && a.length <= 0) {
|
|
1739
|
+
this._err = NO$1;
|
|
1740
|
+
this._stopID = setTimeout(function () { return _this._stopNow(); });
|
|
1741
|
+
}
|
|
1742
|
+
else if (a.length === 1) {
|
|
1743
|
+
this._pruneCycles();
|
|
31
1744
|
}
|
|
1745
|
+
}
|
|
1746
|
+
};
|
|
1747
|
+
// If all paths stemming from `this` stream eventually end at `this`
|
|
1748
|
+
// stream, then we remove the single listener of `this` stream, to
|
|
1749
|
+
// force it to end its execution and dispose resources. This method
|
|
1750
|
+
// assumes as a precondition that this._ils has just one listener.
|
|
1751
|
+
Stream.prototype._pruneCycles = function () {
|
|
1752
|
+
if (this._hasNoSinks(this, []))
|
|
1753
|
+
this._remove(this._ils[0]);
|
|
1754
|
+
};
|
|
1755
|
+
// Checks whether *there is no* path starting from `x` that leads to an end
|
|
1756
|
+
// listener (sink) in the stream graph, following edges A->B where B is a
|
|
1757
|
+
// listener of A. This means these paths constitute a cycle somehow. Is given
|
|
1758
|
+
// a trace of all visited nodes so far.
|
|
1759
|
+
Stream.prototype._hasNoSinks = function (x, trace) {
|
|
1760
|
+
if (trace.indexOf(x) !== -1)
|
|
1761
|
+
return true;
|
|
1762
|
+
else if (x.out === this)
|
|
1763
|
+
return true;
|
|
1764
|
+
else if (x.out && x.out !== NO$1)
|
|
1765
|
+
return this._hasNoSinks(x.out, trace.concat(x));
|
|
1766
|
+
else if (x._ils) {
|
|
1767
|
+
for (var i = 0, N = x._ils.length; i < N; i++)
|
|
1768
|
+
if (!this._hasNoSinks(x._ils[i], trace.concat(x)))
|
|
1769
|
+
return false;
|
|
1770
|
+
return true;
|
|
1771
|
+
}
|
|
1772
|
+
else
|
|
1773
|
+
return false;
|
|
1774
|
+
};
|
|
1775
|
+
Stream.prototype.ctor = function () {
|
|
1776
|
+
return this instanceof MemoryStream ? MemoryStream : Stream;
|
|
1777
|
+
};
|
|
1778
|
+
/**
|
|
1779
|
+
* Adds a Listener to the Stream.
|
|
1780
|
+
*
|
|
1781
|
+
* @param {Listener} listener
|
|
1782
|
+
*/
|
|
1783
|
+
Stream.prototype.addListener = function (listener) {
|
|
1784
|
+
listener._n = listener.next || noop;
|
|
1785
|
+
listener._e = listener.error || noop;
|
|
1786
|
+
listener._c = listener.complete || noop;
|
|
1787
|
+
this._add(listener);
|
|
1788
|
+
};
|
|
1789
|
+
/**
|
|
1790
|
+
* Removes a Listener from the Stream, assuming the Listener was added to it.
|
|
1791
|
+
*
|
|
1792
|
+
* @param {Listener<T>} listener
|
|
1793
|
+
*/
|
|
1794
|
+
Stream.prototype.removeListener = function (listener) {
|
|
1795
|
+
this._remove(listener);
|
|
1796
|
+
};
|
|
1797
|
+
/**
|
|
1798
|
+
* Adds a Listener to the Stream returning a Subscription to remove that
|
|
1799
|
+
* listener.
|
|
1800
|
+
*
|
|
1801
|
+
* @param {Listener} listener
|
|
1802
|
+
* @returns {Subscription}
|
|
1803
|
+
*/
|
|
1804
|
+
Stream.prototype.subscribe = function (listener) {
|
|
1805
|
+
this.addListener(listener);
|
|
1806
|
+
return new StreamSub(this, listener);
|
|
1807
|
+
};
|
|
1808
|
+
/**
|
|
1809
|
+
* Add interop between most.js and RxJS 5
|
|
1810
|
+
*
|
|
1811
|
+
* @returns {Stream}
|
|
1812
|
+
*/
|
|
1813
|
+
Stream.prototype[$$observable] = function () {
|
|
1814
|
+
return this;
|
|
1815
|
+
};
|
|
1816
|
+
/**
|
|
1817
|
+
* Creates a new Stream given a Producer.
|
|
1818
|
+
*
|
|
1819
|
+
* @factory true
|
|
1820
|
+
* @param {Producer} producer An optional Producer that dictates how to
|
|
1821
|
+
* start, generate events, and stop the Stream.
|
|
1822
|
+
* @return {Stream}
|
|
1823
|
+
*/
|
|
1824
|
+
Stream.create = function (producer) {
|
|
1825
|
+
if (producer) {
|
|
1826
|
+
if (typeof producer.start !== 'function'
|
|
1827
|
+
|| typeof producer.stop !== 'function')
|
|
1828
|
+
throw new Error('producer requires both start and stop functions');
|
|
1829
|
+
internalizeProducer(producer); // mutates the input
|
|
1830
|
+
}
|
|
1831
|
+
return new Stream(producer);
|
|
1832
|
+
};
|
|
1833
|
+
/**
|
|
1834
|
+
* Creates a new MemoryStream given a Producer.
|
|
1835
|
+
*
|
|
1836
|
+
* @factory true
|
|
1837
|
+
* @param {Producer} producer An optional Producer that dictates how to
|
|
1838
|
+
* start, generate events, and stop the Stream.
|
|
1839
|
+
* @return {MemoryStream}
|
|
1840
|
+
*/
|
|
1841
|
+
Stream.createWithMemory = function (producer) {
|
|
1842
|
+
if (producer)
|
|
1843
|
+
internalizeProducer(producer); // mutates the input
|
|
1844
|
+
return new MemoryStream(producer);
|
|
1845
|
+
};
|
|
1846
|
+
/**
|
|
1847
|
+
* Creates a Stream that does nothing when started. It never emits any event.
|
|
1848
|
+
*
|
|
1849
|
+
* Marble diagram:
|
|
1850
|
+
*
|
|
1851
|
+
* ```text
|
|
1852
|
+
* never
|
|
1853
|
+
* -----------------------
|
|
1854
|
+
* ```
|
|
1855
|
+
*
|
|
1856
|
+
* @factory true
|
|
1857
|
+
* @return {Stream}
|
|
1858
|
+
*/
|
|
1859
|
+
Stream.never = function () {
|
|
1860
|
+
return new Stream({ _start: noop, _stop: noop });
|
|
1861
|
+
};
|
|
1862
|
+
/**
|
|
1863
|
+
* Creates a Stream that immediately emits the "complete" notification when
|
|
1864
|
+
* started, and that's it.
|
|
1865
|
+
*
|
|
1866
|
+
* Marble diagram:
|
|
1867
|
+
*
|
|
1868
|
+
* ```text
|
|
1869
|
+
* empty
|
|
1870
|
+
* -|
|
|
1871
|
+
* ```
|
|
1872
|
+
*
|
|
1873
|
+
* @factory true
|
|
1874
|
+
* @return {Stream}
|
|
1875
|
+
*/
|
|
1876
|
+
Stream.empty = function () {
|
|
1877
|
+
return new Stream({
|
|
1878
|
+
_start: function (il) { il._c(); },
|
|
1879
|
+
_stop: noop,
|
|
32
1880
|
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
1881
|
+
};
|
|
1882
|
+
/**
|
|
1883
|
+
* Creates a Stream that immediately emits an "error" notification with the
|
|
1884
|
+
* value you passed as the `error` argument when the stream starts, and that's
|
|
1885
|
+
* it.
|
|
1886
|
+
*
|
|
1887
|
+
* Marble diagram:
|
|
1888
|
+
*
|
|
1889
|
+
* ```text
|
|
1890
|
+
* throw(X)
|
|
1891
|
+
* -X
|
|
1892
|
+
* ```
|
|
1893
|
+
*
|
|
1894
|
+
* @factory true
|
|
1895
|
+
* @param error The error event to emit on the created stream.
|
|
1896
|
+
* @return {Stream}
|
|
1897
|
+
*/
|
|
1898
|
+
Stream.throw = function (error) {
|
|
1899
|
+
return new Stream({
|
|
1900
|
+
_start: function (il) { il._e(error); },
|
|
1901
|
+
_stop: noop,
|
|
1902
|
+
});
|
|
1903
|
+
};
|
|
1904
|
+
/**
|
|
1905
|
+
* Creates a stream from an Array, Promise, or an Observable.
|
|
1906
|
+
*
|
|
1907
|
+
* @factory true
|
|
1908
|
+
* @param {Array|PromiseLike|Observable} input The input to make a stream from.
|
|
1909
|
+
* @return {Stream}
|
|
1910
|
+
*/
|
|
1911
|
+
Stream.from = function (input) {
|
|
1912
|
+
if (typeof input[$$observable] === 'function')
|
|
1913
|
+
return Stream.fromObservable(input);
|
|
1914
|
+
else if (typeof input.then === 'function')
|
|
1915
|
+
return Stream.fromPromise(input);
|
|
1916
|
+
else if (Array.isArray(input))
|
|
1917
|
+
return Stream.fromArray(input);
|
|
1918
|
+
throw new TypeError("Type of input to from() must be an Array, Promise, or Observable");
|
|
1919
|
+
};
|
|
1920
|
+
/**
|
|
1921
|
+
* Creates a Stream that immediately emits the arguments that you give to
|
|
1922
|
+
* *of*, then completes.
|
|
1923
|
+
*
|
|
1924
|
+
* Marble diagram:
|
|
1925
|
+
*
|
|
1926
|
+
* ```text
|
|
1927
|
+
* of(1,2,3)
|
|
1928
|
+
* 123|
|
|
1929
|
+
* ```
|
|
1930
|
+
*
|
|
1931
|
+
* @factory true
|
|
1932
|
+
* @param a The first value you want to emit as an event on the stream.
|
|
1933
|
+
* @param b The second value you want to emit as an event on the stream. One
|
|
1934
|
+
* or more of these values may be given as arguments.
|
|
1935
|
+
* @return {Stream}
|
|
1936
|
+
*/
|
|
1937
|
+
Stream.of = function () {
|
|
1938
|
+
var items = [];
|
|
1939
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1940
|
+
items[_i] = arguments[_i];
|
|
1941
|
+
}
|
|
1942
|
+
return Stream.fromArray(items);
|
|
1943
|
+
};
|
|
1944
|
+
/**
|
|
1945
|
+
* Converts an array to a stream. The returned stream will emit synchronously
|
|
1946
|
+
* all the items in the array, and then complete.
|
|
1947
|
+
*
|
|
1948
|
+
* Marble diagram:
|
|
1949
|
+
*
|
|
1950
|
+
* ```text
|
|
1951
|
+
* fromArray([1,2,3])
|
|
1952
|
+
* 123|
|
|
1953
|
+
* ```
|
|
1954
|
+
*
|
|
1955
|
+
* @factory true
|
|
1956
|
+
* @param {Array} array The array to be converted as a stream.
|
|
1957
|
+
* @return {Stream}
|
|
1958
|
+
*/
|
|
1959
|
+
Stream.fromArray = function (array) {
|
|
1960
|
+
return new Stream(new FromArray(array));
|
|
1961
|
+
};
|
|
1962
|
+
/**
|
|
1963
|
+
* Converts a promise to a stream. The returned stream will emit the resolved
|
|
1964
|
+
* value of the promise, and then complete. However, if the promise is
|
|
1965
|
+
* rejected, the stream will emit the corresponding error.
|
|
1966
|
+
*
|
|
1967
|
+
* Marble diagram:
|
|
1968
|
+
*
|
|
1969
|
+
* ```text
|
|
1970
|
+
* fromPromise( ----42 )
|
|
1971
|
+
* -----------------42|
|
|
1972
|
+
* ```
|
|
1973
|
+
*
|
|
1974
|
+
* @factory true
|
|
1975
|
+
* @param {PromiseLike} promise The promise to be converted as a stream.
|
|
1976
|
+
* @return {Stream}
|
|
1977
|
+
*/
|
|
1978
|
+
Stream.fromPromise = function (promise) {
|
|
1979
|
+
return new Stream(new FromPromise(promise));
|
|
1980
|
+
};
|
|
1981
|
+
/**
|
|
1982
|
+
* Converts an Observable into a Stream.
|
|
1983
|
+
*
|
|
1984
|
+
* @factory true
|
|
1985
|
+
* @param {any} observable The observable to be converted as a stream.
|
|
1986
|
+
* @return {Stream}
|
|
1987
|
+
*/
|
|
1988
|
+
Stream.fromObservable = function (obs) {
|
|
1989
|
+
if (obs.endWhen !== undefined)
|
|
1990
|
+
return obs;
|
|
1991
|
+
var o = typeof obs[$$observable] === 'function' ? obs[$$observable]() : obs;
|
|
1992
|
+
return new Stream(new FromObservable(o));
|
|
1993
|
+
};
|
|
1994
|
+
/**
|
|
1995
|
+
* Creates a stream that periodically emits incremental numbers, every
|
|
1996
|
+
* `period` milliseconds.
|
|
1997
|
+
*
|
|
1998
|
+
* Marble diagram:
|
|
1999
|
+
*
|
|
2000
|
+
* ```text
|
|
2001
|
+
* periodic(1000)
|
|
2002
|
+
* ---0---1---2---3---4---...
|
|
2003
|
+
* ```
|
|
2004
|
+
*
|
|
2005
|
+
* @factory true
|
|
2006
|
+
* @param {number} period The interval in milliseconds to use as a rate of
|
|
2007
|
+
* emission.
|
|
2008
|
+
* @return {Stream}
|
|
2009
|
+
*/
|
|
2010
|
+
Stream.periodic = function (period) {
|
|
2011
|
+
return new Stream(new Periodic(period));
|
|
2012
|
+
};
|
|
2013
|
+
Stream.prototype._map = function (project) {
|
|
2014
|
+
return new (this.ctor())(new MapOp(project, this));
|
|
2015
|
+
};
|
|
2016
|
+
/**
|
|
2017
|
+
* Transforms each event from the input Stream through a `project` function,
|
|
2018
|
+
* to get a Stream that emits those transformed events.
|
|
2019
|
+
*
|
|
2020
|
+
* Marble diagram:
|
|
2021
|
+
*
|
|
2022
|
+
* ```text
|
|
2023
|
+
* --1---3--5-----7------
|
|
2024
|
+
* map(i => i * 10)
|
|
2025
|
+
* --10--30-50----70-----
|
|
2026
|
+
* ```
|
|
2027
|
+
*
|
|
2028
|
+
* @param {Function} project A function of type `(t: T) => U` that takes event
|
|
2029
|
+
* `t` of type `T` from the input Stream and produces an event of type `U`, to
|
|
2030
|
+
* be emitted on the output Stream.
|
|
2031
|
+
* @return {Stream}
|
|
2032
|
+
*/
|
|
2033
|
+
Stream.prototype.map = function (project) {
|
|
2034
|
+
return this._map(project);
|
|
2035
|
+
};
|
|
2036
|
+
/**
|
|
2037
|
+
* It's like `map`, but transforms each input event to always the same
|
|
2038
|
+
* constant value on the output Stream.
|
|
2039
|
+
*
|
|
2040
|
+
* Marble diagram:
|
|
2041
|
+
*
|
|
2042
|
+
* ```text
|
|
2043
|
+
* --1---3--5-----7-----
|
|
2044
|
+
* mapTo(10)
|
|
2045
|
+
* --10--10-10----10----
|
|
2046
|
+
* ```
|
|
2047
|
+
*
|
|
2048
|
+
* @param projectedValue A value to emit on the output Stream whenever the
|
|
2049
|
+
* input Stream emits any value.
|
|
2050
|
+
* @return {Stream}
|
|
2051
|
+
*/
|
|
2052
|
+
Stream.prototype.mapTo = function (projectedValue) {
|
|
2053
|
+
var s = this.map(function () { return projectedValue; });
|
|
2054
|
+
var op = s._prod;
|
|
2055
|
+
op.type = 'mapTo';
|
|
2056
|
+
return s;
|
|
2057
|
+
};
|
|
2058
|
+
/**
|
|
2059
|
+
* Only allows events that pass the test given by the `passes` argument.
|
|
2060
|
+
*
|
|
2061
|
+
* Each event from the input stream is given to the `passes` function. If the
|
|
2062
|
+
* function returns `true`, the event is forwarded to the output stream,
|
|
2063
|
+
* otherwise it is ignored and not forwarded.
|
|
2064
|
+
*
|
|
2065
|
+
* Marble diagram:
|
|
2066
|
+
*
|
|
2067
|
+
* ```text
|
|
2068
|
+
* --1---2--3-----4-----5---6--7-8--
|
|
2069
|
+
* filter(i => i % 2 === 0)
|
|
2070
|
+
* ------2--------4---------6----8--
|
|
2071
|
+
* ```
|
|
2072
|
+
*
|
|
2073
|
+
* @param {Function} passes A function of type `(t: T) => boolean` that takes
|
|
2074
|
+
* an event from the input stream and checks if it passes, by returning a
|
|
2075
|
+
* boolean.
|
|
2076
|
+
* @return {Stream}
|
|
2077
|
+
*/
|
|
2078
|
+
Stream.prototype.filter = function (passes) {
|
|
2079
|
+
var p = this._prod;
|
|
2080
|
+
if (p instanceof Filter)
|
|
2081
|
+
return new Stream(new Filter(and(p.f, passes), p.ins));
|
|
2082
|
+
return new Stream(new Filter(passes, this));
|
|
2083
|
+
};
|
|
2084
|
+
/**
|
|
2085
|
+
* Lets the first `amount` many events from the input stream pass to the
|
|
2086
|
+
* output stream, then makes the output stream complete.
|
|
2087
|
+
*
|
|
2088
|
+
* Marble diagram:
|
|
2089
|
+
*
|
|
2090
|
+
* ```text
|
|
2091
|
+
* --a---b--c----d---e--
|
|
2092
|
+
* take(3)
|
|
2093
|
+
* --a---b--c|
|
|
2094
|
+
* ```
|
|
2095
|
+
*
|
|
2096
|
+
* @param {number} amount How many events to allow from the input stream
|
|
2097
|
+
* before completing the output stream.
|
|
2098
|
+
* @return {Stream}
|
|
2099
|
+
*/
|
|
2100
|
+
Stream.prototype.take = function (amount) {
|
|
2101
|
+
return new (this.ctor())(new Take(amount, this));
|
|
2102
|
+
};
|
|
2103
|
+
/**
|
|
2104
|
+
* Ignores the first `amount` many events from the input stream, and then
|
|
2105
|
+
* after that starts forwarding events from the input stream to the output
|
|
2106
|
+
* stream.
|
|
2107
|
+
*
|
|
2108
|
+
* Marble diagram:
|
|
2109
|
+
*
|
|
2110
|
+
* ```text
|
|
2111
|
+
* --a---b--c----d---e--
|
|
2112
|
+
* drop(3)
|
|
2113
|
+
* --------------d---e--
|
|
2114
|
+
* ```
|
|
2115
|
+
*
|
|
2116
|
+
* @param {number} amount How many events to ignore from the input stream
|
|
2117
|
+
* before forwarding all events from the input stream to the output stream.
|
|
2118
|
+
* @return {Stream}
|
|
2119
|
+
*/
|
|
2120
|
+
Stream.prototype.drop = function (amount) {
|
|
2121
|
+
return new Stream(new Drop(amount, this));
|
|
2122
|
+
};
|
|
2123
|
+
/**
|
|
2124
|
+
* When the input stream completes, the output stream will emit the last event
|
|
2125
|
+
* emitted by the input stream, and then will also complete.
|
|
2126
|
+
*
|
|
2127
|
+
* Marble diagram:
|
|
2128
|
+
*
|
|
2129
|
+
* ```text
|
|
2130
|
+
* --a---b--c--d----|
|
|
2131
|
+
* last()
|
|
2132
|
+
* -----------------d|
|
|
2133
|
+
* ```
|
|
2134
|
+
*
|
|
2135
|
+
* @return {Stream}
|
|
2136
|
+
*/
|
|
2137
|
+
Stream.prototype.last = function () {
|
|
2138
|
+
return new Stream(new Last(this));
|
|
2139
|
+
};
|
|
2140
|
+
/**
|
|
2141
|
+
* Prepends the given `initial` value to the sequence of events emitted by the
|
|
2142
|
+
* input stream. The returned stream is a MemoryStream, which means it is
|
|
2143
|
+
* already `remember()`'d.
|
|
2144
|
+
*
|
|
2145
|
+
* Marble diagram:
|
|
2146
|
+
*
|
|
2147
|
+
* ```text
|
|
2148
|
+
* ---1---2-----3---
|
|
2149
|
+
* startWith(0)
|
|
2150
|
+
* 0--1---2-----3---
|
|
2151
|
+
* ```
|
|
2152
|
+
*
|
|
2153
|
+
* @param initial The value or event to prepend.
|
|
2154
|
+
* @return {MemoryStream}
|
|
2155
|
+
*/
|
|
2156
|
+
Stream.prototype.startWith = function (initial) {
|
|
2157
|
+
return new MemoryStream(new StartWith(this, initial));
|
|
2158
|
+
};
|
|
2159
|
+
/**
|
|
2160
|
+
* Uses another stream to determine when to complete the current stream.
|
|
2161
|
+
*
|
|
2162
|
+
* When the given `other` stream emits an event or completes, the output
|
|
2163
|
+
* stream will complete. Before that happens, the output stream will behaves
|
|
2164
|
+
* like the input stream.
|
|
2165
|
+
*
|
|
2166
|
+
* Marble diagram:
|
|
2167
|
+
*
|
|
2168
|
+
* ```text
|
|
2169
|
+
* ---1---2-----3--4----5----6---
|
|
2170
|
+
* endWhen( --------a--b--| )
|
|
2171
|
+
* ---1---2-----3--4--|
|
|
2172
|
+
* ```
|
|
2173
|
+
*
|
|
2174
|
+
* @param other Some other stream that is used to know when should the output
|
|
2175
|
+
* stream of this operator complete.
|
|
2176
|
+
* @return {Stream}
|
|
2177
|
+
*/
|
|
2178
|
+
Stream.prototype.endWhen = function (other) {
|
|
2179
|
+
return new (this.ctor())(new EndWhen(other, this));
|
|
2180
|
+
};
|
|
2181
|
+
/**
|
|
2182
|
+
* "Folds" the stream onto itself.
|
|
2183
|
+
*
|
|
2184
|
+
* Combines events from the past throughout
|
|
2185
|
+
* the entire execution of the input stream, allowing you to accumulate them
|
|
2186
|
+
* together. It's essentially like `Array.prototype.reduce`. The returned
|
|
2187
|
+
* stream is a MemoryStream, which means it is already `remember()`'d.
|
|
2188
|
+
*
|
|
2189
|
+
* The output stream starts by emitting the `seed` which you give as argument.
|
|
2190
|
+
* Then, when an event happens on the input stream, it is combined with that
|
|
2191
|
+
* seed value through the `accumulate` function, and the output value is
|
|
2192
|
+
* emitted on the output stream. `fold` remembers that output value as `acc`
|
|
2193
|
+
* ("accumulator"), and then when a new input event `t` happens, `acc` will be
|
|
2194
|
+
* combined with that to produce the new `acc` and so forth.
|
|
2195
|
+
*
|
|
2196
|
+
* Marble diagram:
|
|
2197
|
+
*
|
|
2198
|
+
* ```text
|
|
2199
|
+
* ------1-----1--2----1----1------
|
|
2200
|
+
* fold((acc, x) => acc + x, 3)
|
|
2201
|
+
* 3-----4-----5--7----8----9------
|
|
2202
|
+
* ```
|
|
2203
|
+
*
|
|
2204
|
+
* @param {Function} accumulate A function of type `(acc: R, t: T) => R` that
|
|
2205
|
+
* takes the previous accumulated value `acc` and the incoming event from the
|
|
2206
|
+
* input stream and produces the new accumulated value.
|
|
2207
|
+
* @param seed The initial accumulated value, of type `R`.
|
|
2208
|
+
* @return {MemoryStream}
|
|
2209
|
+
*/
|
|
2210
|
+
Stream.prototype.fold = function (accumulate, seed) {
|
|
2211
|
+
return new MemoryStream(new Fold(accumulate, seed, this));
|
|
2212
|
+
};
|
|
2213
|
+
/**
|
|
2214
|
+
* Replaces an error with another stream.
|
|
2215
|
+
*
|
|
2216
|
+
* When (and if) an error happens on the input stream, instead of forwarding
|
|
2217
|
+
* that error to the output stream, *replaceError* will call the `replace`
|
|
2218
|
+
* function which returns the stream that the output stream will replicate.
|
|
2219
|
+
* And, in case that new stream also emits an error, `replace` will be called
|
|
2220
|
+
* again to get another stream to start replicating.
|
|
2221
|
+
*
|
|
2222
|
+
* Marble diagram:
|
|
2223
|
+
*
|
|
2224
|
+
* ```text
|
|
2225
|
+
* --1---2-----3--4-----X
|
|
2226
|
+
* replaceError( () => --10--| )
|
|
2227
|
+
* --1---2-----3--4--------10--|
|
|
2228
|
+
* ```
|
|
2229
|
+
*
|
|
2230
|
+
* @param {Function} replace A function of type `(err) => Stream` that takes
|
|
2231
|
+
* the error that occurred on the input stream or on the previous replacement
|
|
2232
|
+
* stream and returns a new stream. The output stream will behave like the
|
|
2233
|
+
* stream that this function returns.
|
|
2234
|
+
* @return {Stream}
|
|
2235
|
+
*/
|
|
2236
|
+
Stream.prototype.replaceError = function (replace) {
|
|
2237
|
+
return new (this.ctor())(new ReplaceError(replace, this));
|
|
2238
|
+
};
|
|
2239
|
+
/**
|
|
2240
|
+
* Flattens a "stream of streams", handling only one nested stream at a time
|
|
2241
|
+
* (no concurrency).
|
|
2242
|
+
*
|
|
2243
|
+
* If the input stream is a stream that emits streams, then this operator will
|
|
2244
|
+
* return an output stream which is a flat stream: emits regular events. The
|
|
2245
|
+
* flattening happens without concurrency. It works like this: when the input
|
|
2246
|
+
* stream emits a nested stream, *flatten* will start imitating that nested
|
|
2247
|
+
* one. However, as soon as the next nested stream is emitted on the input
|
|
2248
|
+
* stream, *flatten* will forget the previous nested one it was imitating, and
|
|
2249
|
+
* will start imitating the new nested one.
|
|
2250
|
+
*
|
|
2251
|
+
* Marble diagram:
|
|
2252
|
+
*
|
|
2253
|
+
* ```text
|
|
2254
|
+
* --+--------+---------------
|
|
2255
|
+
* \ \
|
|
2256
|
+
* \ ----1----2---3--
|
|
2257
|
+
* --a--b----c----d--------
|
|
2258
|
+
* flatten
|
|
2259
|
+
* -----a--b------1----2---3--
|
|
2260
|
+
* ```
|
|
2261
|
+
*
|
|
2262
|
+
* @return {Stream}
|
|
2263
|
+
*/
|
|
2264
|
+
Stream.prototype.flatten = function () {
|
|
2265
|
+
return new Stream(new Flatten(this));
|
|
2266
|
+
};
|
|
2267
|
+
/**
|
|
2268
|
+
* Passes the input stream to a custom operator, to produce an output stream.
|
|
2269
|
+
*
|
|
2270
|
+
* *compose* is a handy way of using an existing function in a chained style.
|
|
2271
|
+
* Instead of writing `outStream = f(inStream)` you can write
|
|
2272
|
+
* `outStream = inStream.compose(f)`.
|
|
2273
|
+
*
|
|
2274
|
+
* @param {function} operator A function that takes a stream as input and
|
|
2275
|
+
* returns a stream as well.
|
|
2276
|
+
* @return {Stream}
|
|
2277
|
+
*/
|
|
2278
|
+
Stream.prototype.compose = function (operator) {
|
|
2279
|
+
return operator(this);
|
|
2280
|
+
};
|
|
2281
|
+
/**
|
|
2282
|
+
* Returns an output stream that behaves like the input stream, but also
|
|
2283
|
+
* remembers the most recent event that happens on the input stream, so that a
|
|
2284
|
+
* newly added listener will immediately receive that memorised event.
|
|
2285
|
+
*
|
|
2286
|
+
* @return {MemoryStream}
|
|
2287
|
+
*/
|
|
2288
|
+
Stream.prototype.remember = function () {
|
|
2289
|
+
return new MemoryStream(new Remember(this));
|
|
2290
|
+
};
|
|
2291
|
+
/**
|
|
2292
|
+
* Returns an output stream that identically behaves like the input stream,
|
|
2293
|
+
* but also runs a `spy` function for each event, to help you debug your app.
|
|
2294
|
+
*
|
|
2295
|
+
* *debug* takes a `spy` function as argument, and runs that for each event
|
|
2296
|
+
* happening on the input stream. If you don't provide the `spy` argument,
|
|
2297
|
+
* then *debug* will just `console.log` each event. This helps you to
|
|
2298
|
+
* understand the flow of events through some operator chain.
|
|
2299
|
+
*
|
|
2300
|
+
* Please note that if the output stream has no listeners, then it will not
|
|
2301
|
+
* start, which means `spy` will never run because no actual event happens in
|
|
2302
|
+
* that case.
|
|
2303
|
+
*
|
|
2304
|
+
* Marble diagram:
|
|
2305
|
+
*
|
|
2306
|
+
* ```text
|
|
2307
|
+
* --1----2-----3-----4--
|
|
2308
|
+
* debug
|
|
2309
|
+
* --1----2-----3-----4--
|
|
2310
|
+
* ```
|
|
2311
|
+
*
|
|
2312
|
+
* @param {function} labelOrSpy A string to use as the label when printing
|
|
2313
|
+
* debug information on the console, or a 'spy' function that takes an event
|
|
2314
|
+
* as argument, and does not need to return anything.
|
|
2315
|
+
* @return {Stream}
|
|
2316
|
+
*/
|
|
2317
|
+
Stream.prototype.debug = function (labelOrSpy) {
|
|
2318
|
+
return new (this.ctor())(new Debug(this, labelOrSpy));
|
|
2319
|
+
};
|
|
2320
|
+
/**
|
|
2321
|
+
* *imitate* changes this current Stream to emit the same events that the
|
|
2322
|
+
* `other` given Stream does. This method returns nothing.
|
|
2323
|
+
*
|
|
2324
|
+
* This method exists to allow one thing: **circular dependency of streams**.
|
|
2325
|
+
* For instance, let's imagine that for some reason you need to create a
|
|
2326
|
+
* circular dependency where stream `first$` depends on stream `second$`
|
|
2327
|
+
* which in turn depends on `first$`:
|
|
2328
|
+
*
|
|
2329
|
+
* <!-- skip-example -->
|
|
2330
|
+
* ```js
|
|
2331
|
+
* import delay from 'xstream/extra/delay'
|
|
2332
|
+
*
|
|
2333
|
+
* var first$ = second$.map(x => x * 10).take(3);
|
|
2334
|
+
* var second$ = first$.map(x => x + 1).startWith(1).compose(delay(100));
|
|
2335
|
+
* ```
|
|
2336
|
+
*
|
|
2337
|
+
* However, that is invalid JavaScript, because `second$` is undefined
|
|
2338
|
+
* on the first line. This is how *imitate* can help solve it:
|
|
2339
|
+
*
|
|
2340
|
+
* ```js
|
|
2341
|
+
* import delay from 'xstream/extra/delay'
|
|
2342
|
+
*
|
|
2343
|
+
* var secondProxy$ = xs.create();
|
|
2344
|
+
* var first$ = secondProxy$.map(x => x * 10).take(3);
|
|
2345
|
+
* var second$ = first$.map(x => x + 1).startWith(1).compose(delay(100));
|
|
2346
|
+
* secondProxy$.imitate(second$);
|
|
2347
|
+
* ```
|
|
2348
|
+
*
|
|
2349
|
+
* We create `secondProxy$` before the others, so it can be used in the
|
|
2350
|
+
* declaration of `first$`. Then, after both `first$` and `second$` are
|
|
2351
|
+
* defined, we hook `secondProxy$` with `second$` with `imitate()` to tell
|
|
2352
|
+
* that they are "the same". `imitate` will not trigger the start of any
|
|
2353
|
+
* stream, it just binds `secondProxy$` and `second$` together.
|
|
2354
|
+
*
|
|
2355
|
+
* The following is an example where `imitate()` is important in Cycle.js
|
|
2356
|
+
* applications. A parent component contains some child components. A child
|
|
2357
|
+
* has an action stream which is given to the parent to define its state:
|
|
2358
|
+
*
|
|
2359
|
+
* <!-- skip-example -->
|
|
2360
|
+
* ```js
|
|
2361
|
+
* const childActionProxy$ = xs.create();
|
|
2362
|
+
* const parent = Parent({...sources, childAction$: childActionProxy$});
|
|
2363
|
+
* const childAction$ = parent.state$.map(s => s.child.action$).flatten();
|
|
2364
|
+
* childActionProxy$.imitate(childAction$);
|
|
2365
|
+
* ```
|
|
2366
|
+
*
|
|
2367
|
+
* Note, though, that **`imitate()` does not support MemoryStreams**. If we
|
|
2368
|
+
* would attempt to imitate a MemoryStream in a circular dependency, we would
|
|
2369
|
+
* either get a race condition (where the symptom would be "nothing happens")
|
|
2370
|
+
* or an infinite cyclic emission of values. It's useful to think about
|
|
2371
|
+
* MemoryStreams as cells in a spreadsheet. It doesn't make any sense to
|
|
2372
|
+
* define a spreadsheet cell `A1` with a formula that depends on `B1` and
|
|
2373
|
+
* cell `B1` defined with a formula that depends on `A1`.
|
|
2374
|
+
*
|
|
2375
|
+
* If you find yourself wanting to use `imitate()` with a
|
|
2376
|
+
* MemoryStream, you should rework your code around `imitate()` to use a
|
|
2377
|
+
* Stream instead. Look for the stream in the circular dependency that
|
|
2378
|
+
* represents an event stream, and that would be a candidate for creating a
|
|
2379
|
+
* proxy Stream which then imitates the target Stream.
|
|
2380
|
+
*
|
|
2381
|
+
* @param {Stream} target The other stream to imitate on the current one. Must
|
|
2382
|
+
* not be a MemoryStream.
|
|
2383
|
+
*/
|
|
2384
|
+
Stream.prototype.imitate = function (target) {
|
|
2385
|
+
if (target instanceof MemoryStream)
|
|
2386
|
+
throw new Error('A MemoryStream was given to imitate(), but it only ' +
|
|
2387
|
+
'supports a Stream. Read more about this restriction here: ' +
|
|
2388
|
+
'https://github.com/staltz/xstream#faq');
|
|
2389
|
+
this._target = target;
|
|
2390
|
+
for (var ils = this._ils, N = ils.length, i = 0; i < N; i++)
|
|
2391
|
+
target._add(ils[i]);
|
|
2392
|
+
this._ils = [];
|
|
2393
|
+
};
|
|
2394
|
+
/**
|
|
2395
|
+
* Forces the Stream to emit the given value to its listeners.
|
|
2396
|
+
*
|
|
2397
|
+
* As the name indicates, if you use this, you are most likely doing something
|
|
2398
|
+
* The Wrong Way. Please try to understand the reactive way before using this
|
|
2399
|
+
* method. Use it only when you know what you are doing.
|
|
2400
|
+
*
|
|
2401
|
+
* @param value The "next" value you want to broadcast to all listeners of
|
|
2402
|
+
* this Stream.
|
|
2403
|
+
*/
|
|
2404
|
+
Stream.prototype.shamefullySendNext = function (value) {
|
|
2405
|
+
this._n(value);
|
|
2406
|
+
};
|
|
2407
|
+
/**
|
|
2408
|
+
* Forces the Stream to emit the given error to its listeners.
|
|
2409
|
+
*
|
|
2410
|
+
* As the name indicates, if you use this, you are most likely doing something
|
|
2411
|
+
* The Wrong Way. Please try to understand the reactive way before using this
|
|
2412
|
+
* method. Use it only when you know what you are doing.
|
|
2413
|
+
*
|
|
2414
|
+
* @param {any} error The error you want to broadcast to all the listeners of
|
|
2415
|
+
* this Stream.
|
|
2416
|
+
*/
|
|
2417
|
+
Stream.prototype.shamefullySendError = function (error) {
|
|
2418
|
+
this._e(error);
|
|
2419
|
+
};
|
|
2420
|
+
/**
|
|
2421
|
+
* Forces the Stream to emit the "completed" event to its listeners.
|
|
2422
|
+
*
|
|
2423
|
+
* As the name indicates, if you use this, you are most likely doing something
|
|
2424
|
+
* The Wrong Way. Please try to understand the reactive way before using this
|
|
2425
|
+
* method. Use it only when you know what you are doing.
|
|
2426
|
+
*/
|
|
2427
|
+
Stream.prototype.shamefullySendComplete = function () {
|
|
2428
|
+
this._c();
|
|
2429
|
+
};
|
|
2430
|
+
/**
|
|
2431
|
+
* Adds a "debug" listener to the stream. There can only be one debug
|
|
2432
|
+
* listener, that's why this is 'setDebugListener'. To remove the debug
|
|
2433
|
+
* listener, just call setDebugListener(null).
|
|
2434
|
+
*
|
|
2435
|
+
* A debug listener is like any other listener. The only difference is that a
|
|
2436
|
+
* debug listener is "stealthy": its presence/absence does not trigger the
|
|
2437
|
+
* start/stop of the stream (or the producer inside the stream). This is
|
|
2438
|
+
* useful so you can inspect what is going on without changing the behavior
|
|
2439
|
+
* of the program. If you have an idle stream and you add a normal listener to
|
|
2440
|
+
* it, the stream will start executing. But if you set a debug listener on an
|
|
2441
|
+
* idle stream, it won't start executing (not until the first normal listener
|
|
2442
|
+
* is added).
|
|
2443
|
+
*
|
|
2444
|
+
* As the name indicates, we don't recommend using this method to build app
|
|
2445
|
+
* logic. In fact, in most cases the debug operator works just fine. Only use
|
|
2446
|
+
* this one if you know what you're doing.
|
|
2447
|
+
*
|
|
2448
|
+
* @param {Listener<T>} listener
|
|
2449
|
+
*/
|
|
2450
|
+
Stream.prototype.setDebugListener = function (listener) {
|
|
2451
|
+
if (!listener) {
|
|
2452
|
+
this._d = false;
|
|
2453
|
+
this._dl = NO$1;
|
|
2454
|
+
}
|
|
2455
|
+
else {
|
|
2456
|
+
this._d = true;
|
|
2457
|
+
listener._n = listener.next || noop;
|
|
2458
|
+
listener._e = listener.error || noop;
|
|
2459
|
+
listener._c = listener.complete || noop;
|
|
2460
|
+
this._dl = listener;
|
|
2461
|
+
}
|
|
2462
|
+
};
|
|
2463
|
+
/**
|
|
2464
|
+
* Blends multiple streams together, emitting events from all of them
|
|
2465
|
+
* concurrently.
|
|
2466
|
+
*
|
|
2467
|
+
* *merge* takes multiple streams as arguments, and creates a stream that
|
|
2468
|
+
* behaves like each of the argument streams, in parallel.
|
|
2469
|
+
*
|
|
2470
|
+
* Marble diagram:
|
|
2471
|
+
*
|
|
2472
|
+
* ```text
|
|
2473
|
+
* --1----2-----3--------4---
|
|
2474
|
+
* ----a-----b----c---d------
|
|
2475
|
+
* merge
|
|
2476
|
+
* --1-a--2--b--3-c---d--4---
|
|
2477
|
+
* ```
|
|
2478
|
+
*
|
|
2479
|
+
* @factory true
|
|
2480
|
+
* @param {Stream} stream1 A stream to merge together with other streams.
|
|
2481
|
+
* @param {Stream} stream2 A stream to merge together with other streams. Two
|
|
2482
|
+
* or more streams may be given as arguments.
|
|
2483
|
+
* @return {Stream}
|
|
2484
|
+
*/
|
|
2485
|
+
Stream.merge = function merge() {
|
|
2486
|
+
var streams = [];
|
|
2487
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2488
|
+
streams[_i] = arguments[_i];
|
|
2489
|
+
}
|
|
2490
|
+
return new Stream(new Merge(streams));
|
|
2491
|
+
};
|
|
2492
|
+
/**
|
|
2493
|
+
* Combines multiple input streams together to return a stream whose events
|
|
2494
|
+
* are arrays that collect the latest events from each input stream.
|
|
2495
|
+
*
|
|
2496
|
+
* *combine* internally remembers the most recent event from each of the input
|
|
2497
|
+
* streams. When any of the input streams emits an event, that event together
|
|
2498
|
+
* with all the other saved events are combined into an array. That array will
|
|
2499
|
+
* be emitted on the output stream. It's essentially a way of joining together
|
|
2500
|
+
* the events from multiple streams.
|
|
2501
|
+
*
|
|
2502
|
+
* Marble diagram:
|
|
2503
|
+
*
|
|
2504
|
+
* ```text
|
|
2505
|
+
* --1----2-----3--------4---
|
|
2506
|
+
* ----a-----b-----c--d------
|
|
2507
|
+
* combine
|
|
2508
|
+
* ----1a-2a-2b-3b-3c-3d-4d--
|
|
2509
|
+
* ```
|
|
2510
|
+
*
|
|
2511
|
+
* @factory true
|
|
2512
|
+
* @param {Stream} stream1 A stream to combine together with other streams.
|
|
2513
|
+
* @param {Stream} stream2 A stream to combine together with other streams.
|
|
2514
|
+
* Multiple streams, not just two, may be given as arguments.
|
|
2515
|
+
* @return {Stream}
|
|
2516
|
+
*/
|
|
2517
|
+
Stream.combine = function combine() {
|
|
2518
|
+
var streams = [];
|
|
2519
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2520
|
+
streams[_i] = arguments[_i];
|
|
2521
|
+
}
|
|
2522
|
+
return new Stream(new Combine(streams));
|
|
2523
|
+
};
|
|
2524
|
+
return Stream;
|
|
2525
|
+
}());
|
|
2526
|
+
var Stream_1 = xstream.Stream = Stream$1;
|
|
2527
|
+
var MemoryStream = /** @class */ (function (_super) {
|
|
2528
|
+
__extends(MemoryStream, _super);
|
|
2529
|
+
function MemoryStream(producer) {
|
|
2530
|
+
var _this = _super.call(this, producer) || this;
|
|
2531
|
+
_this._has = false;
|
|
2532
|
+
return _this;
|
|
2533
|
+
}
|
|
2534
|
+
MemoryStream.prototype._n = function (x) {
|
|
2535
|
+
this._v = x;
|
|
2536
|
+
this._has = true;
|
|
2537
|
+
_super.prototype._n.call(this, x);
|
|
2538
|
+
};
|
|
2539
|
+
MemoryStream.prototype._add = function (il) {
|
|
2540
|
+
var ta = this._target;
|
|
2541
|
+
if (ta)
|
|
2542
|
+
return ta._add(il);
|
|
2543
|
+
var a = this._ils;
|
|
2544
|
+
a.push(il);
|
|
2545
|
+
if (a.length > 1) {
|
|
2546
|
+
if (this._has)
|
|
2547
|
+
il._n(this._v);
|
|
2548
|
+
return;
|
|
2549
|
+
}
|
|
2550
|
+
if (this._stopID !== NO$1) {
|
|
2551
|
+
if (this._has)
|
|
2552
|
+
il._n(this._v);
|
|
2553
|
+
clearTimeout(this._stopID);
|
|
2554
|
+
this._stopID = NO$1;
|
|
2555
|
+
}
|
|
2556
|
+
else if (this._has)
|
|
2557
|
+
il._n(this._v);
|
|
2558
|
+
else {
|
|
2559
|
+
var p = this._prod;
|
|
2560
|
+
if (p !== NO$1)
|
|
2561
|
+
p._start(this);
|
|
2562
|
+
}
|
|
2563
|
+
};
|
|
2564
|
+
MemoryStream.prototype._stopNow = function () {
|
|
2565
|
+
this._has = false;
|
|
2566
|
+
_super.prototype._stopNow.call(this);
|
|
2567
|
+
};
|
|
2568
|
+
MemoryStream.prototype._x = function () {
|
|
2569
|
+
this._has = false;
|
|
2570
|
+
_super.prototype._x.call(this);
|
|
2571
|
+
};
|
|
2572
|
+
MemoryStream.prototype.map = function (project) {
|
|
2573
|
+
return this._map(project);
|
|
2574
|
+
};
|
|
2575
|
+
MemoryStream.prototype.mapTo = function (projectedValue) {
|
|
2576
|
+
return _super.prototype.mapTo.call(this, projectedValue);
|
|
2577
|
+
};
|
|
2578
|
+
MemoryStream.prototype.take = function (amount) {
|
|
2579
|
+
return _super.prototype.take.call(this, amount);
|
|
2580
|
+
};
|
|
2581
|
+
MemoryStream.prototype.endWhen = function (other) {
|
|
2582
|
+
return _super.prototype.endWhen.call(this, other);
|
|
2583
|
+
};
|
|
2584
|
+
MemoryStream.prototype.replaceError = function (replace) {
|
|
2585
|
+
return _super.prototype.replaceError.call(this, replace);
|
|
2586
|
+
};
|
|
2587
|
+
MemoryStream.prototype.remember = function () {
|
|
2588
|
+
return this;
|
|
2589
|
+
};
|
|
2590
|
+
MemoryStream.prototype.debug = function (labelOrSpy) {
|
|
2591
|
+
return _super.prototype.debug.call(this, labelOrSpy);
|
|
2592
|
+
};
|
|
2593
|
+
return MemoryStream;
|
|
2594
|
+
}(Stream$1));
|
|
2595
|
+
var MemoryStream_1 = xstream.MemoryStream = MemoryStream;
|
|
2596
|
+
var xs$1 = Stream$1;
|
|
2597
|
+
var _default$5 = xstream.default = xs$1;
|
|
37
2598
|
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
2599
|
+
var xstreamNamespace = /*#__PURE__*/_mergeNamespaces({
|
|
2600
|
+
__proto__: null,
|
|
2601
|
+
get MemoryStream () { return MemoryStream_1; },
|
|
2602
|
+
get NO () { return NO_1; },
|
|
2603
|
+
get NO_IL () { return NO_IL_1; },
|
|
2604
|
+
get Stream () { return Stream_1; },
|
|
2605
|
+
default: _default$5
|
|
2606
|
+
}, [xstream]);
|
|
44
2607
|
|
|
45
2608
|
function getGlobal() {
|
|
46
2609
|
let globalObj;
|
|
@@ -66,7 +2629,7 @@ function makeSinkProxies(drivers) {
|
|
|
66
2629
|
const sinkProxies = {};
|
|
67
2630
|
for (const name in drivers) {
|
|
68
2631
|
if (Object.prototype.hasOwnProperty.call(drivers, name)) {
|
|
69
|
-
sinkProxies[name] =
|
|
2632
|
+
sinkProxies[name] = _default$5.create();
|
|
70
2633
|
}
|
|
71
2634
|
}
|
|
72
2635
|
return sinkProxies;
|
|
@@ -107,7 +2670,7 @@ function replicateMany(sinks, sinkProxies) {
|
|
|
107
2670
|
complete: () => { },
|
|
108
2671
|
};
|
|
109
2672
|
});
|
|
110
|
-
const subscriptions = sinkNames.map(name =>
|
|
2673
|
+
const subscriptions = sinkNames.map(name => _default$5.fromObservable(sinks[name]).subscribe(replicators[name]));
|
|
111
2674
|
sinkNames.forEach(name => {
|
|
112
2675
|
const listener = sinkProxies[name];
|
|
113
2676
|
const next = (x) => {
|
|
@@ -219,6 +2782,133 @@ function setupReusable(drivers) {
|
|
|
219
2782
|
return { sources, run: _run, dispose: disposeEngine };
|
|
220
2783
|
}
|
|
221
2784
|
|
|
2785
|
+
var dropRepeats$3 = {};
|
|
2786
|
+
|
|
2787
|
+
Object.defineProperty(dropRepeats$3, "__esModule", { value: true });
|
|
2788
|
+
var DropRepeatsOperator_1 = dropRepeats$3.DropRepeatsOperator = void 0;
|
|
2789
|
+
var index_1$4 = xstream;
|
|
2790
|
+
var empty = {};
|
|
2791
|
+
var DropRepeatsOperator = /** @class */ (function () {
|
|
2792
|
+
function DropRepeatsOperator(ins, fn) {
|
|
2793
|
+
this.ins = ins;
|
|
2794
|
+
this.type = 'dropRepeats';
|
|
2795
|
+
this.out = null;
|
|
2796
|
+
this.v = empty;
|
|
2797
|
+
this.isEq = fn ? fn : function (x, y) { return x === y; };
|
|
2798
|
+
}
|
|
2799
|
+
DropRepeatsOperator.prototype._start = function (out) {
|
|
2800
|
+
this.out = out;
|
|
2801
|
+
this.ins._add(this);
|
|
2802
|
+
};
|
|
2803
|
+
DropRepeatsOperator.prototype._stop = function () {
|
|
2804
|
+
this.ins._remove(this);
|
|
2805
|
+
this.out = null;
|
|
2806
|
+
this.v = empty;
|
|
2807
|
+
};
|
|
2808
|
+
DropRepeatsOperator.prototype._n = function (t) {
|
|
2809
|
+
var u = this.out;
|
|
2810
|
+
if (!u)
|
|
2811
|
+
return;
|
|
2812
|
+
var v = this.v;
|
|
2813
|
+
if (v !== empty && this.isEq(t, v))
|
|
2814
|
+
return;
|
|
2815
|
+
this.v = t;
|
|
2816
|
+
u._n(t);
|
|
2817
|
+
};
|
|
2818
|
+
DropRepeatsOperator.prototype._e = function (err) {
|
|
2819
|
+
var u = this.out;
|
|
2820
|
+
if (!u)
|
|
2821
|
+
return;
|
|
2822
|
+
u._e(err);
|
|
2823
|
+
};
|
|
2824
|
+
DropRepeatsOperator.prototype._c = function () {
|
|
2825
|
+
var u = this.out;
|
|
2826
|
+
if (!u)
|
|
2827
|
+
return;
|
|
2828
|
+
u._c();
|
|
2829
|
+
};
|
|
2830
|
+
return DropRepeatsOperator;
|
|
2831
|
+
}());
|
|
2832
|
+
DropRepeatsOperator_1 = dropRepeats$3.DropRepeatsOperator = DropRepeatsOperator;
|
|
2833
|
+
/**
|
|
2834
|
+
* Drops consecutive duplicate values in a stream.
|
|
2835
|
+
*
|
|
2836
|
+
* Marble diagram:
|
|
2837
|
+
*
|
|
2838
|
+
* ```text
|
|
2839
|
+
* --1--2--1--1--1--2--3--4--3--3|
|
|
2840
|
+
* dropRepeats
|
|
2841
|
+
* --1--2--1--------2--3--4--3---|
|
|
2842
|
+
* ```
|
|
2843
|
+
*
|
|
2844
|
+
* Example:
|
|
2845
|
+
*
|
|
2846
|
+
* ```js
|
|
2847
|
+
* import dropRepeats from 'xstream/extra/dropRepeats'
|
|
2848
|
+
*
|
|
2849
|
+
* const stream = xs.of(1, 2, 1, 1, 1, 2, 3, 4, 3, 3)
|
|
2850
|
+
* .compose(dropRepeats())
|
|
2851
|
+
*
|
|
2852
|
+
* stream.addListener({
|
|
2853
|
+
* next: i => console.log(i),
|
|
2854
|
+
* error: err => console.error(err),
|
|
2855
|
+
* complete: () => console.log('completed')
|
|
2856
|
+
* })
|
|
2857
|
+
* ```
|
|
2858
|
+
*
|
|
2859
|
+
* ```text
|
|
2860
|
+
* > 1
|
|
2861
|
+
* > 2
|
|
2862
|
+
* > 1
|
|
2863
|
+
* > 2
|
|
2864
|
+
* > 3
|
|
2865
|
+
* > 4
|
|
2866
|
+
* > 3
|
|
2867
|
+
* > completed
|
|
2868
|
+
* ```
|
|
2869
|
+
*
|
|
2870
|
+
* Example with a custom isEqual function:
|
|
2871
|
+
*
|
|
2872
|
+
* ```js
|
|
2873
|
+
* import dropRepeats from 'xstream/extra/dropRepeats'
|
|
2874
|
+
*
|
|
2875
|
+
* const stream = xs.of('a', 'b', 'a', 'A', 'B', 'b')
|
|
2876
|
+
* .compose(dropRepeats((x, y) => x.toLowerCase() === y.toLowerCase()))
|
|
2877
|
+
*
|
|
2878
|
+
* stream.addListener({
|
|
2879
|
+
* next: i => console.log(i),
|
|
2880
|
+
* error: err => console.error(err),
|
|
2881
|
+
* complete: () => console.log('completed')
|
|
2882
|
+
* })
|
|
2883
|
+
* ```
|
|
2884
|
+
*
|
|
2885
|
+
* ```text
|
|
2886
|
+
* > a
|
|
2887
|
+
* > b
|
|
2888
|
+
* > a
|
|
2889
|
+
* > B
|
|
2890
|
+
* > completed
|
|
2891
|
+
* ```
|
|
2892
|
+
*
|
|
2893
|
+
* @param {Function} isEqual An optional function of type
|
|
2894
|
+
* `(x: T, y: T) => boolean` that takes an event from the input stream and
|
|
2895
|
+
* checks if it is equal to previous event, by returning a boolean.
|
|
2896
|
+
* @return {Stream}
|
|
2897
|
+
*/
|
|
2898
|
+
function dropRepeats$2(isEqual) {
|
|
2899
|
+
if (isEqual === void 0) { isEqual = void 0; }
|
|
2900
|
+
return function dropRepeatsOperator(ins) {
|
|
2901
|
+
return new index_1$4.Stream(new DropRepeatsOperator(ins, isEqual));
|
|
2902
|
+
};
|
|
2903
|
+
}
|
|
2904
|
+
var _default$4 = dropRepeats$3.default = dropRepeats$2;
|
|
2905
|
+
|
|
2906
|
+
var dropRepeatsModule = /*#__PURE__*/_mergeNamespaces({
|
|
2907
|
+
__proto__: null,
|
|
2908
|
+
get DropRepeatsOperator () { return DropRepeatsOperator_1; },
|
|
2909
|
+
default: _default$4
|
|
2910
|
+
}, [dropRepeats$3]);
|
|
2911
|
+
|
|
222
2912
|
function updateArrayEntry(array, scope, newVal) {
|
|
223
2913
|
if (newVal === array[scope]) {
|
|
224
2914
|
return array;
|
|
@@ -288,7 +2978,7 @@ class StateSource {
|
|
|
288
2978
|
this.isolateSink = isolateSink;
|
|
289
2979
|
this._stream = stream
|
|
290
2980
|
.filter(s => typeof s !== 'undefined')
|
|
291
|
-
.compose(
|
|
2981
|
+
.compose(_default$4())
|
|
292
2982
|
.remember();
|
|
293
2983
|
this._name = name;
|
|
294
2984
|
this.stream = adapt(this._stream);
|
|
@@ -359,7 +3049,7 @@ function isolateAllSinks(sources, innerSinks, scopes) {
|
|
|
359
3049
|
source &&
|
|
360
3050
|
scopes[channel] !== null &&
|
|
361
3051
|
typeof source.isolateSink === 'function') {
|
|
362
|
-
outerSinks[channel] = adapt(source.isolateSink(
|
|
3052
|
+
outerSinks[channel] = adapt(source.isolateSink(_default$5.fromObservable(innerSink), scopes[channel]));
|
|
363
3053
|
}
|
|
364
3054
|
else if (Object.prototype.hasOwnProperty.call(innerSinks, channel)) {
|
|
365
3055
|
outerSinks[channel] = innerSinks[channel];
|
|
@@ -461,7 +3151,7 @@ class PickMerge {
|
|
|
461
3151
|
for (let i = 0; i < n; ++i) {
|
|
462
3152
|
const sinks = arrSinks[i];
|
|
463
3153
|
const key = sinks._key;
|
|
464
|
-
const sink =
|
|
3154
|
+
const sink = _default$5.fromObservable(sinks[sel] || _default$5.never());
|
|
465
3155
|
if (!ils.has(key)) {
|
|
466
3156
|
ils.set(key, new PickMergeListener(out, this, sink));
|
|
467
3157
|
sink._add(ils.get(key));
|
|
@@ -494,7 +3184,7 @@ class PickMerge {
|
|
|
494
3184
|
}
|
|
495
3185
|
function pickMerge(selector) {
|
|
496
3186
|
return function pickMergeOperator(inst$) {
|
|
497
|
-
return new
|
|
3187
|
+
return new Stream_1(new PickMerge(selector, inst$));
|
|
498
3188
|
};
|
|
499
3189
|
}
|
|
500
3190
|
|
|
@@ -503,7 +3193,7 @@ class PickCombineListener {
|
|
|
503
3193
|
this.key = key;
|
|
504
3194
|
this.out = out;
|
|
505
3195
|
this.p = p;
|
|
506
|
-
this.val =
|
|
3196
|
+
this.val = NO_1;
|
|
507
3197
|
this.ins = ins;
|
|
508
3198
|
}
|
|
509
3199
|
_n(t) {
|
|
@@ -562,7 +3252,7 @@ class PickCombine {
|
|
|
562
3252
|
return;
|
|
563
3253
|
}
|
|
564
3254
|
const val = ils.get(key).val;
|
|
565
|
-
if (val ===
|
|
3255
|
+
if (val === NO_1) {
|
|
566
3256
|
return;
|
|
567
3257
|
}
|
|
568
3258
|
outArr[i] = val;
|
|
@@ -600,7 +3290,7 @@ class PickCombine {
|
|
|
600
3290
|
if (!sinks[sel]) {
|
|
601
3291
|
throw new Error('pickCombine found an undefined child sink stream');
|
|
602
3292
|
}
|
|
603
|
-
const sink =
|
|
3293
|
+
const sink = _default$5.fromObservable(sinks[sel]);
|
|
604
3294
|
if (!ils.has(key)) {
|
|
605
3295
|
ils.set(key, new PickCombineListener(key, out, this, sink));
|
|
606
3296
|
sink._add(ils.get(key));
|
|
@@ -627,7 +3317,7 @@ class PickCombine {
|
|
|
627
3317
|
}
|
|
628
3318
|
function pickCombine(selector) {
|
|
629
3319
|
return function pickCombineOperator(inst$) {
|
|
630
|
-
return new
|
|
3320
|
+
return new Stream_1(new PickCombine(selector, inst$));
|
|
631
3321
|
};
|
|
632
3322
|
}
|
|
633
3323
|
|
|
@@ -693,7 +3383,7 @@ function makeCollection(opts) {
|
|
|
693
3383
|
const name = opts.channel || 'state';
|
|
694
3384
|
const itemKey = opts.itemKey;
|
|
695
3385
|
const itemScope = opts.itemScope || defaultItemScope;
|
|
696
|
-
const state$ =
|
|
3386
|
+
const state$ = _default$5.fromObservable(sources[name].stream);
|
|
697
3387
|
const instances$ = state$.fold((acc, nextState) => {
|
|
698
3388
|
const dict = acc.dict;
|
|
699
3389
|
if (Array.isArray(nextState)) {
|
|
@@ -722,8 +3412,11 @@ function makeCollection(opts) {
|
|
|
722
3412
|
nextInstArray[i]._key = key;
|
|
723
3413
|
}
|
|
724
3414
|
// remove
|
|
725
|
-
dict.forEach((
|
|
3415
|
+
dict.forEach((sinks, key) => {
|
|
726
3416
|
if (!nextKeys.has(key)) {
|
|
3417
|
+
if (sinks && typeof sinks.__dispose === 'function') {
|
|
3418
|
+
sinks.__dispose();
|
|
3419
|
+
}
|
|
727
3420
|
dict.delete(key);
|
|
728
3421
|
}
|
|
729
3422
|
});
|
|
@@ -731,6 +3424,10 @@ function makeCollection(opts) {
|
|
|
731
3424
|
return { dict: dict, arr: nextInstArray };
|
|
732
3425
|
}
|
|
733
3426
|
else {
|
|
3427
|
+
dict.forEach((sinks) => {
|
|
3428
|
+
if (sinks && typeof sinks.__dispose === 'function')
|
|
3429
|
+
sinks.__dispose();
|
|
3430
|
+
});
|
|
734
3431
|
dict.clear();
|
|
735
3432
|
const key = `${itemKey ? itemKey(nextState, 0) : 'this'}`;
|
|
736
3433
|
const stateScope = identityLens;
|
|
@@ -750,9 +3447,111 @@ function makeCollection(opts) {
|
|
|
750
3447
|
};
|
|
751
3448
|
}
|
|
752
3449
|
|
|
3450
|
+
var concat$2 = {};
|
|
3451
|
+
|
|
3452
|
+
Object.defineProperty(concat$2, "__esModule", { value: true });
|
|
3453
|
+
var index_1$3 = xstream;
|
|
3454
|
+
var ConcatProducer = /** @class */ (function () {
|
|
3455
|
+
function ConcatProducer(streams) {
|
|
3456
|
+
this.streams = streams;
|
|
3457
|
+
this.type = 'concat';
|
|
3458
|
+
this.out = null;
|
|
3459
|
+
this.i = 0;
|
|
3460
|
+
}
|
|
3461
|
+
ConcatProducer.prototype._start = function (out) {
|
|
3462
|
+
this.out = out;
|
|
3463
|
+
this.streams[this.i]._add(this);
|
|
3464
|
+
};
|
|
3465
|
+
ConcatProducer.prototype._stop = function () {
|
|
3466
|
+
var streams = this.streams;
|
|
3467
|
+
if (this.i < streams.length) {
|
|
3468
|
+
streams[this.i]._remove(this);
|
|
3469
|
+
}
|
|
3470
|
+
this.i = 0;
|
|
3471
|
+
this.out = null;
|
|
3472
|
+
};
|
|
3473
|
+
ConcatProducer.prototype._n = function (t) {
|
|
3474
|
+
var u = this.out;
|
|
3475
|
+
if (!u)
|
|
3476
|
+
return;
|
|
3477
|
+
u._n(t);
|
|
3478
|
+
};
|
|
3479
|
+
ConcatProducer.prototype._e = function (err) {
|
|
3480
|
+
var u = this.out;
|
|
3481
|
+
if (!u)
|
|
3482
|
+
return;
|
|
3483
|
+
u._e(err);
|
|
3484
|
+
};
|
|
3485
|
+
ConcatProducer.prototype._c = function () {
|
|
3486
|
+
var u = this.out;
|
|
3487
|
+
if (!u)
|
|
3488
|
+
return;
|
|
3489
|
+
var streams = this.streams;
|
|
3490
|
+
streams[this.i]._remove(this);
|
|
3491
|
+
if (++this.i < streams.length) {
|
|
3492
|
+
streams[this.i]._add(this);
|
|
3493
|
+
}
|
|
3494
|
+
else {
|
|
3495
|
+
u._c();
|
|
3496
|
+
}
|
|
3497
|
+
};
|
|
3498
|
+
return ConcatProducer;
|
|
3499
|
+
}());
|
|
3500
|
+
/**
|
|
3501
|
+
* Puts one stream after the other. *concat* is a factory that takes multiple
|
|
3502
|
+
* streams as arguments, and starts the `n+1`-th stream only when the `n`-th
|
|
3503
|
+
* stream has completed. It concatenates those streams together.
|
|
3504
|
+
*
|
|
3505
|
+
* Marble diagram:
|
|
3506
|
+
*
|
|
3507
|
+
* ```text
|
|
3508
|
+
* --1--2---3---4-|
|
|
3509
|
+
* ...............--a-b-c--d-|
|
|
3510
|
+
* concat
|
|
3511
|
+
* --1--2---3---4---a-b-c--d-|
|
|
3512
|
+
* ```
|
|
3513
|
+
*
|
|
3514
|
+
* Example:
|
|
3515
|
+
*
|
|
3516
|
+
* ```js
|
|
3517
|
+
* import concat from 'xstream/extra/concat'
|
|
3518
|
+
*
|
|
3519
|
+
* const streamA = xs.of('a', 'b', 'c')
|
|
3520
|
+
* const streamB = xs.of(10, 20, 30)
|
|
3521
|
+
* const streamC = xs.of('X', 'Y', 'Z')
|
|
3522
|
+
*
|
|
3523
|
+
* const outputStream = concat(streamA, streamB, streamC)
|
|
3524
|
+
*
|
|
3525
|
+
* outputStream.addListener({
|
|
3526
|
+
* next: (x) => console.log(x),
|
|
3527
|
+
* error: (err) => console.error(err),
|
|
3528
|
+
* complete: () => console.log('concat completed'),
|
|
3529
|
+
* })
|
|
3530
|
+
* ```
|
|
3531
|
+
*
|
|
3532
|
+
* @factory true
|
|
3533
|
+
* @param {Stream} stream1 A stream to concatenate together with other streams.
|
|
3534
|
+
* @param {Stream} stream2 A stream to concatenate together with other streams. Two
|
|
3535
|
+
* or more streams may be given as arguments.
|
|
3536
|
+
* @return {Stream}
|
|
3537
|
+
*/
|
|
3538
|
+
function concat$1() {
|
|
3539
|
+
var streams = [];
|
|
3540
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3541
|
+
streams[_i] = arguments[_i];
|
|
3542
|
+
}
|
|
3543
|
+
return new index_1$3.Stream(new ConcatProducer(streams));
|
|
3544
|
+
}
|
|
3545
|
+
var _default$3 = concat$2.default = concat$1;
|
|
3546
|
+
|
|
3547
|
+
var concatModule = /*#__PURE__*/_mergeNamespaces({
|
|
3548
|
+
__proto__: null,
|
|
3549
|
+
default: _default$3
|
|
3550
|
+
}, [concat$2]);
|
|
3551
|
+
|
|
753
3552
|
function withState(main, name = 'state') {
|
|
754
3553
|
return function mainWithState(sources) {
|
|
755
|
-
const reducerMimic$ =
|
|
3554
|
+
const reducerMimic$ = _default$5.create();
|
|
756
3555
|
const state$ = reducerMimic$
|
|
757
3556
|
.fold((state, reducer) => reducer(state), void 0)
|
|
758
3557
|
.drop(1);
|
|
@@ -760,7 +3559,7 @@ function withState(main, name = 'state') {
|
|
|
760
3559
|
innerSources[name] = new StateSource(state$, name);
|
|
761
3560
|
const sinks = main(innerSources);
|
|
762
3561
|
if (sinks[name]) {
|
|
763
|
-
const stream$ =
|
|
3562
|
+
const stream$ = _default$3(_default$5.fromObservable(sinks[name]), _default$5.never());
|
|
764
3563
|
stream$.subscribe({
|
|
765
3564
|
next: i => queueMicrotask(() => reducerMimic$._n(i)),
|
|
766
3565
|
error: err => queueMicrotask(() => reducerMimic$._e(err)),
|
|
@@ -773,7 +3572,7 @@ function withState(main, name = 'state') {
|
|
|
773
3572
|
|
|
774
3573
|
function fromEvent(element, eventName, useCapture = false, preventDefault = false, passive = false) {
|
|
775
3574
|
let next = null;
|
|
776
|
-
return
|
|
3575
|
+
return Stream_1.create({
|
|
777
3576
|
start: function start(listener) {
|
|
778
3577
|
if (preventDefault) {
|
|
779
3578
|
next = function _next(event) {
|
|
@@ -838,25 +3637,45 @@ function isPredicate(fn) {
|
|
|
838
3637
|
}
|
|
839
3638
|
|
|
840
3639
|
class DocumentDOMSource {
|
|
841
|
-
constructor(_name) {
|
|
3640
|
+
constructor(_name, selector) {
|
|
842
3641
|
this._name = _name;
|
|
3642
|
+
this._selector = selector || null;
|
|
843
3643
|
}
|
|
844
3644
|
select(selector) {
|
|
845
|
-
return this;
|
|
3645
|
+
return new DocumentDOMSource(this._name, selector);
|
|
846
3646
|
}
|
|
847
3647
|
elements() {
|
|
848
|
-
|
|
3648
|
+
if (this._selector) {
|
|
3649
|
+
const out = adapt(_default$5.of(Array.from(document.querySelectorAll(this._selector))));
|
|
3650
|
+
out._isCycleSource = this._name;
|
|
3651
|
+
return out;
|
|
3652
|
+
}
|
|
3653
|
+
const out = adapt(_default$5.of([document]));
|
|
849
3654
|
out._isCycleSource = this._name;
|
|
850
3655
|
return out;
|
|
851
3656
|
}
|
|
852
3657
|
element() {
|
|
853
|
-
|
|
3658
|
+
if (this._selector) {
|
|
3659
|
+
const out = adapt(_default$5.of(document.querySelector(this._selector)));
|
|
3660
|
+
out._isCycleSource = this._name;
|
|
3661
|
+
return out;
|
|
3662
|
+
}
|
|
3663
|
+
const out = adapt(_default$5.of(document));
|
|
854
3664
|
out._isCycleSource = this._name;
|
|
855
3665
|
return out;
|
|
856
3666
|
}
|
|
857
3667
|
events(eventType, options = {}, bubbles) {
|
|
858
3668
|
let stream;
|
|
859
3669
|
stream = fromEvent(document, eventType, options.useCapture, options.preventDefault);
|
|
3670
|
+
if (this._selector) {
|
|
3671
|
+
const selector = this._selector;
|
|
3672
|
+
stream = stream.filter((ev) => {
|
|
3673
|
+
const target = ev.target;
|
|
3674
|
+
if (!(target instanceof Element))
|
|
3675
|
+
return false;
|
|
3676
|
+
return target.matches(selector) || target.closest(selector) !== null;
|
|
3677
|
+
});
|
|
3678
|
+
}
|
|
860
3679
|
const out = adapt(stream);
|
|
861
3680
|
out._isCycleSource = this._name;
|
|
862
3681
|
return out;
|
|
@@ -871,12 +3690,12 @@ class BodyDOMSource {
|
|
|
871
3690
|
return this;
|
|
872
3691
|
}
|
|
873
3692
|
elements() {
|
|
874
|
-
const out = adapt(
|
|
3693
|
+
const out = adapt(_default$5.of([document.body]));
|
|
875
3694
|
out._isCycleSource = this._name;
|
|
876
3695
|
return out;
|
|
877
3696
|
}
|
|
878
3697
|
element() {
|
|
879
|
-
const out = adapt(
|
|
3698
|
+
const out = adapt(_default$5.of(document.body));
|
|
880
3699
|
out._isCycleSource = this._name;
|
|
881
3700
|
return out;
|
|
882
3701
|
}
|
|
@@ -1093,6 +3912,190 @@ class MainDOMSource {
|
|
|
1093
3912
|
}
|
|
1094
3913
|
}
|
|
1095
3914
|
|
|
3915
|
+
var sampleCombine$1 = {};
|
|
3916
|
+
|
|
3917
|
+
var __spreadArrays = (commonjsGlobal && commonjsGlobal.__spreadArrays) || function () {
|
|
3918
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
3919
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
3920
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
3921
|
+
r[k] = a[j];
|
|
3922
|
+
return r;
|
|
3923
|
+
};
|
|
3924
|
+
Object.defineProperty(sampleCombine$1, "__esModule", { value: true });
|
|
3925
|
+
sampleCombine$1.SampleCombineOperator = sampleCombine$1.SampleCombineListener = void 0;
|
|
3926
|
+
var index_1$2 = xstream;
|
|
3927
|
+
var NO = {};
|
|
3928
|
+
var SampleCombineListener = /** @class */ (function () {
|
|
3929
|
+
function SampleCombineListener(i, p) {
|
|
3930
|
+
this.i = i;
|
|
3931
|
+
this.p = p;
|
|
3932
|
+
p.ils[i] = this;
|
|
3933
|
+
}
|
|
3934
|
+
SampleCombineListener.prototype._n = function (t) {
|
|
3935
|
+
var p = this.p;
|
|
3936
|
+
if (p.out === NO)
|
|
3937
|
+
return;
|
|
3938
|
+
p.up(t, this.i);
|
|
3939
|
+
};
|
|
3940
|
+
SampleCombineListener.prototype._e = function (err) {
|
|
3941
|
+
this.p._e(err);
|
|
3942
|
+
};
|
|
3943
|
+
SampleCombineListener.prototype._c = function () {
|
|
3944
|
+
this.p.down(this.i, this);
|
|
3945
|
+
};
|
|
3946
|
+
return SampleCombineListener;
|
|
3947
|
+
}());
|
|
3948
|
+
sampleCombine$1.SampleCombineListener = SampleCombineListener;
|
|
3949
|
+
var SampleCombineOperator = /** @class */ (function () {
|
|
3950
|
+
function SampleCombineOperator(ins, streams) {
|
|
3951
|
+
this.type = 'sampleCombine';
|
|
3952
|
+
this.ins = ins;
|
|
3953
|
+
this.others = streams;
|
|
3954
|
+
this.out = NO;
|
|
3955
|
+
this.ils = [];
|
|
3956
|
+
this.Nn = 0;
|
|
3957
|
+
this.vals = [];
|
|
3958
|
+
}
|
|
3959
|
+
SampleCombineOperator.prototype._start = function (out) {
|
|
3960
|
+
this.out = out;
|
|
3961
|
+
var s = this.others;
|
|
3962
|
+
var n = this.Nn = s.length;
|
|
3963
|
+
var vals = this.vals = new Array(n);
|
|
3964
|
+
for (var i = 0; i < n; i++) {
|
|
3965
|
+
vals[i] = NO;
|
|
3966
|
+
s[i]._add(new SampleCombineListener(i, this));
|
|
3967
|
+
}
|
|
3968
|
+
this.ins._add(this);
|
|
3969
|
+
};
|
|
3970
|
+
SampleCombineOperator.prototype._stop = function () {
|
|
3971
|
+
var s = this.others;
|
|
3972
|
+
var n = s.length;
|
|
3973
|
+
var ils = this.ils;
|
|
3974
|
+
this.ins._remove(this);
|
|
3975
|
+
for (var i = 0; i < n; i++) {
|
|
3976
|
+
s[i]._remove(ils[i]);
|
|
3977
|
+
}
|
|
3978
|
+
this.out = NO;
|
|
3979
|
+
this.vals = [];
|
|
3980
|
+
this.ils = [];
|
|
3981
|
+
};
|
|
3982
|
+
SampleCombineOperator.prototype._n = function (t) {
|
|
3983
|
+
var out = this.out;
|
|
3984
|
+
if (out === NO)
|
|
3985
|
+
return;
|
|
3986
|
+
if (this.Nn > 0)
|
|
3987
|
+
return;
|
|
3988
|
+
out._n(__spreadArrays([t], this.vals));
|
|
3989
|
+
};
|
|
3990
|
+
SampleCombineOperator.prototype._e = function (err) {
|
|
3991
|
+
var out = this.out;
|
|
3992
|
+
if (out === NO)
|
|
3993
|
+
return;
|
|
3994
|
+
out._e(err);
|
|
3995
|
+
};
|
|
3996
|
+
SampleCombineOperator.prototype._c = function () {
|
|
3997
|
+
var out = this.out;
|
|
3998
|
+
if (out === NO)
|
|
3999
|
+
return;
|
|
4000
|
+
out._c();
|
|
4001
|
+
};
|
|
4002
|
+
SampleCombineOperator.prototype.up = function (t, i) {
|
|
4003
|
+
var v = this.vals[i];
|
|
4004
|
+
if (this.Nn > 0 && v === NO) {
|
|
4005
|
+
this.Nn--;
|
|
4006
|
+
}
|
|
4007
|
+
this.vals[i] = t;
|
|
4008
|
+
};
|
|
4009
|
+
SampleCombineOperator.prototype.down = function (i, l) {
|
|
4010
|
+
this.others[i]._remove(l);
|
|
4011
|
+
};
|
|
4012
|
+
return SampleCombineOperator;
|
|
4013
|
+
}());
|
|
4014
|
+
sampleCombine$1.SampleCombineOperator = SampleCombineOperator;
|
|
4015
|
+
var sampleCombine;
|
|
4016
|
+
/**
|
|
4017
|
+
*
|
|
4018
|
+
* Combines a source stream with multiple other streams. The result stream
|
|
4019
|
+
* will emit the latest events from all input streams, but only when the
|
|
4020
|
+
* source stream emits.
|
|
4021
|
+
*
|
|
4022
|
+
* If the source, or any input stream, throws an error, the result stream
|
|
4023
|
+
* will propagate the error. If any input streams end, their final emitted
|
|
4024
|
+
* value will remain in the array of any subsequent events from the result
|
|
4025
|
+
* stream.
|
|
4026
|
+
*
|
|
4027
|
+
* The result stream will only complete upon completion of the source stream.
|
|
4028
|
+
*
|
|
4029
|
+
* Marble diagram:
|
|
4030
|
+
*
|
|
4031
|
+
* ```text
|
|
4032
|
+
* --1----2-----3--------4--- (source)
|
|
4033
|
+
* ----a-----b-----c--d------ (other)
|
|
4034
|
+
* sampleCombine
|
|
4035
|
+
* -------2a----3b-------4d--
|
|
4036
|
+
* ```
|
|
4037
|
+
*
|
|
4038
|
+
* Examples:
|
|
4039
|
+
*
|
|
4040
|
+
* ```js
|
|
4041
|
+
* import sampleCombine from 'xstream/extra/sampleCombine'
|
|
4042
|
+
* import xs from 'xstream'
|
|
4043
|
+
*
|
|
4044
|
+
* const sampler = xs.periodic(1000).take(3)
|
|
4045
|
+
* const other = xs.periodic(100)
|
|
4046
|
+
*
|
|
4047
|
+
* const stream = sampler.compose(sampleCombine(other))
|
|
4048
|
+
*
|
|
4049
|
+
* stream.addListener({
|
|
4050
|
+
* next: i => console.log(i),
|
|
4051
|
+
* error: err => console.error(err),
|
|
4052
|
+
* complete: () => console.log('completed')
|
|
4053
|
+
* })
|
|
4054
|
+
* ```
|
|
4055
|
+
*
|
|
4056
|
+
* ```text
|
|
4057
|
+
* > [0, 8]
|
|
4058
|
+
* > [1, 18]
|
|
4059
|
+
* > [2, 28]
|
|
4060
|
+
* ```
|
|
4061
|
+
*
|
|
4062
|
+
* ```js
|
|
4063
|
+
* import sampleCombine from 'xstream/extra/sampleCombine'
|
|
4064
|
+
* import xs from 'xstream'
|
|
4065
|
+
*
|
|
4066
|
+
* const sampler = xs.periodic(1000).take(3)
|
|
4067
|
+
* const other = xs.periodic(100).take(2)
|
|
4068
|
+
*
|
|
4069
|
+
* const stream = sampler.compose(sampleCombine(other))
|
|
4070
|
+
*
|
|
4071
|
+
* stream.addListener({
|
|
4072
|
+
* next: i => console.log(i),
|
|
4073
|
+
* error: err => console.error(err),
|
|
4074
|
+
* complete: () => console.log('completed')
|
|
4075
|
+
* })
|
|
4076
|
+
* ```
|
|
4077
|
+
*
|
|
4078
|
+
* ```text
|
|
4079
|
+
* > [0, 1]
|
|
4080
|
+
* > [1, 1]
|
|
4081
|
+
* > [2, 1]
|
|
4082
|
+
* ```
|
|
4083
|
+
*
|
|
4084
|
+
* @param {...Stream} streams One or more streams to combine with the sampler
|
|
4085
|
+
* stream.
|
|
4086
|
+
* @return {Stream}
|
|
4087
|
+
*/
|
|
4088
|
+
sampleCombine = function sampleCombine() {
|
|
4089
|
+
var streams = [];
|
|
4090
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
4091
|
+
streams[_i] = arguments[_i];
|
|
4092
|
+
}
|
|
4093
|
+
return function sampleCombineOperator(sampler) {
|
|
4094
|
+
return new index_1$2.Stream(new SampleCombineOperator(sampler, streams));
|
|
4095
|
+
};
|
|
4096
|
+
};
|
|
4097
|
+
var _default$2 = sampleCombine$1.default = sampleCombine;
|
|
4098
|
+
|
|
1096
4099
|
function selectorParser(node) {
|
|
1097
4100
|
if (!node.sel) {
|
|
1098
4101
|
return { tagName: '', id: '', className: '' };
|
|
@@ -1559,7 +4562,7 @@ class EventDelegator {
|
|
|
1559
4562
|
});
|
|
1560
4563
|
}
|
|
1561
4564
|
addEventListener(eventType, namespace, options, bubbles) {
|
|
1562
|
-
const subject =
|
|
4565
|
+
const subject = _default$5.never();
|
|
1563
4566
|
let dest;
|
|
1564
4567
|
const scopeChecker = new ScopeChecker(namespace, this.isolateModule);
|
|
1565
4568
|
const shouldBubble = bubbles === undefined
|
|
@@ -1602,7 +4605,7 @@ class EventDelegator {
|
|
|
1602
4605
|
}
|
|
1603
4606
|
const self = this;
|
|
1604
4607
|
let subscription = null;
|
|
1605
|
-
return
|
|
4608
|
+
return _default$5.create({
|
|
1606
4609
|
start: listener => {
|
|
1607
4610
|
subscription = nonBubbleSubject.subscribe(listener);
|
|
1608
4611
|
},
|
|
@@ -1856,7 +4859,7 @@ function domDriverInputGuard(view$) {
|
|
|
1856
4859
|
}
|
|
1857
4860
|
}
|
|
1858
4861
|
function dropCompletion(input) {
|
|
1859
|
-
return
|
|
4862
|
+
return _default$5.merge(input, _default$5.never());
|
|
1860
4863
|
}
|
|
1861
4864
|
function unwrapElementFromVNode(vnode) {
|
|
1862
4865
|
return vnode.elm;
|
|
@@ -1865,7 +4868,7 @@ function defaultReportSnabbdomError(err) {
|
|
|
1865
4868
|
(console.error || console.log)(err);
|
|
1866
4869
|
}
|
|
1867
4870
|
function makeDOMReady$() {
|
|
1868
|
-
return
|
|
4871
|
+
return _default$5.create({
|
|
1869
4872
|
start(lis) {
|
|
1870
4873
|
if (document.readyState === 'loading') {
|
|
1871
4874
|
document.addEventListener('readystatechange', () => {
|
|
@@ -1899,7 +4902,7 @@ function makeDOMDriver(container, options = {}) {
|
|
|
1899
4902
|
const domReady$ = makeDOMReady$();
|
|
1900
4903
|
let vnodeWrapper;
|
|
1901
4904
|
let mutationObserver;
|
|
1902
|
-
const mutationConfirmed$ =
|
|
4905
|
+
const mutationConfirmed$ = _default$5.create({
|
|
1903
4906
|
start(listener) {
|
|
1904
4907
|
mutationObserver = new MutationObserver(() => listener.next(null));
|
|
1905
4908
|
},
|
|
@@ -1909,7 +4912,7 @@ function makeDOMDriver(container, options = {}) {
|
|
|
1909
4912
|
});
|
|
1910
4913
|
function DOMDriver(vnode$, name = 'DOM') {
|
|
1911
4914
|
domDriverInputGuard(vnode$);
|
|
1912
|
-
const sanitation$ =
|
|
4915
|
+
const sanitation$ = _default$5.create();
|
|
1913
4916
|
const firstRoot$ = domReady$.map(() => {
|
|
1914
4917
|
const firstRoot = getValidNode(container) || document.body;
|
|
1915
4918
|
vnodeWrapper = new VNodeWrapper(firstRoot);
|
|
@@ -1919,7 +4922,7 @@ function makeDOMDriver(container, options = {}) {
|
|
|
1919
4922
|
rememberedVNode$.addListener({});
|
|
1920
4923
|
mutationConfirmed$.addListener({});
|
|
1921
4924
|
const elementAfterPatch$ = firstRoot$
|
|
1922
|
-
.map(firstRoot =>
|
|
4925
|
+
.map(firstRoot => _default$5
|
|
1923
4926
|
.merge(rememberedVNode$.endWhen(sanitation$), sanitation$)
|
|
1924
4927
|
.map(vnode => vnodeWrapper.call(vnode))
|
|
1925
4928
|
.startWith(addRootScope(tovnode.toVNode(firstRoot)))
|
|
@@ -1940,9 +4943,9 @@ function makeDOMDriver(container, options = {}) {
|
|
|
1940
4943
|
})
|
|
1941
4944
|
.compose(dropCompletion))
|
|
1942
4945
|
.flatten();
|
|
1943
|
-
const rootElement$ =
|
|
4946
|
+
const rootElement$ = _default$3(domReady$, mutationConfirmed$)
|
|
1944
4947
|
.endWhen(sanitation$)
|
|
1945
|
-
.compose(
|
|
4948
|
+
.compose(_default$2(elementAfterPatch$))
|
|
1946
4949
|
.map(arr => arr[1])
|
|
1947
4950
|
.remember();
|
|
1948
4951
|
rootElement$.addListener({
|
|
@@ -1965,7 +4968,7 @@ function eventBusDriver(out$) {
|
|
|
1965
4968
|
const all = !type;
|
|
1966
4969
|
const _type = Array.isArray(type) ? type : [type];
|
|
1967
4970
|
let cb;
|
|
1968
|
-
const in$ =
|
|
4971
|
+
const in$ = _default$5.create({
|
|
1969
4972
|
start: (listener) => {
|
|
1970
4973
|
cb = ({ detail: event }) => {
|
|
1971
4974
|
const data = (event && event.data) || null;
|
|
@@ -2069,12 +5072,12 @@ function getXs(namespaceValue) {
|
|
|
2069
5072
|
}
|
|
2070
5073
|
return value;
|
|
2071
5074
|
}
|
|
2072
|
-
const xs = getXs(
|
|
2073
|
-
const Stream =
|
|
2074
|
-
(
|
|
5075
|
+
const xs = getXs(xstreamNamespace);
|
|
5076
|
+
const Stream = Stream_1 ||
|
|
5077
|
+
(_default$5 && _default$5.Stream) ||
|
|
2075
5078
|
(xs && xs.Stream);
|
|
2076
5079
|
|
|
2077
|
-
const dropRepeats$1 = resolveInteropDefault(
|
|
5080
|
+
const dropRepeats$1 = resolveInteropDefault(dropRepeatsModule);
|
|
2078
5081
|
function switchable(factories, name$, initial, opts = {}) {
|
|
2079
5082
|
const { switched = ['DOM'], stateSourceName = 'STATE' } = opts;
|
|
2080
5083
|
const nameType = typeof name$;
|
|
@@ -2150,16 +5153,226 @@ function _switchable(factories, sources, name$, switched = ['DOM'], stateSourceN
|
|
|
2150
5153
|
return switchedSinks;
|
|
2151
5154
|
}
|
|
2152
5155
|
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
5156
|
+
var delay$2 = {};
|
|
5157
|
+
|
|
5158
|
+
Object.defineProperty(delay$2, "__esModule", { value: true });
|
|
5159
|
+
var index_1$1 = xstream;
|
|
5160
|
+
var DelayOperator = /** @class */ (function () {
|
|
5161
|
+
function DelayOperator(dt, ins) {
|
|
5162
|
+
this.dt = dt;
|
|
5163
|
+
this.ins = ins;
|
|
5164
|
+
this.type = 'delay';
|
|
5165
|
+
this.out = null;
|
|
5166
|
+
}
|
|
5167
|
+
DelayOperator.prototype._start = function (out) {
|
|
5168
|
+
this.out = out;
|
|
5169
|
+
this.ins._add(this);
|
|
5170
|
+
};
|
|
5171
|
+
DelayOperator.prototype._stop = function () {
|
|
5172
|
+
this.ins._remove(this);
|
|
5173
|
+
this.out = null;
|
|
5174
|
+
};
|
|
5175
|
+
DelayOperator.prototype._n = function (t) {
|
|
5176
|
+
var u = this.out;
|
|
5177
|
+
if (!u)
|
|
5178
|
+
return;
|
|
5179
|
+
var id = setInterval(function () {
|
|
5180
|
+
u._n(t);
|
|
5181
|
+
clearInterval(id);
|
|
5182
|
+
}, this.dt);
|
|
5183
|
+
};
|
|
5184
|
+
DelayOperator.prototype._e = function (err) {
|
|
5185
|
+
var u = this.out;
|
|
5186
|
+
if (!u)
|
|
5187
|
+
return;
|
|
5188
|
+
var id = setInterval(function () {
|
|
5189
|
+
u._e(err);
|
|
5190
|
+
clearInterval(id);
|
|
5191
|
+
}, this.dt);
|
|
5192
|
+
};
|
|
5193
|
+
DelayOperator.prototype._c = function () {
|
|
5194
|
+
var u = this.out;
|
|
5195
|
+
if (!u)
|
|
5196
|
+
return;
|
|
5197
|
+
var id = setInterval(function () {
|
|
5198
|
+
u._c();
|
|
5199
|
+
clearInterval(id);
|
|
5200
|
+
}, this.dt);
|
|
5201
|
+
};
|
|
5202
|
+
return DelayOperator;
|
|
5203
|
+
}());
|
|
5204
|
+
/**
|
|
5205
|
+
* Delays periodic events by a given time period.
|
|
5206
|
+
*
|
|
5207
|
+
* Marble diagram:
|
|
5208
|
+
*
|
|
5209
|
+
* ```text
|
|
5210
|
+
* 1----2--3--4----5|
|
|
5211
|
+
* delay(60)
|
|
5212
|
+
* ---1----2--3--4----5|
|
|
5213
|
+
* ```
|
|
5214
|
+
*
|
|
5215
|
+
* Example:
|
|
5216
|
+
*
|
|
5217
|
+
* ```js
|
|
5218
|
+
* import fromDiagram from 'xstream/extra/fromDiagram'
|
|
5219
|
+
* import delay from 'xstream/extra/delay'
|
|
5220
|
+
*
|
|
5221
|
+
* const stream = fromDiagram('1----2--3--4----5|')
|
|
5222
|
+
* .compose(delay(60))
|
|
5223
|
+
*
|
|
5224
|
+
* stream.addListener({
|
|
5225
|
+
* next: i => console.log(i),
|
|
5226
|
+
* error: err => console.error(err),
|
|
5227
|
+
* complete: () => console.log('completed')
|
|
5228
|
+
* })
|
|
5229
|
+
* ```
|
|
5230
|
+
*
|
|
5231
|
+
* ```text
|
|
5232
|
+
* > 1 (after 60 ms)
|
|
5233
|
+
* > 2 (after 160 ms)
|
|
5234
|
+
* > 3 (after 220 ms)
|
|
5235
|
+
* > 4 (after 280 ms)
|
|
5236
|
+
* > 5 (after 380 ms)
|
|
5237
|
+
* > completed
|
|
5238
|
+
* ```
|
|
5239
|
+
*
|
|
5240
|
+
* @param {number} period The amount of silence required in milliseconds.
|
|
5241
|
+
* @return {Stream}
|
|
5242
|
+
*/
|
|
5243
|
+
function delay$1(period) {
|
|
5244
|
+
return function delayOperator(ins) {
|
|
5245
|
+
return new index_1$1.Stream(new DelayOperator(period, ins));
|
|
5246
|
+
};
|
|
5247
|
+
}
|
|
5248
|
+
var _default$1 = delay$2.default = delay$1;
|
|
5249
|
+
|
|
5250
|
+
var delayModule = /*#__PURE__*/_mergeNamespaces({
|
|
5251
|
+
__proto__: null,
|
|
5252
|
+
default: _default$1
|
|
5253
|
+
}, [delay$2]);
|
|
5254
|
+
|
|
5255
|
+
var debounce$2 = {};
|
|
5256
|
+
|
|
5257
|
+
Object.defineProperty(debounce$2, "__esModule", { value: true });
|
|
5258
|
+
var index_1 = xstream;
|
|
5259
|
+
var DebounceOperator = /** @class */ (function () {
|
|
5260
|
+
function DebounceOperator(dt, ins) {
|
|
5261
|
+
this.dt = dt;
|
|
5262
|
+
this.ins = ins;
|
|
5263
|
+
this.type = 'debounce';
|
|
5264
|
+
this.out = null;
|
|
5265
|
+
this.id = null;
|
|
5266
|
+
this.t = index_1.NO;
|
|
5267
|
+
}
|
|
5268
|
+
DebounceOperator.prototype._start = function (out) {
|
|
5269
|
+
this.out = out;
|
|
5270
|
+
this.ins._add(this);
|
|
5271
|
+
};
|
|
5272
|
+
DebounceOperator.prototype._stop = function () {
|
|
5273
|
+
this.ins._remove(this);
|
|
5274
|
+
this.out = null;
|
|
5275
|
+
this.clearInterval();
|
|
5276
|
+
};
|
|
5277
|
+
DebounceOperator.prototype.clearInterval = function () {
|
|
5278
|
+
var id = this.id;
|
|
5279
|
+
if (id !== null) {
|
|
5280
|
+
clearInterval(id);
|
|
5281
|
+
}
|
|
5282
|
+
this.id = null;
|
|
5283
|
+
};
|
|
5284
|
+
DebounceOperator.prototype._n = function (t) {
|
|
5285
|
+
var _this = this;
|
|
5286
|
+
var u = this.out;
|
|
5287
|
+
if (!u)
|
|
5288
|
+
return;
|
|
5289
|
+
this.clearInterval();
|
|
5290
|
+
this.t = t;
|
|
5291
|
+
this.id = setInterval(function () {
|
|
5292
|
+
_this.clearInterval();
|
|
5293
|
+
u._n(t);
|
|
5294
|
+
_this.t = index_1.NO;
|
|
5295
|
+
}, this.dt);
|
|
5296
|
+
};
|
|
5297
|
+
DebounceOperator.prototype._e = function (err) {
|
|
5298
|
+
var u = this.out;
|
|
5299
|
+
if (!u)
|
|
5300
|
+
return;
|
|
5301
|
+
this.clearInterval();
|
|
5302
|
+
u._e(err);
|
|
5303
|
+
};
|
|
5304
|
+
DebounceOperator.prototype._c = function () {
|
|
5305
|
+
var u = this.out;
|
|
5306
|
+
if (!u)
|
|
5307
|
+
return;
|
|
5308
|
+
this.clearInterval();
|
|
5309
|
+
if (this.t != index_1.NO)
|
|
5310
|
+
u._n(this.t);
|
|
5311
|
+
this.t = index_1.NO;
|
|
5312
|
+
u._c();
|
|
5313
|
+
};
|
|
5314
|
+
return DebounceOperator;
|
|
5315
|
+
}());
|
|
5316
|
+
/**
|
|
5317
|
+
* Delays events until a certain amount of silence has passed. If that timespan
|
|
5318
|
+
* of silence is not met the event is dropped.
|
|
5319
|
+
*
|
|
5320
|
+
* Marble diagram:
|
|
5321
|
+
*
|
|
5322
|
+
* ```text
|
|
5323
|
+
* --1----2--3--4----5|
|
|
5324
|
+
* debounce(60)
|
|
5325
|
+
* -----1----------4--|
|
|
5326
|
+
* ```
|
|
5327
|
+
*
|
|
5328
|
+
* Example:
|
|
5329
|
+
*
|
|
5330
|
+
* ```js
|
|
5331
|
+
* import fromDiagram from 'xstream/extra/fromDiagram'
|
|
5332
|
+
* import debounce from 'xstream/extra/debounce'
|
|
5333
|
+
*
|
|
5334
|
+
* const stream = fromDiagram('--1----2--3--4----5|')
|
|
5335
|
+
* .compose(debounce(60))
|
|
5336
|
+
*
|
|
5337
|
+
* stream.addListener({
|
|
5338
|
+
* next: i => console.log(i),
|
|
5339
|
+
* error: err => console.error(err),
|
|
5340
|
+
* complete: () => console.log('completed')
|
|
5341
|
+
* })
|
|
5342
|
+
* ```
|
|
5343
|
+
*
|
|
5344
|
+
* ```text
|
|
5345
|
+
* > 1
|
|
5346
|
+
* > 4
|
|
5347
|
+
* > completed
|
|
5348
|
+
* ```
|
|
5349
|
+
*
|
|
5350
|
+
* @param {number} period The amount of silence required in milliseconds.
|
|
5351
|
+
* @return {Stream}
|
|
5352
|
+
*/
|
|
5353
|
+
function debounce$1(period) {
|
|
5354
|
+
return function debounceOperator(ins) {
|
|
5355
|
+
return new index_1.Stream(new DebounceOperator(period, ins));
|
|
5356
|
+
};
|
|
5357
|
+
}
|
|
5358
|
+
var _default = debounce$2.default = debounce$1;
|
|
5359
|
+
|
|
5360
|
+
var debounceModule = /*#__PURE__*/_mergeNamespaces({
|
|
5361
|
+
__proto__: null,
|
|
5362
|
+
default: _default
|
|
5363
|
+
}, [debounce$2]);
|
|
5364
|
+
|
|
5365
|
+
const delay = resolveInteropDefault(delayModule);
|
|
5366
|
+
const concat = resolveInteropDefault(concatModule);
|
|
5367
|
+
const debounce = resolveInteropDefault(debounceModule);
|
|
5368
|
+
const dropRepeats = resolveInteropDefault(dropRepeatsModule);
|
|
2157
5369
|
const ENVIRONMENT = (typeof window != 'undefined' && window) || (typeof process !== 'undefined' && process.env) || {};
|
|
2158
5370
|
const BOOTSTRAP_ACTION = 'BOOTSTRAP';
|
|
2159
5371
|
const INITIALIZE_ACTION = 'INITIALIZE';
|
|
2160
5372
|
const HYDRATE_ACTION = 'HYDRATE';
|
|
2161
5373
|
const PARENT_SINK_NAME = 'PARENT';
|
|
2162
5374
|
const CHILD_SOURCE_NAME = 'CHILD';
|
|
5375
|
+
const READY_SINK_NAME = 'READY';
|
|
2163
5376
|
let COMPONENT_COUNT = 0;
|
|
2164
5377
|
function wrapDOMSource(domSource) {
|
|
2165
5378
|
return new Proxy(domSource, {
|
|
@@ -2204,19 +5417,32 @@ function component(opts) {
|
|
|
2204
5417
|
if (isObj(fixedIsolateOpts)) {
|
|
2205
5418
|
const wrapped = (sources) => {
|
|
2206
5419
|
const fixedOpts = { ...opts, sources };
|
|
2207
|
-
|
|
5420
|
+
const instance = new Component(fixedOpts);
|
|
5421
|
+
instance.sinks.__dispose = () => instance.dispose();
|
|
5422
|
+
return instance.sinks;
|
|
2208
5423
|
};
|
|
2209
5424
|
returnFunction = currySources ? isolate(wrapped, fixedIsolateOpts) : isolate(wrapped, fixedIsolateOpts)(sources);
|
|
2210
5425
|
}
|
|
2211
5426
|
else {
|
|
2212
|
-
|
|
5427
|
+
if (currySources) {
|
|
5428
|
+
returnFunction = (sources) => {
|
|
5429
|
+
const instance = new Component({ ...opts, sources });
|
|
5430
|
+
instance.sinks.__dispose = () => instance.dispose();
|
|
5431
|
+
return instance.sinks;
|
|
5432
|
+
};
|
|
5433
|
+
}
|
|
5434
|
+
else {
|
|
5435
|
+
const instance = new Component(opts);
|
|
5436
|
+
instance.sinks.__dispose = () => instance.dispose();
|
|
5437
|
+
returnFunction = instance.sinks;
|
|
5438
|
+
}
|
|
2213
5439
|
}
|
|
2214
5440
|
returnFunction.componentName = name;
|
|
2215
5441
|
returnFunction.isSygnalComponent = true;
|
|
2216
5442
|
return returnFunction;
|
|
2217
5443
|
}
|
|
2218
5444
|
class Component {
|
|
2219
|
-
constructor({ name = 'NO NAME', sources, intent, model, hmrActions, context, response, view, peers = {}, components = {}, initialState, calculated, storeCalculatedInState = true, DOMSourceName = 'DOM', stateSourceName = 'STATE', requestSourceName = 'HTTP', debug = false }) {
|
|
5445
|
+
constructor({ name = 'NO NAME', sources, intent, model, hmrActions, context, response, view, peers = {}, components = {}, initialState, calculated, storeCalculatedInState = true, DOMSourceName = 'DOM', stateSourceName = 'STATE', requestSourceName = 'HTTP', onError, debug = false }) {
|
|
2220
5446
|
if (!sources || !isObj(sources))
|
|
2221
5447
|
throw new Error(`[${name}] Missing or invalid sources`);
|
|
2222
5448
|
this._componentNumber = COMPONENT_COUNT++;
|
|
@@ -2237,6 +5463,7 @@ class Component {
|
|
|
2237
5463
|
this.stateSourceName = stateSourceName;
|
|
2238
5464
|
this.requestSourceName = requestSourceName;
|
|
2239
5465
|
this.sourceNames = Object.keys(sources);
|
|
5466
|
+
this.onError = onError;
|
|
2240
5467
|
this._debug = debug;
|
|
2241
5468
|
// Warn if calculated fields shadow base state keys
|
|
2242
5469
|
if (this.calculated && this.initialState
|
|
@@ -2386,6 +5613,20 @@ class Component {
|
|
|
2386
5613
|
__NOOP_ACTION__: (state) => state
|
|
2387
5614
|
};
|
|
2388
5615
|
}
|
|
5616
|
+
this._subscriptions = [];
|
|
5617
|
+
this._activeSubComponents = new Map();
|
|
5618
|
+
this._childReadyState = {};
|
|
5619
|
+
this._readyChangedListener = null;
|
|
5620
|
+
this._readyChanged$ = xs.create({
|
|
5621
|
+
start: (listener) => { this._readyChangedListener = listener; },
|
|
5622
|
+
stop: () => { },
|
|
5623
|
+
});
|
|
5624
|
+
this._disposeListener = null;
|
|
5625
|
+
this._dispose$ = xs.create({
|
|
5626
|
+
start: (listener) => { this._disposeListener = listener; },
|
|
5627
|
+
stop: () => { },
|
|
5628
|
+
});
|
|
5629
|
+
this.sources.dispose$ = this._dispose$;
|
|
2389
5630
|
this.addCalculated = this.createMemoizedAddCalculated();
|
|
2390
5631
|
this.log = makeLog(`${this._componentNumber} | ${name}`);
|
|
2391
5632
|
this.initChildSources$();
|
|
@@ -2412,6 +5653,51 @@ class Component {
|
|
|
2412
5653
|
}
|
|
2413
5654
|
}
|
|
2414
5655
|
}
|
|
5656
|
+
dispose() {
|
|
5657
|
+
// Signal disposal to the component via dispose$ stream
|
|
5658
|
+
// This fires FIRST so CLEANUP actions in the model can process
|
|
5659
|
+
if (this._disposeListener) {
|
|
5660
|
+
try {
|
|
5661
|
+
this._disposeListener.next(true);
|
|
5662
|
+
this._disposeListener.complete();
|
|
5663
|
+
}
|
|
5664
|
+
catch (_) { }
|
|
5665
|
+
this._disposeListener = null;
|
|
5666
|
+
}
|
|
5667
|
+
// Tear down streams on next microtask to allow CLEANUP actions to process
|
|
5668
|
+
setTimeout(() => {
|
|
5669
|
+
// Complete the action$ stream to stop the entire component cycle
|
|
5670
|
+
if (this.action$ && typeof this.action$.shamefullySendComplete === 'function') {
|
|
5671
|
+
try {
|
|
5672
|
+
this.action$.shamefullySendComplete();
|
|
5673
|
+
}
|
|
5674
|
+
catch (_) { }
|
|
5675
|
+
}
|
|
5676
|
+
// Complete the vdom$ stream to stop rendering
|
|
5677
|
+
if (this.vdom$ && typeof this.vdom$.shamefullySendComplete === 'function') {
|
|
5678
|
+
try {
|
|
5679
|
+
this.vdom$.shamefullySendComplete();
|
|
5680
|
+
}
|
|
5681
|
+
catch (_) { }
|
|
5682
|
+
}
|
|
5683
|
+
// Unsubscribe tracked internal subscriptions
|
|
5684
|
+
for (const sub of this._subscriptions) {
|
|
5685
|
+
if (sub && typeof sub.unsubscribe === 'function') {
|
|
5686
|
+
try {
|
|
5687
|
+
sub.unsubscribe();
|
|
5688
|
+
}
|
|
5689
|
+
catch (_) { }
|
|
5690
|
+
}
|
|
5691
|
+
}
|
|
5692
|
+
this._subscriptions = [];
|
|
5693
|
+
// Dispose any active sub-components
|
|
5694
|
+
this._activeSubComponents.forEach((entry) => {
|
|
5695
|
+
if (entry?.sink$?.__dispose)
|
|
5696
|
+
entry.sink$.__dispose();
|
|
5697
|
+
});
|
|
5698
|
+
this._activeSubComponents.clear();
|
|
5699
|
+
}, 0);
|
|
5700
|
+
}
|
|
2415
5701
|
get debug() {
|
|
2416
5702
|
return this._debug || (ENVIRONMENT.SYGNAL_DEBUG === 'true' || ENVIRONMENT.SYGNAL_DEBUG === true);
|
|
2417
5703
|
}
|
|
@@ -2542,7 +5828,7 @@ class Component {
|
|
|
2542
5828
|
})
|
|
2543
5829
|
.compose(dropRepeats(objIsEqual))
|
|
2544
5830
|
.startWith({});
|
|
2545
|
-
this.context$.subscribe({ next: (_) => _, error: (err) => console.error(`[${this.name}] Error in context stream:`, err) });
|
|
5831
|
+
this._subscriptions.push(this.context$.subscribe({ next: (_) => _, error: (err) => console.error(`[${this.name}] Error in context stream:`, err) }));
|
|
2546
5832
|
}
|
|
2547
5833
|
initModel$() {
|
|
2548
5834
|
if (typeof this.model == 'undefined') {
|
|
@@ -2665,7 +5951,7 @@ class Component {
|
|
|
2665
5951
|
stop: (_) => {
|
|
2666
5952
|
}
|
|
2667
5953
|
});
|
|
2668
|
-
subComponentSink$.subscribe({ next: (_) => _, error: (err) => console.error(`[${this.name}] Error in sub-component sink stream:`, err) });
|
|
5954
|
+
this._subscriptions.push(subComponentSink$.subscribe({ next: (_) => _, error: (err) => console.error(`[${this.name}] Error in sub-component sink stream:`, err) }));
|
|
2669
5955
|
this.subComponentSink$ = subComponentSink$.filter((sinks) => Object.keys(sinks).length > 0);
|
|
2670
5956
|
}
|
|
2671
5957
|
initSubComponentsRendered$() {
|
|
@@ -2688,10 +5974,27 @@ class Component {
|
|
|
2688
5974
|
.map((params) => {
|
|
2689
5975
|
const { props, state, children, context, ...peers } = params;
|
|
2690
5976
|
const { sygnalFactory, sygnalOptions, ...sanitizedProps } = props || {};
|
|
2691
|
-
|
|
5977
|
+
try {
|
|
5978
|
+
return this.view({ ...sanitizedProps, state, children, context, peers }, state, context, peers);
|
|
5979
|
+
}
|
|
5980
|
+
catch (err) {
|
|
5981
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
5982
|
+
console.error(`[${this.name}] Error in view:`, error);
|
|
5983
|
+
if (typeof this.onError === 'function') {
|
|
5984
|
+
try {
|
|
5985
|
+
return this.onError(error, { componentName: this.name });
|
|
5986
|
+
}
|
|
5987
|
+
catch (fallbackErr) {
|
|
5988
|
+
console.error(`[${this.name}] Error in onError handler:`, fallbackErr);
|
|
5989
|
+
}
|
|
5990
|
+
}
|
|
5991
|
+
return { sel: 'div', data: { attrs: { 'data-sygnal-error': this.name } }, children: [] };
|
|
5992
|
+
}
|
|
2692
5993
|
})
|
|
2693
5994
|
.compose(this.log('View rendered'))
|
|
2694
5995
|
.map((vDom) => vDom || { sel: 'div', data: {}, children: [] })
|
|
5996
|
+
.map(processPortals)
|
|
5997
|
+
.map(processTransitions)
|
|
2695
5998
|
.compose(this.instantiateSubComponents.bind(this))
|
|
2696
5999
|
.filter((val) => val !== undefined)
|
|
2697
6000
|
.compose(this.renderVdom.bind(this));
|
|
@@ -2711,6 +6014,20 @@ class Component {
|
|
|
2711
6014
|
}, {});
|
|
2712
6015
|
this.sinks[this.DOMSourceName] = this.vdom$;
|
|
2713
6016
|
this.sinks[PARENT_SINK_NAME] = this.model$[PARENT_SINK_NAME] || xs.never();
|
|
6017
|
+
// READY sink: if the component explicitly defined READY model entries, use them;
|
|
6018
|
+
// otherwise auto-emit true. Check the raw model object, not model$ (which always has keys for all sources).
|
|
6019
|
+
const hasExplicitReady = this.model && isObj(this.model) && Object.values(this.model).some((sinks) => {
|
|
6020
|
+
if (isObj(sinks) && READY_SINK_NAME in sinks)
|
|
6021
|
+
return true;
|
|
6022
|
+
return false;
|
|
6023
|
+
});
|
|
6024
|
+
if (hasExplicitReady) {
|
|
6025
|
+
this.sinks[READY_SINK_NAME] = this.model$[READY_SINK_NAME];
|
|
6026
|
+
this.sinks[READY_SINK_NAME].__explicitReady = true;
|
|
6027
|
+
}
|
|
6028
|
+
else {
|
|
6029
|
+
this.sinks[READY_SINK_NAME] = xs.of(true);
|
|
6030
|
+
}
|
|
2714
6031
|
}
|
|
2715
6032
|
makeOnAction(action$, isStateSink = true, rootAction$) {
|
|
2716
6033
|
rootAction$ = rootAction$ || action$;
|
|
@@ -2734,26 +6051,38 @@ class Component {
|
|
|
2734
6051
|
if (isStateSink) {
|
|
2735
6052
|
return (state) => {
|
|
2736
6053
|
const _state = this.isSubComponent ? this.currentState : state;
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
6054
|
+
try {
|
|
6055
|
+
const enhancedState = this.addCalculated(_state);
|
|
6056
|
+
props.state = enhancedState;
|
|
6057
|
+
const newState = reducer(enhancedState, data, next, props);
|
|
6058
|
+
if (newState === ABORT)
|
|
6059
|
+
return _state;
|
|
6060
|
+
return this.cleanupCalculated(newState);
|
|
6061
|
+
}
|
|
6062
|
+
catch (err) {
|
|
6063
|
+
console.error(`[${this.name}] Error in model reducer '${name}':`, err);
|
|
2741
6064
|
return _state;
|
|
2742
|
-
|
|
6065
|
+
}
|
|
2743
6066
|
};
|
|
2744
6067
|
}
|
|
2745
6068
|
else {
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
6069
|
+
try {
|
|
6070
|
+
const enhancedState = this.addCalculated(this.currentState);
|
|
6071
|
+
props.state = enhancedState;
|
|
6072
|
+
const reduced = reducer(enhancedState, data, next, props);
|
|
6073
|
+
const type = typeof reduced;
|
|
6074
|
+
if (isObj(reduced) || ['string', 'number', 'boolean', 'function'].includes(type))
|
|
6075
|
+
return reduced;
|
|
6076
|
+
if (type === 'undefined') {
|
|
6077
|
+
console.warn(`[${this.name}] 'undefined' value sent to ${name}`);
|
|
6078
|
+
return reduced;
|
|
6079
|
+
}
|
|
6080
|
+
throw new Error(`[${this.name}] Invalid reducer type for action '${name}': ${type}`);
|
|
6081
|
+
}
|
|
6082
|
+
catch (err) {
|
|
6083
|
+
console.error(`[${this.name}] Error in model reducer '${name}':`, err);
|
|
6084
|
+
return ABORT;
|
|
2755
6085
|
}
|
|
2756
|
-
throw new Error(`[${this.name}] Invalid reducer type for action '${name}': ${type}`);
|
|
2757
6086
|
}
|
|
2758
6087
|
}).filter((result) => result !== ABORT);
|
|
2759
6088
|
}
|
|
@@ -2901,6 +6230,12 @@ class Component {
|
|
|
2901
6230
|
const entries = Object.entries(foundComponents);
|
|
2902
6231
|
const rootEntry = { '::ROOT::': vDom };
|
|
2903
6232
|
if (entries.length === 0) {
|
|
6233
|
+
// Dispose any previously active sub-components
|
|
6234
|
+
this._activeSubComponents.forEach((entry) => {
|
|
6235
|
+
if (entry?.sink$?.__dispose)
|
|
6236
|
+
entry.sink$.__dispose();
|
|
6237
|
+
});
|
|
6238
|
+
this._activeSubComponents.clear();
|
|
2904
6239
|
return rootEntry;
|
|
2905
6240
|
}
|
|
2906
6241
|
const sinkArrsByType = {};
|
|
@@ -2918,7 +6253,7 @@ class Component {
|
|
|
2918
6253
|
if (name === PARENT_SINK_NAME) {
|
|
2919
6254
|
childSources.push(stream);
|
|
2920
6255
|
}
|
|
2921
|
-
else if (name !== this.DOMSourceName) {
|
|
6256
|
+
else if (name !== this.DOMSourceName && name !== READY_SINK_NAME) {
|
|
2922
6257
|
sinkArrsByType[name].push(stream);
|
|
2923
6258
|
}
|
|
2924
6259
|
});
|
|
@@ -2944,9 +6279,27 @@ class Component {
|
|
|
2944
6279
|
instantiator = this.instantiateCustomComponent.bind(this);
|
|
2945
6280
|
}
|
|
2946
6281
|
newInstanceCount++;
|
|
2947
|
-
|
|
6282
|
+
let sink$;
|
|
6283
|
+
try {
|
|
6284
|
+
sink$ = instantiator(el, props$, children$);
|
|
6285
|
+
}
|
|
6286
|
+
catch (err) {
|
|
6287
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
6288
|
+
console.error(`[${this.name}] Error instantiating sub-component:`, error);
|
|
6289
|
+
let fallbackVNode = { sel: 'div', data: { attrs: { 'data-sygnal-error': this.name } }, children: [] };
|
|
6290
|
+
if (typeof this.onError === 'function') {
|
|
6291
|
+
try {
|
|
6292
|
+
fallbackVNode = this.onError(error, { componentName: this.name }) || fallbackVNode;
|
|
6293
|
+
}
|
|
6294
|
+
catch (fallbackErr) {
|
|
6295
|
+
console.error(`[${this.name}] Error in onError handler:`, fallbackErr);
|
|
6296
|
+
}
|
|
6297
|
+
}
|
|
6298
|
+
sink$ = { [this.DOMSourceName]: xs.of(fallbackVNode) };
|
|
6299
|
+
}
|
|
2948
6300
|
sink$[this.DOMSourceName] = sink$[this.DOMSourceName] ? this.makeCoordinatedSubComponentDomSink(sink$[this.DOMSourceName]) : xs.never();
|
|
2949
6301
|
acc[id] = { sink$, props$, children$ };
|
|
6302
|
+
this._activeSubComponents.set(id, acc[id]);
|
|
2950
6303
|
addSinks(sink$);
|
|
2951
6304
|
return acc;
|
|
2952
6305
|
}, rootEntry);
|
|
@@ -2956,6 +6309,16 @@ class Component {
|
|
|
2956
6309
|
acc[name] = streamArr.length === 1 ? streamArr[0] : xs.merge(...streamArr);
|
|
2957
6310
|
return acc;
|
|
2958
6311
|
}, {});
|
|
6312
|
+
// Dispose removed sub-components
|
|
6313
|
+
const currentIds = new Set(Object.keys(newComponents));
|
|
6314
|
+
this._activeSubComponents.forEach((entry, id) => {
|
|
6315
|
+
if (!currentIds.has(id)) {
|
|
6316
|
+
if (entry?.sink$?.__dispose)
|
|
6317
|
+
entry.sink$.__dispose();
|
|
6318
|
+
this._activeSubComponents.delete(id);
|
|
6319
|
+
delete this._childReadyState[id];
|
|
6320
|
+
}
|
|
6321
|
+
});
|
|
2959
6322
|
this.newSubComponentSinks(mergedSinksByType);
|
|
2960
6323
|
this.newChildSources(childSources);
|
|
2961
6324
|
if (newInstanceCount > 0)
|
|
@@ -3008,8 +6371,8 @@ class Component {
|
|
|
3008
6371
|
else {
|
|
3009
6372
|
const name = collectionOf.componentName || collectionOf.label || collectionOf.name || 'FUNCTION_COMPONENT';
|
|
3010
6373
|
const view = collectionOf;
|
|
3011
|
-
const { model, intent, hmrActions, context, peers, components, initialState, calculated, storeCalculatedInState, DOMSourceName, stateSourceName, debug } = collectionOf;
|
|
3012
|
-
const options = { name, view, model, intent, hmrActions, context, peers, components, initialState, calculated, storeCalculatedInState, DOMSourceName, stateSourceName, debug };
|
|
6374
|
+
const { model, intent, hmrActions, context, peers, components, initialState, calculated, storeCalculatedInState, DOMSourceName, stateSourceName, onError, debug } = collectionOf;
|
|
6375
|
+
const options = { name, view, model, intent, hmrActions, context, peers, components, initialState, calculated, storeCalculatedInState, DOMSourceName, stateSourceName, onError, debug };
|
|
3013
6376
|
factory = component(options);
|
|
3014
6377
|
}
|
|
3015
6378
|
}
|
|
@@ -3168,8 +6531,8 @@ class Component {
|
|
|
3168
6531
|
if (!current.isSygnalComponent) {
|
|
3169
6532
|
const name = current.componentName || current.label || current.name || 'FUNCTION_COMPONENT';
|
|
3170
6533
|
const view = current;
|
|
3171
|
-
const { model, intent, hmrActions, context, peers, components, initialState, calculated, storeCalculatedInState, DOMSourceName, stateSourceName, debug } = current;
|
|
3172
|
-
const options = { name, view, model, intent, hmrActions, context, peers, components, initialState, calculated, storeCalculatedInState, DOMSourceName, stateSourceName, debug };
|
|
6534
|
+
const { model, intent, hmrActions, context, peers, components, initialState, calculated, storeCalculatedInState, DOMSourceName, stateSourceName, onError, debug } = current;
|
|
6535
|
+
const options = { name, view, model, intent, hmrActions, context, peers, components, initialState, calculated, storeCalculatedInState, DOMSourceName, stateSourceName, onError, debug };
|
|
3173
6536
|
switchableComponents[key] = component(options);
|
|
3174
6537
|
}
|
|
3175
6538
|
});
|
|
@@ -3242,14 +6605,14 @@ class Component {
|
|
|
3242
6605
|
return sink$;
|
|
3243
6606
|
}
|
|
3244
6607
|
renderVdom(componentInstances$) {
|
|
3245
|
-
return xs.combine(this.subComponentsRendered$, componentInstances
|
|
6608
|
+
return xs.combine(this.subComponentsRendered$, componentInstances$, this._readyChanged$.startWith(null))
|
|
3246
6609
|
.compose(debounce(1))
|
|
3247
6610
|
.map(([_, components]) => {
|
|
3248
6611
|
const componentNames = Object.keys(this.components);
|
|
3249
6612
|
const root = components['::ROOT::'];
|
|
3250
6613
|
const entries = Object.entries(components).filter(([id]) => id !== '::ROOT::');
|
|
3251
6614
|
if (entries.length === 0) {
|
|
3252
|
-
return xs.of(root);
|
|
6615
|
+
return xs.of(processSuspensePost(root));
|
|
3253
6616
|
}
|
|
3254
6617
|
const ids = [];
|
|
3255
6618
|
const vdom$ = entries
|
|
@@ -3259,6 +6622,33 @@ class Component {
|
|
|
3259
6622
|
});
|
|
3260
6623
|
if (vdom$.length === 0)
|
|
3261
6624
|
return xs.of(root);
|
|
6625
|
+
// Track READY state on the component instance (persists across folds)
|
|
6626
|
+
for (const [id, val] of entries) {
|
|
6627
|
+
if (this._childReadyState[id] !== undefined)
|
|
6628
|
+
continue; // already tracking
|
|
6629
|
+
const readySink = val.sink$[READY_SINK_NAME];
|
|
6630
|
+
if (readySink) {
|
|
6631
|
+
const isExplicit = readySink.__explicitReady;
|
|
6632
|
+
this._childReadyState[id] = isExplicit ? false : true;
|
|
6633
|
+
readySink.addListener({
|
|
6634
|
+
next: (ready) => {
|
|
6635
|
+
const wasReady = this._childReadyState[id];
|
|
6636
|
+
this._childReadyState[id] = !!ready;
|
|
6637
|
+
// When READY state changes, trigger a re-render
|
|
6638
|
+
if (wasReady !== !!ready && this._readyChangedListener) {
|
|
6639
|
+
setTimeout(() => {
|
|
6640
|
+
this._readyChangedListener?.next(null);
|
|
6641
|
+
}, 0);
|
|
6642
|
+
}
|
|
6643
|
+
},
|
|
6644
|
+
error: () => { },
|
|
6645
|
+
complete: () => { },
|
|
6646
|
+
});
|
|
6647
|
+
}
|
|
6648
|
+
else {
|
|
6649
|
+
this._childReadyState[id] = true;
|
|
6650
|
+
}
|
|
6651
|
+
}
|
|
3262
6652
|
return xs.combine(...vdom$)
|
|
3263
6653
|
.compose(debounce(1))
|
|
3264
6654
|
.map((vdoms) => {
|
|
@@ -3267,8 +6657,8 @@ class Component {
|
|
|
3267
6657
|
return acc;
|
|
3268
6658
|
}, {});
|
|
3269
6659
|
const rootCopy = deepCopyVdom(root);
|
|
3270
|
-
const injected = injectComponents(rootCopy, withIds, componentNames);
|
|
3271
|
-
return injected;
|
|
6660
|
+
const injected = injectComponents(rootCopy, withIds, componentNames, 'r', undefined, this._childReadyState);
|
|
6661
|
+
return processSuspensePost(injected);
|
|
3272
6662
|
});
|
|
3273
6663
|
})
|
|
3274
6664
|
.flatten()
|
|
@@ -3375,7 +6765,7 @@ function getComponents(currentElement, componentNames, path = 'r', parentId) {
|
|
|
3375
6765
|
}
|
|
3376
6766
|
return found;
|
|
3377
6767
|
}
|
|
3378
|
-
function injectComponents(currentElement, components, componentNames, path = 'r', parentId) {
|
|
6768
|
+
function injectComponents(currentElement, components, componentNames, path = 'r', parentId, readyMap) {
|
|
3379
6769
|
if (!currentElement)
|
|
3380
6770
|
return;
|
|
3381
6771
|
if (currentElement.data?.componentsInjected)
|
|
@@ -3391,7 +6781,13 @@ function injectComponents(currentElement, components, componentNames, path = 'r'
|
|
|
3391
6781
|
let id = parentId;
|
|
3392
6782
|
if (isComponent) {
|
|
3393
6783
|
id = getComponentIdFromElement(currentElement, path, parentId);
|
|
3394
|
-
|
|
6784
|
+
let component = components[id];
|
|
6785
|
+
// Annotate the injected VNode with its READY state
|
|
6786
|
+
if (readyMap && id && component && typeof component === 'object' && component.sel) {
|
|
6787
|
+
component.data = component.data || {};
|
|
6788
|
+
component.data.attrs = component.data.attrs || {};
|
|
6789
|
+
component.data.attrs['data-sygnal-ready'] = readyMap[id] !== false ? 'true' : 'false';
|
|
6790
|
+
}
|
|
3395
6791
|
if (isCollection) {
|
|
3396
6792
|
currentElement.sel = 'div';
|
|
3397
6793
|
currentElement.children = Array.isArray(component) ? component : [component];
|
|
@@ -3405,7 +6801,7 @@ function injectComponents(currentElement, components, componentNames, path = 'r'
|
|
|
3405
6801
|
}
|
|
3406
6802
|
}
|
|
3407
6803
|
else if (children.length > 0) {
|
|
3408
|
-
currentElement.children = children.map((child, i) => injectComponents(child, components, componentNames, `${path}.${i}`, id)).flat();
|
|
6804
|
+
currentElement.children = children.map((child, i) => injectComponents(child, components, componentNames, `${path}.${i}`, id, readyMap)).flat();
|
|
3409
6805
|
return currentElement;
|
|
3410
6806
|
}
|
|
3411
6807
|
else {
|
|
@@ -3421,6 +6817,189 @@ function getComponentIdFromElement(el, path, parentId) {
|
|
|
3421
6817
|
const fullId = `${parentString}${name}::${id}`;
|
|
3422
6818
|
return fullId;
|
|
3423
6819
|
}
|
|
6820
|
+
function hasNotReadyChild(vnode) {
|
|
6821
|
+
if (!vnode || !vnode.sel)
|
|
6822
|
+
return false;
|
|
6823
|
+
// Check for data-sygnal-ready="false" on injected sub-components
|
|
6824
|
+
if (vnode.data?.attrs?.['data-sygnal-ready'] === 'false')
|
|
6825
|
+
return true;
|
|
6826
|
+
// Check for lazy-loading placeholder (not yet instantiated as a component)
|
|
6827
|
+
if (vnode.data?.attrs?.['data-sygnal-lazy'] === 'loading')
|
|
6828
|
+
return true;
|
|
6829
|
+
// Stop at inner Suspense boundaries — they handle their own children
|
|
6830
|
+
if (vnode.sel === 'suspense')
|
|
6831
|
+
return false;
|
|
6832
|
+
if (Array.isArray(vnode.children)) {
|
|
6833
|
+
for (const child of vnode.children) {
|
|
6834
|
+
if (hasNotReadyChild(child))
|
|
6835
|
+
return true;
|
|
6836
|
+
}
|
|
6837
|
+
}
|
|
6838
|
+
return false;
|
|
6839
|
+
}
|
|
6840
|
+
function processSuspensePost(vnode) {
|
|
6841
|
+
if (!vnode || !vnode.sel)
|
|
6842
|
+
return vnode;
|
|
6843
|
+
if (vnode.sel === 'suspense') {
|
|
6844
|
+
const props = vnode.data?.props || {};
|
|
6845
|
+
const fallback = props.fallback;
|
|
6846
|
+
const children = vnode.children || [];
|
|
6847
|
+
// Check if any child within this boundary is not ready
|
|
6848
|
+
const isPending = children.some(hasNotReadyChild);
|
|
6849
|
+
if (isPending && fallback) {
|
|
6850
|
+
// Render fallback
|
|
6851
|
+
if (typeof fallback === 'string') {
|
|
6852
|
+
return { sel: 'div', data: { attrs: { 'data-sygnal-suspense': 'pending' } }, children: [{ text: fallback }], text: undefined, elm: undefined, key: undefined };
|
|
6853
|
+
}
|
|
6854
|
+
return { sel: 'div', data: { attrs: { 'data-sygnal-suspense': 'pending' } }, children: [fallback], text: undefined, elm: undefined, key: undefined };
|
|
6855
|
+
}
|
|
6856
|
+
// All children ready or no fallback — render children directly
|
|
6857
|
+
if (children.length === 1)
|
|
6858
|
+
return processSuspensePost(children[0]);
|
|
6859
|
+
return { sel: 'div', data: { attrs: { 'data-sygnal-suspense': 'resolved' } }, children: children.map((c) => processSuspensePost(c)), text: undefined, elm: undefined, key: undefined };
|
|
6860
|
+
}
|
|
6861
|
+
if (vnode.children && vnode.children.length > 0) {
|
|
6862
|
+
vnode.children = vnode.children.map((c) => processSuspensePost(c));
|
|
6863
|
+
}
|
|
6864
|
+
return vnode;
|
|
6865
|
+
}
|
|
6866
|
+
const portalPatch = init.init(modules);
|
|
6867
|
+
function processPortals(vnode) {
|
|
6868
|
+
if (!vnode || !vnode.sel)
|
|
6869
|
+
return vnode;
|
|
6870
|
+
if (vnode.sel === 'portal') {
|
|
6871
|
+
const target = vnode.data?.props?.target;
|
|
6872
|
+
const children = vnode.children || [];
|
|
6873
|
+
return createPortalPlaceholder(target, children);
|
|
6874
|
+
}
|
|
6875
|
+
if (vnode.children && vnode.children.length > 0) {
|
|
6876
|
+
vnode.children = vnode.children.map(processPortals);
|
|
6877
|
+
}
|
|
6878
|
+
return vnode;
|
|
6879
|
+
}
|
|
6880
|
+
function processTransitions(vnode) {
|
|
6881
|
+
if (!vnode || !vnode.sel)
|
|
6882
|
+
return vnode;
|
|
6883
|
+
if (vnode.sel === 'transition') {
|
|
6884
|
+
const props = vnode.data?.props || {};
|
|
6885
|
+
const name = props.name || 'v';
|
|
6886
|
+
const duration = props.duration;
|
|
6887
|
+
const children = vnode.children || [];
|
|
6888
|
+
const child = children[0];
|
|
6889
|
+
if (!child || !child.sel)
|
|
6890
|
+
return child || vnode;
|
|
6891
|
+
return applyTransitionHooks(processTransitions(child), name, duration);
|
|
6892
|
+
}
|
|
6893
|
+
if (vnode.children && vnode.children.length > 0) {
|
|
6894
|
+
vnode.children = vnode.children.map(processTransitions);
|
|
6895
|
+
}
|
|
6896
|
+
return vnode;
|
|
6897
|
+
}
|
|
6898
|
+
function applyTransitionHooks(vnode, name, duration) {
|
|
6899
|
+
const existingInsert = vnode.data?.hook?.insert;
|
|
6900
|
+
const existingRemove = vnode.data?.hook?.remove;
|
|
6901
|
+
vnode.data = vnode.data || {};
|
|
6902
|
+
vnode.data.hook = vnode.data.hook || {};
|
|
6903
|
+
vnode.data.hook.insert = (vn) => {
|
|
6904
|
+
if (existingInsert)
|
|
6905
|
+
existingInsert(vn);
|
|
6906
|
+
const el = vn.elm;
|
|
6907
|
+
if (!el || !el.classList)
|
|
6908
|
+
return;
|
|
6909
|
+
el.classList.add(`${name}-enter-from`, `${name}-enter-active`);
|
|
6910
|
+
requestAnimationFrame(() => {
|
|
6911
|
+
requestAnimationFrame(() => {
|
|
6912
|
+
el.classList.remove(`${name}-enter-from`);
|
|
6913
|
+
el.classList.add(`${name}-enter-to`);
|
|
6914
|
+
onTransitionEnd(el, duration, () => {
|
|
6915
|
+
el.classList.remove(`${name}-enter-active`, `${name}-enter-to`);
|
|
6916
|
+
});
|
|
6917
|
+
});
|
|
6918
|
+
});
|
|
6919
|
+
};
|
|
6920
|
+
vnode.data.hook.remove = (vn, rm) => {
|
|
6921
|
+
if (existingRemove)
|
|
6922
|
+
existingRemove(vn, () => { });
|
|
6923
|
+
const el = vn.elm;
|
|
6924
|
+
if (!el || !el.classList) {
|
|
6925
|
+
rm();
|
|
6926
|
+
return;
|
|
6927
|
+
}
|
|
6928
|
+
el.classList.add(`${name}-leave-from`, `${name}-leave-active`);
|
|
6929
|
+
requestAnimationFrame(() => {
|
|
6930
|
+
requestAnimationFrame(() => {
|
|
6931
|
+
el.classList.remove(`${name}-leave-from`);
|
|
6932
|
+
el.classList.add(`${name}-leave-to`);
|
|
6933
|
+
onTransitionEnd(el, duration, () => {
|
|
6934
|
+
el.classList.remove(`${name}-leave-active`, `${name}-leave-to`);
|
|
6935
|
+
rm();
|
|
6936
|
+
});
|
|
6937
|
+
});
|
|
6938
|
+
});
|
|
6939
|
+
};
|
|
6940
|
+
return vnode;
|
|
6941
|
+
}
|
|
6942
|
+
function onTransitionEnd(el, duration, cb) {
|
|
6943
|
+
if (typeof duration === 'number') {
|
|
6944
|
+
setTimeout(cb, duration);
|
|
6945
|
+
}
|
|
6946
|
+
else {
|
|
6947
|
+
const handler = () => {
|
|
6948
|
+
el.removeEventListener('transitionend', handler);
|
|
6949
|
+
cb();
|
|
6950
|
+
};
|
|
6951
|
+
el.addEventListener('transitionend', handler);
|
|
6952
|
+
}
|
|
6953
|
+
}
|
|
6954
|
+
function createPortalPlaceholder(target, children) {
|
|
6955
|
+
const portalChildren = children || [];
|
|
6956
|
+
return {
|
|
6957
|
+
sel: 'div',
|
|
6958
|
+
data: {
|
|
6959
|
+
style: { display: 'none' },
|
|
6960
|
+
attrs: { 'data-sygnal-portal': target },
|
|
6961
|
+
portalChildren,
|
|
6962
|
+
hook: {
|
|
6963
|
+
insert: (vnode) => {
|
|
6964
|
+
const container = document.querySelector(target);
|
|
6965
|
+
if (!container) {
|
|
6966
|
+
console.warn(`[Portal] Target "${target}" not found in DOM`);
|
|
6967
|
+
return;
|
|
6968
|
+
}
|
|
6969
|
+
const anchor = document.createElement('div');
|
|
6970
|
+
container.appendChild(anchor);
|
|
6971
|
+
vnode.data._portalVnode = portalPatch(anchor, {
|
|
6972
|
+
sel: 'div', data: {}, children: portalChildren,
|
|
6973
|
+
text: undefined, elm: undefined, key: undefined,
|
|
6974
|
+
});
|
|
6975
|
+
vnode.data._portalContainer = container;
|
|
6976
|
+
},
|
|
6977
|
+
postpatch: (oldVnode, newVnode) => {
|
|
6978
|
+
const prevPortalVnode = oldVnode.data?._portalVnode;
|
|
6979
|
+
const container = oldVnode.data?._portalContainer;
|
|
6980
|
+
if (!prevPortalVnode || !container)
|
|
6981
|
+
return;
|
|
6982
|
+
const newChildren = newVnode.data?.portalChildren || [];
|
|
6983
|
+
newVnode.data._portalVnode = portalPatch(prevPortalVnode, {
|
|
6984
|
+
sel: 'div', data: {}, children: newChildren,
|
|
6985
|
+
text: undefined, elm: undefined, key: undefined,
|
|
6986
|
+
});
|
|
6987
|
+
newVnode.data._portalContainer = container;
|
|
6988
|
+
},
|
|
6989
|
+
destroy: (vnode) => {
|
|
6990
|
+
const pv = vnode.data?._portalVnode;
|
|
6991
|
+
if (pv && pv.elm && pv.elm.parentNode) {
|
|
6992
|
+
pv.elm.parentNode.removeChild(pv.elm);
|
|
6993
|
+
}
|
|
6994
|
+
},
|
|
6995
|
+
},
|
|
6996
|
+
},
|
|
6997
|
+
children: [],
|
|
6998
|
+
text: undefined,
|
|
6999
|
+
elm: undefined,
|
|
7000
|
+
key: undefined,
|
|
7001
|
+
};
|
|
7002
|
+
}
|
|
3424
7003
|
function deepCopyVdom(obj) {
|
|
3425
7004
|
if (typeof obj === 'undefined')
|
|
3426
7005
|
return obj;
|
|
@@ -3795,7 +7374,7 @@ function run(app, drivers = {}, options = {}) {
|
|
|
3795
7374
|
if (!app.isSygnalComponent) {
|
|
3796
7375
|
const name = app.name || app.componentName || app.label || 'FUNCTIONAL_COMPONENT';
|
|
3797
7376
|
const view = app;
|
|
3798
|
-
const { model, intent, hmrActions, context, peers, components, initialState, calculated, storeCalculatedInState, DOMSourceName, stateSourceName, debug, } = app;
|
|
7377
|
+
const { model, intent, hmrActions, context, peers, components, initialState, calculated, storeCalculatedInState, DOMSourceName, stateSourceName, onError, debug, } = app;
|
|
3799
7378
|
const componentOptions = {
|
|
3800
7379
|
name,
|
|
3801
7380
|
view,
|
|
@@ -3810,6 +7389,7 @@ function run(app, drivers = {}, options = {}) {
|
|
|
3810
7389
|
storeCalculatedInState,
|
|
3811
7390
|
DOMSourceName,
|
|
3812
7391
|
stateSourceName,
|
|
7392
|
+
onError,
|
|
3813
7393
|
debug,
|
|
3814
7394
|
};
|
|
3815
7395
|
app = component(componentOptions);
|
|
@@ -3982,6 +7562,7 @@ var client = (element) => {
|
|
|
3982
7562
|
Wrapped.storeCalculatedInState = Component.storeCalculatedInState;
|
|
3983
7563
|
Wrapped.DOMSourceName = Component.DOMSourceName;
|
|
3984
7564
|
Wrapped.stateSourceName = Component.stateSourceName;
|
|
7565
|
+
Wrapped.onError = Component.onError;
|
|
3985
7566
|
Wrapped.debug = Component.debug;
|
|
3986
7567
|
Wrapped.componentName = Component.componentName || Component.name;
|
|
3987
7568
|
const app = run(Wrapped, {}, { mountPoint });
|