rx-tiny-flux 1.0.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/LICENSE +21 -0
- package/Readme.md +297 -0
- package/dist/rx-tiny-flux.esm.js +2175 -0
- package/examples/counter.js +132 -0
- package/jsconfig.json +8 -0
- package/package.json +40 -0
- package/rollup.config.js +43 -0
- package/src/actions.js +16 -0
- package/src/effects.js +33 -0
- package/src/index.js +8 -0
- package/src/reducers.js +67 -0
- package/src/rxjs.js +20 -0
- package/src/selectors.js +39 -0
- package/src/store.js +125 -0
- package/src/utils.js +25 -0
- package/src/zeppos.js +62 -0
|
@@ -0,0 +1,2175 @@
|
|
|
1
|
+
/******************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
16
|
+
|
|
17
|
+
var extendStatics = function(d, b) {
|
|
18
|
+
extendStatics = Object.setPrototypeOf ||
|
|
19
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
20
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
21
|
+
return extendStatics(d, b);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function __extends(d, b) {
|
|
25
|
+
if (typeof b !== "function" && b !== null)
|
|
26
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
27
|
+
extendStatics(d, b);
|
|
28
|
+
function __() { this.constructor = d; }
|
|
29
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
33
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
34
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
35
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
36
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
37
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
38
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function __generator(thisArg, body) {
|
|
43
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
44
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
45
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
46
|
+
function step(op) {
|
|
47
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
48
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
49
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
50
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
51
|
+
switch (op[0]) {
|
|
52
|
+
case 0: case 1: t = op; break;
|
|
53
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
54
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
55
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
56
|
+
default:
|
|
57
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
58
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
59
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
60
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
61
|
+
if (t[2]) _.ops.pop();
|
|
62
|
+
_.trys.pop(); continue;
|
|
63
|
+
}
|
|
64
|
+
op = body.call(thisArg, _);
|
|
65
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
66
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function __values(o) {
|
|
71
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
72
|
+
if (m) return m.call(o);
|
|
73
|
+
if (o && typeof o.length === "number") return {
|
|
74
|
+
next: function () {
|
|
75
|
+
if (o && i >= o.length) o = void 0;
|
|
76
|
+
return { value: o && o[i++], done: !o };
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function __read(o, n) {
|
|
83
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
84
|
+
if (!m) return o;
|
|
85
|
+
var i = m.call(o), r, ar = [], e;
|
|
86
|
+
try {
|
|
87
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
88
|
+
}
|
|
89
|
+
catch (error) { e = { error: error }; }
|
|
90
|
+
finally {
|
|
91
|
+
try {
|
|
92
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
93
|
+
}
|
|
94
|
+
finally { if (e) throw e.error; }
|
|
95
|
+
}
|
|
96
|
+
return ar;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function __spreadArray(to, from, pack) {
|
|
100
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
101
|
+
if (ar || !(i in from)) {
|
|
102
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
103
|
+
ar[i] = from[i];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function __await(v) {
|
|
110
|
+
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
114
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
115
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
116
|
+
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
117
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
118
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
119
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
120
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
121
|
+
function fulfill(value) { resume("next", value); }
|
|
122
|
+
function reject(value) { resume("throw", value); }
|
|
123
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function __asyncValues(o) {
|
|
127
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
128
|
+
var m = o[Symbol.asyncIterator], i;
|
|
129
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
130
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
131
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
135
|
+
var e = new Error(message);
|
|
136
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
function isFunction(value) {
|
|
140
|
+
return typeof value === 'function';
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function createErrorClass(createImpl) {
|
|
144
|
+
var _super = function (instance) {
|
|
145
|
+
Error.call(instance);
|
|
146
|
+
instance.stack = new Error().stack;
|
|
147
|
+
};
|
|
148
|
+
var ctorFunc = createImpl(_super);
|
|
149
|
+
ctorFunc.prototype = Object.create(Error.prototype);
|
|
150
|
+
ctorFunc.prototype.constructor = ctorFunc;
|
|
151
|
+
return ctorFunc;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
var UnsubscriptionError = createErrorClass(function (_super) {
|
|
155
|
+
return function UnsubscriptionErrorImpl(errors) {
|
|
156
|
+
_super(this);
|
|
157
|
+
this.message = errors
|
|
158
|
+
? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n ')
|
|
159
|
+
: '';
|
|
160
|
+
this.name = 'UnsubscriptionError';
|
|
161
|
+
this.errors = errors;
|
|
162
|
+
};
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
function arrRemove(arr, item) {
|
|
166
|
+
if (arr) {
|
|
167
|
+
var index = arr.indexOf(item);
|
|
168
|
+
0 <= index && arr.splice(index, 1);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
var Subscription = (function () {
|
|
173
|
+
function Subscription(initialTeardown) {
|
|
174
|
+
this.initialTeardown = initialTeardown;
|
|
175
|
+
this.closed = false;
|
|
176
|
+
this._parentage = null;
|
|
177
|
+
this._finalizers = null;
|
|
178
|
+
}
|
|
179
|
+
Subscription.prototype.unsubscribe = function () {
|
|
180
|
+
var e_1, _a, e_2, _b;
|
|
181
|
+
var errors;
|
|
182
|
+
if (!this.closed) {
|
|
183
|
+
this.closed = true;
|
|
184
|
+
var _parentage = this._parentage;
|
|
185
|
+
if (_parentage) {
|
|
186
|
+
this._parentage = null;
|
|
187
|
+
if (Array.isArray(_parentage)) {
|
|
188
|
+
try {
|
|
189
|
+
for (var _parentage_1 = __values(_parentage), _parentage_1_1 = _parentage_1.next(); !_parentage_1_1.done; _parentage_1_1 = _parentage_1.next()) {
|
|
190
|
+
var parent_1 = _parentage_1_1.value;
|
|
191
|
+
parent_1.remove(this);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
195
|
+
finally {
|
|
196
|
+
try {
|
|
197
|
+
if (_parentage_1_1 && !_parentage_1_1.done && (_a = _parentage_1.return)) _a.call(_parentage_1);
|
|
198
|
+
}
|
|
199
|
+
finally { if (e_1) throw e_1.error; }
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
_parentage.remove(this);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
var initialFinalizer = this.initialTeardown;
|
|
207
|
+
if (isFunction(initialFinalizer)) {
|
|
208
|
+
try {
|
|
209
|
+
initialFinalizer();
|
|
210
|
+
}
|
|
211
|
+
catch (e) {
|
|
212
|
+
errors = e instanceof UnsubscriptionError ? e.errors : [e];
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
var _finalizers = this._finalizers;
|
|
216
|
+
if (_finalizers) {
|
|
217
|
+
this._finalizers = null;
|
|
218
|
+
try {
|
|
219
|
+
for (var _finalizers_1 = __values(_finalizers), _finalizers_1_1 = _finalizers_1.next(); !_finalizers_1_1.done; _finalizers_1_1 = _finalizers_1.next()) {
|
|
220
|
+
var finalizer = _finalizers_1_1.value;
|
|
221
|
+
try {
|
|
222
|
+
execFinalizer(finalizer);
|
|
223
|
+
}
|
|
224
|
+
catch (err) {
|
|
225
|
+
errors = errors !== null && errors !== void 0 ? errors : [];
|
|
226
|
+
if (err instanceof UnsubscriptionError) {
|
|
227
|
+
errors = __spreadArray(__spreadArray([], __read(errors)), __read(err.errors));
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
errors.push(err);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
236
|
+
finally {
|
|
237
|
+
try {
|
|
238
|
+
if (_finalizers_1_1 && !_finalizers_1_1.done && (_b = _finalizers_1.return)) _b.call(_finalizers_1);
|
|
239
|
+
}
|
|
240
|
+
finally { if (e_2) throw e_2.error; }
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
if (errors) {
|
|
244
|
+
throw new UnsubscriptionError(errors);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
Subscription.prototype.add = function (teardown) {
|
|
249
|
+
var _a;
|
|
250
|
+
if (teardown && teardown !== this) {
|
|
251
|
+
if (this.closed) {
|
|
252
|
+
execFinalizer(teardown);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
if (teardown instanceof Subscription) {
|
|
256
|
+
if (teardown.closed || teardown._hasParent(this)) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
teardown._addParent(this);
|
|
260
|
+
}
|
|
261
|
+
(this._finalizers = (_a = this._finalizers) !== null && _a !== void 0 ? _a : []).push(teardown);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
Subscription.prototype._hasParent = function (parent) {
|
|
266
|
+
var _parentage = this._parentage;
|
|
267
|
+
return _parentage === parent || (Array.isArray(_parentage) && _parentage.includes(parent));
|
|
268
|
+
};
|
|
269
|
+
Subscription.prototype._addParent = function (parent) {
|
|
270
|
+
var _parentage = this._parentage;
|
|
271
|
+
this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
|
|
272
|
+
};
|
|
273
|
+
Subscription.prototype._removeParent = function (parent) {
|
|
274
|
+
var _parentage = this._parentage;
|
|
275
|
+
if (_parentage === parent) {
|
|
276
|
+
this._parentage = null;
|
|
277
|
+
}
|
|
278
|
+
else if (Array.isArray(_parentage)) {
|
|
279
|
+
arrRemove(_parentage, parent);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
Subscription.prototype.remove = function (teardown) {
|
|
283
|
+
var _finalizers = this._finalizers;
|
|
284
|
+
_finalizers && arrRemove(_finalizers, teardown);
|
|
285
|
+
if (teardown instanceof Subscription) {
|
|
286
|
+
teardown._removeParent(this);
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
Subscription.EMPTY = (function () {
|
|
290
|
+
var empty = new Subscription();
|
|
291
|
+
empty.closed = true;
|
|
292
|
+
return empty;
|
|
293
|
+
})();
|
|
294
|
+
return Subscription;
|
|
295
|
+
}());
|
|
296
|
+
var EMPTY_SUBSCRIPTION = Subscription.EMPTY;
|
|
297
|
+
function isSubscription(value) {
|
|
298
|
+
return (value instanceof Subscription ||
|
|
299
|
+
(value && 'closed' in value && isFunction(value.remove) && isFunction(value.add) && isFunction(value.unsubscribe)));
|
|
300
|
+
}
|
|
301
|
+
function execFinalizer(finalizer) {
|
|
302
|
+
if (isFunction(finalizer)) {
|
|
303
|
+
finalizer();
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
finalizer.unsubscribe();
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
var config = {
|
|
311
|
+
Promise: undefined};
|
|
312
|
+
|
|
313
|
+
var timeoutProvider = {
|
|
314
|
+
setTimeout: function (handler, timeout) {
|
|
315
|
+
var args = [];
|
|
316
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
317
|
+
args[_i - 2] = arguments[_i];
|
|
318
|
+
}
|
|
319
|
+
return setTimeout.apply(void 0, __spreadArray([handler, timeout], __read(args)));
|
|
320
|
+
},
|
|
321
|
+
clearTimeout: function (handle) {
|
|
322
|
+
return (clearTimeout)(handle);
|
|
323
|
+
},
|
|
324
|
+
delegate: undefined,
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
function reportUnhandledError(err) {
|
|
328
|
+
timeoutProvider.setTimeout(function () {
|
|
329
|
+
{
|
|
330
|
+
throw err;
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function noop() { }
|
|
336
|
+
|
|
337
|
+
function errorContext(cb) {
|
|
338
|
+
{
|
|
339
|
+
cb();
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
var Subscriber = (function (_super) {
|
|
344
|
+
__extends(Subscriber, _super);
|
|
345
|
+
function Subscriber(destination) {
|
|
346
|
+
var _this = _super.call(this) || this;
|
|
347
|
+
_this.isStopped = false;
|
|
348
|
+
if (destination) {
|
|
349
|
+
_this.destination = destination;
|
|
350
|
+
if (isSubscription(destination)) {
|
|
351
|
+
destination.add(_this);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
_this.destination = EMPTY_OBSERVER;
|
|
356
|
+
}
|
|
357
|
+
return _this;
|
|
358
|
+
}
|
|
359
|
+
Subscriber.create = function (next, error, complete) {
|
|
360
|
+
return new SafeSubscriber(next, error, complete);
|
|
361
|
+
};
|
|
362
|
+
Subscriber.prototype.next = function (value) {
|
|
363
|
+
if (this.isStopped) ;
|
|
364
|
+
else {
|
|
365
|
+
this._next(value);
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
Subscriber.prototype.error = function (err) {
|
|
369
|
+
if (this.isStopped) ;
|
|
370
|
+
else {
|
|
371
|
+
this.isStopped = true;
|
|
372
|
+
this._error(err);
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
Subscriber.prototype.complete = function () {
|
|
376
|
+
if (this.isStopped) ;
|
|
377
|
+
else {
|
|
378
|
+
this.isStopped = true;
|
|
379
|
+
this._complete();
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
Subscriber.prototype.unsubscribe = function () {
|
|
383
|
+
if (!this.closed) {
|
|
384
|
+
this.isStopped = true;
|
|
385
|
+
_super.prototype.unsubscribe.call(this);
|
|
386
|
+
this.destination = null;
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
Subscriber.prototype._next = function (value) {
|
|
390
|
+
this.destination.next(value);
|
|
391
|
+
};
|
|
392
|
+
Subscriber.prototype._error = function (err) {
|
|
393
|
+
try {
|
|
394
|
+
this.destination.error(err);
|
|
395
|
+
}
|
|
396
|
+
finally {
|
|
397
|
+
this.unsubscribe();
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
Subscriber.prototype._complete = function () {
|
|
401
|
+
try {
|
|
402
|
+
this.destination.complete();
|
|
403
|
+
}
|
|
404
|
+
finally {
|
|
405
|
+
this.unsubscribe();
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
return Subscriber;
|
|
409
|
+
}(Subscription));
|
|
410
|
+
var ConsumerObserver = (function () {
|
|
411
|
+
function ConsumerObserver(partialObserver) {
|
|
412
|
+
this.partialObserver = partialObserver;
|
|
413
|
+
}
|
|
414
|
+
ConsumerObserver.prototype.next = function (value) {
|
|
415
|
+
var partialObserver = this.partialObserver;
|
|
416
|
+
if (partialObserver.next) {
|
|
417
|
+
try {
|
|
418
|
+
partialObserver.next(value);
|
|
419
|
+
}
|
|
420
|
+
catch (error) {
|
|
421
|
+
handleUnhandledError(error);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
ConsumerObserver.prototype.error = function (err) {
|
|
426
|
+
var partialObserver = this.partialObserver;
|
|
427
|
+
if (partialObserver.error) {
|
|
428
|
+
try {
|
|
429
|
+
partialObserver.error(err);
|
|
430
|
+
}
|
|
431
|
+
catch (error) {
|
|
432
|
+
handleUnhandledError(error);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
handleUnhandledError(err);
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
ConsumerObserver.prototype.complete = function () {
|
|
440
|
+
var partialObserver = this.partialObserver;
|
|
441
|
+
if (partialObserver.complete) {
|
|
442
|
+
try {
|
|
443
|
+
partialObserver.complete();
|
|
444
|
+
}
|
|
445
|
+
catch (error) {
|
|
446
|
+
handleUnhandledError(error);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
return ConsumerObserver;
|
|
451
|
+
}());
|
|
452
|
+
var SafeSubscriber = (function (_super) {
|
|
453
|
+
__extends(SafeSubscriber, _super);
|
|
454
|
+
function SafeSubscriber(observerOrNext, error, complete) {
|
|
455
|
+
var _this = _super.call(this) || this;
|
|
456
|
+
var partialObserver;
|
|
457
|
+
if (isFunction(observerOrNext) || !observerOrNext) {
|
|
458
|
+
partialObserver = {
|
|
459
|
+
next: (observerOrNext !== null && observerOrNext !== void 0 ? observerOrNext : undefined),
|
|
460
|
+
error: error !== null && error !== void 0 ? error : undefined,
|
|
461
|
+
complete: complete !== null && complete !== void 0 ? complete : undefined,
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
else {
|
|
465
|
+
{
|
|
466
|
+
partialObserver = observerOrNext;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
_this.destination = new ConsumerObserver(partialObserver);
|
|
470
|
+
return _this;
|
|
471
|
+
}
|
|
472
|
+
return SafeSubscriber;
|
|
473
|
+
}(Subscriber));
|
|
474
|
+
function handleUnhandledError(error) {
|
|
475
|
+
{
|
|
476
|
+
reportUnhandledError(error);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
function defaultErrorHandler(err) {
|
|
480
|
+
throw err;
|
|
481
|
+
}
|
|
482
|
+
var EMPTY_OBSERVER = {
|
|
483
|
+
closed: true,
|
|
484
|
+
next: noop,
|
|
485
|
+
error: defaultErrorHandler,
|
|
486
|
+
complete: noop,
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
var observable = (function () { return (typeof Symbol === 'function' && Symbol.observable) || '@@observable'; })();
|
|
490
|
+
|
|
491
|
+
function identity(x) {
|
|
492
|
+
return x;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function pipeFromArray(fns) {
|
|
496
|
+
if (fns.length === 0) {
|
|
497
|
+
return identity;
|
|
498
|
+
}
|
|
499
|
+
if (fns.length === 1) {
|
|
500
|
+
return fns[0];
|
|
501
|
+
}
|
|
502
|
+
return function piped(input) {
|
|
503
|
+
return fns.reduce(function (prev, fn) { return fn(prev); }, input);
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
var Observable = (function () {
|
|
508
|
+
function Observable(subscribe) {
|
|
509
|
+
if (subscribe) {
|
|
510
|
+
this._subscribe = subscribe;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
Observable.prototype.lift = function (operator) {
|
|
514
|
+
var observable = new Observable();
|
|
515
|
+
observable.source = this;
|
|
516
|
+
observable.operator = operator;
|
|
517
|
+
return observable;
|
|
518
|
+
};
|
|
519
|
+
Observable.prototype.subscribe = function (observerOrNext, error, complete) {
|
|
520
|
+
var _this = this;
|
|
521
|
+
var subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete);
|
|
522
|
+
errorContext(function () {
|
|
523
|
+
var _a = _this, operator = _a.operator, source = _a.source;
|
|
524
|
+
subscriber.add(operator
|
|
525
|
+
?
|
|
526
|
+
operator.call(subscriber, source)
|
|
527
|
+
: source
|
|
528
|
+
?
|
|
529
|
+
_this._subscribe(subscriber)
|
|
530
|
+
:
|
|
531
|
+
_this._trySubscribe(subscriber));
|
|
532
|
+
});
|
|
533
|
+
return subscriber;
|
|
534
|
+
};
|
|
535
|
+
Observable.prototype._trySubscribe = function (sink) {
|
|
536
|
+
try {
|
|
537
|
+
return this._subscribe(sink);
|
|
538
|
+
}
|
|
539
|
+
catch (err) {
|
|
540
|
+
sink.error(err);
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
Observable.prototype.forEach = function (next, promiseCtor) {
|
|
544
|
+
var _this = this;
|
|
545
|
+
promiseCtor = getPromiseCtor(promiseCtor);
|
|
546
|
+
return new promiseCtor(function (resolve, reject) {
|
|
547
|
+
var subscriber = new SafeSubscriber({
|
|
548
|
+
next: function (value) {
|
|
549
|
+
try {
|
|
550
|
+
next(value);
|
|
551
|
+
}
|
|
552
|
+
catch (err) {
|
|
553
|
+
reject(err);
|
|
554
|
+
subscriber.unsubscribe();
|
|
555
|
+
}
|
|
556
|
+
},
|
|
557
|
+
error: reject,
|
|
558
|
+
complete: resolve,
|
|
559
|
+
});
|
|
560
|
+
_this.subscribe(subscriber);
|
|
561
|
+
});
|
|
562
|
+
};
|
|
563
|
+
Observable.prototype._subscribe = function (subscriber) {
|
|
564
|
+
var _a;
|
|
565
|
+
return (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber);
|
|
566
|
+
};
|
|
567
|
+
Observable.prototype[observable] = function () {
|
|
568
|
+
return this;
|
|
569
|
+
};
|
|
570
|
+
Observable.prototype.pipe = function () {
|
|
571
|
+
var operations = [];
|
|
572
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
573
|
+
operations[_i] = arguments[_i];
|
|
574
|
+
}
|
|
575
|
+
return pipeFromArray(operations)(this);
|
|
576
|
+
};
|
|
577
|
+
Observable.prototype.toPromise = function (promiseCtor) {
|
|
578
|
+
var _this = this;
|
|
579
|
+
promiseCtor = getPromiseCtor(promiseCtor);
|
|
580
|
+
return new promiseCtor(function (resolve, reject) {
|
|
581
|
+
var value;
|
|
582
|
+
_this.subscribe(function (x) { return (value = x); }, function (err) { return reject(err); }, function () { return resolve(value); });
|
|
583
|
+
});
|
|
584
|
+
};
|
|
585
|
+
Observable.create = function (subscribe) {
|
|
586
|
+
return new Observable(subscribe);
|
|
587
|
+
};
|
|
588
|
+
return Observable;
|
|
589
|
+
}());
|
|
590
|
+
function getPromiseCtor(promiseCtor) {
|
|
591
|
+
var _a;
|
|
592
|
+
return (_a = promiseCtor !== null && promiseCtor !== void 0 ? promiseCtor : config.Promise) !== null && _a !== void 0 ? _a : Promise;
|
|
593
|
+
}
|
|
594
|
+
function isObserver(value) {
|
|
595
|
+
return value && isFunction(value.next) && isFunction(value.error) && isFunction(value.complete);
|
|
596
|
+
}
|
|
597
|
+
function isSubscriber(value) {
|
|
598
|
+
return (value && value instanceof Subscriber) || (isObserver(value) && isSubscription(value));
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
function hasLift(source) {
|
|
602
|
+
return isFunction(source === null || source === void 0 ? void 0 : source.lift);
|
|
603
|
+
}
|
|
604
|
+
function operate(init) {
|
|
605
|
+
return function (source) {
|
|
606
|
+
if (hasLift(source)) {
|
|
607
|
+
return source.lift(function (liftedSource) {
|
|
608
|
+
try {
|
|
609
|
+
return init(liftedSource, this);
|
|
610
|
+
}
|
|
611
|
+
catch (err) {
|
|
612
|
+
this.error(err);
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
throw new TypeError('Unable to lift unknown Observable type');
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
function createOperatorSubscriber(destination, onNext, onComplete, onError, onFinalize) {
|
|
621
|
+
return new OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize);
|
|
622
|
+
}
|
|
623
|
+
var OperatorSubscriber = (function (_super) {
|
|
624
|
+
__extends(OperatorSubscriber, _super);
|
|
625
|
+
function OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize, shouldUnsubscribe) {
|
|
626
|
+
var _this = _super.call(this, destination) || this;
|
|
627
|
+
_this.onFinalize = onFinalize;
|
|
628
|
+
_this.shouldUnsubscribe = shouldUnsubscribe;
|
|
629
|
+
_this._next = onNext
|
|
630
|
+
? function (value) {
|
|
631
|
+
try {
|
|
632
|
+
onNext(value);
|
|
633
|
+
}
|
|
634
|
+
catch (err) {
|
|
635
|
+
destination.error(err);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
: _super.prototype._next;
|
|
639
|
+
_this._error = onError
|
|
640
|
+
? function (err) {
|
|
641
|
+
try {
|
|
642
|
+
onError(err);
|
|
643
|
+
}
|
|
644
|
+
catch (err) {
|
|
645
|
+
destination.error(err);
|
|
646
|
+
}
|
|
647
|
+
finally {
|
|
648
|
+
this.unsubscribe();
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
: _super.prototype._error;
|
|
652
|
+
_this._complete = onComplete
|
|
653
|
+
? function () {
|
|
654
|
+
try {
|
|
655
|
+
onComplete();
|
|
656
|
+
}
|
|
657
|
+
catch (err) {
|
|
658
|
+
destination.error(err);
|
|
659
|
+
}
|
|
660
|
+
finally {
|
|
661
|
+
this.unsubscribe();
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
: _super.prototype._complete;
|
|
665
|
+
return _this;
|
|
666
|
+
}
|
|
667
|
+
OperatorSubscriber.prototype.unsubscribe = function () {
|
|
668
|
+
var _a;
|
|
669
|
+
if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
|
|
670
|
+
var closed_1 = this.closed;
|
|
671
|
+
_super.prototype.unsubscribe.call(this);
|
|
672
|
+
!closed_1 && ((_a = this.onFinalize) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
return OperatorSubscriber;
|
|
676
|
+
}(Subscriber));
|
|
677
|
+
|
|
678
|
+
var ObjectUnsubscribedError = createErrorClass(function (_super) {
|
|
679
|
+
return function ObjectUnsubscribedErrorImpl() {
|
|
680
|
+
_super(this);
|
|
681
|
+
this.name = 'ObjectUnsubscribedError';
|
|
682
|
+
this.message = 'object unsubscribed';
|
|
683
|
+
};
|
|
684
|
+
});
|
|
685
|
+
|
|
686
|
+
var Subject = (function (_super) {
|
|
687
|
+
__extends(Subject, _super);
|
|
688
|
+
function Subject() {
|
|
689
|
+
var _this = _super.call(this) || this;
|
|
690
|
+
_this.closed = false;
|
|
691
|
+
_this.currentObservers = null;
|
|
692
|
+
_this.observers = [];
|
|
693
|
+
_this.isStopped = false;
|
|
694
|
+
_this.hasError = false;
|
|
695
|
+
_this.thrownError = null;
|
|
696
|
+
return _this;
|
|
697
|
+
}
|
|
698
|
+
Subject.prototype.lift = function (operator) {
|
|
699
|
+
var subject = new AnonymousSubject(this, this);
|
|
700
|
+
subject.operator = operator;
|
|
701
|
+
return subject;
|
|
702
|
+
};
|
|
703
|
+
Subject.prototype._throwIfClosed = function () {
|
|
704
|
+
if (this.closed) {
|
|
705
|
+
throw new ObjectUnsubscribedError();
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
Subject.prototype.next = function (value) {
|
|
709
|
+
var _this = this;
|
|
710
|
+
errorContext(function () {
|
|
711
|
+
var e_1, _a;
|
|
712
|
+
_this._throwIfClosed();
|
|
713
|
+
if (!_this.isStopped) {
|
|
714
|
+
if (!_this.currentObservers) {
|
|
715
|
+
_this.currentObservers = Array.from(_this.observers);
|
|
716
|
+
}
|
|
717
|
+
try {
|
|
718
|
+
for (var _b = __values(_this.currentObservers), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
719
|
+
var observer = _c.value;
|
|
720
|
+
observer.next(value);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
724
|
+
finally {
|
|
725
|
+
try {
|
|
726
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
727
|
+
}
|
|
728
|
+
finally { if (e_1) throw e_1.error; }
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
});
|
|
732
|
+
};
|
|
733
|
+
Subject.prototype.error = function (err) {
|
|
734
|
+
var _this = this;
|
|
735
|
+
errorContext(function () {
|
|
736
|
+
_this._throwIfClosed();
|
|
737
|
+
if (!_this.isStopped) {
|
|
738
|
+
_this.hasError = _this.isStopped = true;
|
|
739
|
+
_this.thrownError = err;
|
|
740
|
+
var observers = _this.observers;
|
|
741
|
+
while (observers.length) {
|
|
742
|
+
observers.shift().error(err);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
});
|
|
746
|
+
};
|
|
747
|
+
Subject.prototype.complete = function () {
|
|
748
|
+
var _this = this;
|
|
749
|
+
errorContext(function () {
|
|
750
|
+
_this._throwIfClosed();
|
|
751
|
+
if (!_this.isStopped) {
|
|
752
|
+
_this.isStopped = true;
|
|
753
|
+
var observers = _this.observers;
|
|
754
|
+
while (observers.length) {
|
|
755
|
+
observers.shift().complete();
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
};
|
|
760
|
+
Subject.prototype.unsubscribe = function () {
|
|
761
|
+
this.isStopped = this.closed = true;
|
|
762
|
+
this.observers = this.currentObservers = null;
|
|
763
|
+
};
|
|
764
|
+
Object.defineProperty(Subject.prototype, "observed", {
|
|
765
|
+
get: function () {
|
|
766
|
+
var _a;
|
|
767
|
+
return ((_a = this.observers) === null || _a === void 0 ? void 0 : _a.length) > 0;
|
|
768
|
+
},
|
|
769
|
+
enumerable: false,
|
|
770
|
+
configurable: true
|
|
771
|
+
});
|
|
772
|
+
Subject.prototype._trySubscribe = function (subscriber) {
|
|
773
|
+
this._throwIfClosed();
|
|
774
|
+
return _super.prototype._trySubscribe.call(this, subscriber);
|
|
775
|
+
};
|
|
776
|
+
Subject.prototype._subscribe = function (subscriber) {
|
|
777
|
+
this._throwIfClosed();
|
|
778
|
+
this._checkFinalizedStatuses(subscriber);
|
|
779
|
+
return this._innerSubscribe(subscriber);
|
|
780
|
+
};
|
|
781
|
+
Subject.prototype._innerSubscribe = function (subscriber) {
|
|
782
|
+
var _this = this;
|
|
783
|
+
var _a = this, hasError = _a.hasError, isStopped = _a.isStopped, observers = _a.observers;
|
|
784
|
+
if (hasError || isStopped) {
|
|
785
|
+
return EMPTY_SUBSCRIPTION;
|
|
786
|
+
}
|
|
787
|
+
this.currentObservers = null;
|
|
788
|
+
observers.push(subscriber);
|
|
789
|
+
return new Subscription(function () {
|
|
790
|
+
_this.currentObservers = null;
|
|
791
|
+
arrRemove(observers, subscriber);
|
|
792
|
+
});
|
|
793
|
+
};
|
|
794
|
+
Subject.prototype._checkFinalizedStatuses = function (subscriber) {
|
|
795
|
+
var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, isStopped = _a.isStopped;
|
|
796
|
+
if (hasError) {
|
|
797
|
+
subscriber.error(thrownError);
|
|
798
|
+
}
|
|
799
|
+
else if (isStopped) {
|
|
800
|
+
subscriber.complete();
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
Subject.prototype.asObservable = function () {
|
|
804
|
+
var observable = new Observable();
|
|
805
|
+
observable.source = this;
|
|
806
|
+
return observable;
|
|
807
|
+
};
|
|
808
|
+
Subject.create = function (destination, source) {
|
|
809
|
+
return new AnonymousSubject(destination, source);
|
|
810
|
+
};
|
|
811
|
+
return Subject;
|
|
812
|
+
}(Observable));
|
|
813
|
+
var AnonymousSubject = (function (_super) {
|
|
814
|
+
__extends(AnonymousSubject, _super);
|
|
815
|
+
function AnonymousSubject(destination, source) {
|
|
816
|
+
var _this = _super.call(this) || this;
|
|
817
|
+
_this.destination = destination;
|
|
818
|
+
_this.source = source;
|
|
819
|
+
return _this;
|
|
820
|
+
}
|
|
821
|
+
AnonymousSubject.prototype.next = function (value) {
|
|
822
|
+
var _a, _b;
|
|
823
|
+
(_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.next) === null || _b === void 0 ? void 0 : _b.call(_a, value);
|
|
824
|
+
};
|
|
825
|
+
AnonymousSubject.prototype.error = function (err) {
|
|
826
|
+
var _a, _b;
|
|
827
|
+
(_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.call(_a, err);
|
|
828
|
+
};
|
|
829
|
+
AnonymousSubject.prototype.complete = function () {
|
|
830
|
+
var _a, _b;
|
|
831
|
+
(_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.complete) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
832
|
+
};
|
|
833
|
+
AnonymousSubject.prototype._subscribe = function (subscriber) {
|
|
834
|
+
var _a, _b;
|
|
835
|
+
return (_b = (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber)) !== null && _b !== void 0 ? _b : EMPTY_SUBSCRIPTION;
|
|
836
|
+
};
|
|
837
|
+
return AnonymousSubject;
|
|
838
|
+
}(Subject));
|
|
839
|
+
|
|
840
|
+
var BehaviorSubject = (function (_super) {
|
|
841
|
+
__extends(BehaviorSubject, _super);
|
|
842
|
+
function BehaviorSubject(_value) {
|
|
843
|
+
var _this = _super.call(this) || this;
|
|
844
|
+
_this._value = _value;
|
|
845
|
+
return _this;
|
|
846
|
+
}
|
|
847
|
+
Object.defineProperty(BehaviorSubject.prototype, "value", {
|
|
848
|
+
get: function () {
|
|
849
|
+
return this.getValue();
|
|
850
|
+
},
|
|
851
|
+
enumerable: false,
|
|
852
|
+
configurable: true
|
|
853
|
+
});
|
|
854
|
+
BehaviorSubject.prototype._subscribe = function (subscriber) {
|
|
855
|
+
var subscription = _super.prototype._subscribe.call(this, subscriber);
|
|
856
|
+
!subscription.closed && subscriber.next(this._value);
|
|
857
|
+
return subscription;
|
|
858
|
+
};
|
|
859
|
+
BehaviorSubject.prototype.getValue = function () {
|
|
860
|
+
var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, _value = _a._value;
|
|
861
|
+
if (hasError) {
|
|
862
|
+
throw thrownError;
|
|
863
|
+
}
|
|
864
|
+
this._throwIfClosed();
|
|
865
|
+
return _value;
|
|
866
|
+
};
|
|
867
|
+
BehaviorSubject.prototype.next = function (value) {
|
|
868
|
+
_super.prototype.next.call(this, (this._value = value));
|
|
869
|
+
};
|
|
870
|
+
return BehaviorSubject;
|
|
871
|
+
}(Subject));
|
|
872
|
+
|
|
873
|
+
var dateTimestampProvider = {
|
|
874
|
+
now: function () {
|
|
875
|
+
return (dateTimestampProvider.delegate || Date).now();
|
|
876
|
+
},
|
|
877
|
+
delegate: undefined,
|
|
878
|
+
};
|
|
879
|
+
|
|
880
|
+
var ReplaySubject = (function (_super) {
|
|
881
|
+
__extends(ReplaySubject, _super);
|
|
882
|
+
function ReplaySubject(_bufferSize, _windowTime, _timestampProvider) {
|
|
883
|
+
if (_bufferSize === void 0) { _bufferSize = Infinity; }
|
|
884
|
+
if (_windowTime === void 0) { _windowTime = Infinity; }
|
|
885
|
+
if (_timestampProvider === void 0) { _timestampProvider = dateTimestampProvider; }
|
|
886
|
+
var _this = _super.call(this) || this;
|
|
887
|
+
_this._bufferSize = _bufferSize;
|
|
888
|
+
_this._windowTime = _windowTime;
|
|
889
|
+
_this._timestampProvider = _timestampProvider;
|
|
890
|
+
_this._buffer = [];
|
|
891
|
+
_this._infiniteTimeWindow = true;
|
|
892
|
+
_this._infiniteTimeWindow = _windowTime === Infinity;
|
|
893
|
+
_this._bufferSize = Math.max(1, _bufferSize);
|
|
894
|
+
_this._windowTime = Math.max(1, _windowTime);
|
|
895
|
+
return _this;
|
|
896
|
+
}
|
|
897
|
+
ReplaySubject.prototype.next = function (value) {
|
|
898
|
+
var _a = this, isStopped = _a.isStopped, _buffer = _a._buffer, _infiniteTimeWindow = _a._infiniteTimeWindow, _timestampProvider = _a._timestampProvider, _windowTime = _a._windowTime;
|
|
899
|
+
if (!isStopped) {
|
|
900
|
+
_buffer.push(value);
|
|
901
|
+
!_infiniteTimeWindow && _buffer.push(_timestampProvider.now() + _windowTime);
|
|
902
|
+
}
|
|
903
|
+
this._trimBuffer();
|
|
904
|
+
_super.prototype.next.call(this, value);
|
|
905
|
+
};
|
|
906
|
+
ReplaySubject.prototype._subscribe = function (subscriber) {
|
|
907
|
+
this._throwIfClosed();
|
|
908
|
+
this._trimBuffer();
|
|
909
|
+
var subscription = this._innerSubscribe(subscriber);
|
|
910
|
+
var _a = this, _infiniteTimeWindow = _a._infiniteTimeWindow, _buffer = _a._buffer;
|
|
911
|
+
var copy = _buffer.slice();
|
|
912
|
+
for (var i = 0; i < copy.length && !subscriber.closed; i += _infiniteTimeWindow ? 1 : 2) {
|
|
913
|
+
subscriber.next(copy[i]);
|
|
914
|
+
}
|
|
915
|
+
this._checkFinalizedStatuses(subscriber);
|
|
916
|
+
return subscription;
|
|
917
|
+
};
|
|
918
|
+
ReplaySubject.prototype._trimBuffer = function () {
|
|
919
|
+
var _a = this, _bufferSize = _a._bufferSize, _timestampProvider = _a._timestampProvider, _buffer = _a._buffer, _infiniteTimeWindow = _a._infiniteTimeWindow;
|
|
920
|
+
var adjustedBufferSize = (_infiniteTimeWindow ? 1 : 2) * _bufferSize;
|
|
921
|
+
_bufferSize < Infinity && adjustedBufferSize < _buffer.length && _buffer.splice(0, _buffer.length - adjustedBufferSize);
|
|
922
|
+
if (!_infiniteTimeWindow) {
|
|
923
|
+
var now = _timestampProvider.now();
|
|
924
|
+
var last = 0;
|
|
925
|
+
for (var i = 1; i < _buffer.length && _buffer[i] <= now; i += 2) {
|
|
926
|
+
last = i;
|
|
927
|
+
}
|
|
928
|
+
last && _buffer.splice(0, last + 1);
|
|
929
|
+
}
|
|
930
|
+
};
|
|
931
|
+
return ReplaySubject;
|
|
932
|
+
}(Subject));
|
|
933
|
+
|
|
934
|
+
var Action = (function (_super) {
|
|
935
|
+
__extends(Action, _super);
|
|
936
|
+
function Action(scheduler, work) {
|
|
937
|
+
return _super.call(this) || this;
|
|
938
|
+
}
|
|
939
|
+
Action.prototype.schedule = function (state, delay) {
|
|
940
|
+
return this;
|
|
941
|
+
};
|
|
942
|
+
return Action;
|
|
943
|
+
}(Subscription));
|
|
944
|
+
|
|
945
|
+
var intervalProvider = {
|
|
946
|
+
setInterval: function (handler, timeout) {
|
|
947
|
+
var args = [];
|
|
948
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
949
|
+
args[_i - 2] = arguments[_i];
|
|
950
|
+
}
|
|
951
|
+
return setInterval.apply(void 0, __spreadArray([handler, timeout], __read(args)));
|
|
952
|
+
},
|
|
953
|
+
clearInterval: function (handle) {
|
|
954
|
+
return (clearInterval)(handle);
|
|
955
|
+
},
|
|
956
|
+
delegate: undefined,
|
|
957
|
+
};
|
|
958
|
+
|
|
959
|
+
var AsyncAction = (function (_super) {
|
|
960
|
+
__extends(AsyncAction, _super);
|
|
961
|
+
function AsyncAction(scheduler, work) {
|
|
962
|
+
var _this = _super.call(this, scheduler, work) || this;
|
|
963
|
+
_this.scheduler = scheduler;
|
|
964
|
+
_this.work = work;
|
|
965
|
+
_this.pending = false;
|
|
966
|
+
return _this;
|
|
967
|
+
}
|
|
968
|
+
AsyncAction.prototype.schedule = function (state, delay) {
|
|
969
|
+
var _a;
|
|
970
|
+
if (delay === void 0) { delay = 0; }
|
|
971
|
+
if (this.closed) {
|
|
972
|
+
return this;
|
|
973
|
+
}
|
|
974
|
+
this.state = state;
|
|
975
|
+
var id = this.id;
|
|
976
|
+
var scheduler = this.scheduler;
|
|
977
|
+
if (id != null) {
|
|
978
|
+
this.id = this.recycleAsyncId(scheduler, id, delay);
|
|
979
|
+
}
|
|
980
|
+
this.pending = true;
|
|
981
|
+
this.delay = delay;
|
|
982
|
+
this.id = (_a = this.id) !== null && _a !== void 0 ? _a : this.requestAsyncId(scheduler, this.id, delay);
|
|
983
|
+
return this;
|
|
984
|
+
};
|
|
985
|
+
AsyncAction.prototype.requestAsyncId = function (scheduler, _id, delay) {
|
|
986
|
+
if (delay === void 0) { delay = 0; }
|
|
987
|
+
return intervalProvider.setInterval(scheduler.flush.bind(scheduler, this), delay);
|
|
988
|
+
};
|
|
989
|
+
AsyncAction.prototype.recycleAsyncId = function (_scheduler, id, delay) {
|
|
990
|
+
if (delay === void 0) { delay = 0; }
|
|
991
|
+
if (delay != null && this.delay === delay && this.pending === false) {
|
|
992
|
+
return id;
|
|
993
|
+
}
|
|
994
|
+
if (id != null) {
|
|
995
|
+
intervalProvider.clearInterval(id);
|
|
996
|
+
}
|
|
997
|
+
return undefined;
|
|
998
|
+
};
|
|
999
|
+
AsyncAction.prototype.execute = function (state, delay) {
|
|
1000
|
+
if (this.closed) {
|
|
1001
|
+
return new Error('executing a cancelled action');
|
|
1002
|
+
}
|
|
1003
|
+
this.pending = false;
|
|
1004
|
+
var error = this._execute(state, delay);
|
|
1005
|
+
if (error) {
|
|
1006
|
+
return error;
|
|
1007
|
+
}
|
|
1008
|
+
else if (this.pending === false && this.id != null) {
|
|
1009
|
+
this.id = this.recycleAsyncId(this.scheduler, this.id, null);
|
|
1010
|
+
}
|
|
1011
|
+
};
|
|
1012
|
+
AsyncAction.prototype._execute = function (state, _delay) {
|
|
1013
|
+
var errored = false;
|
|
1014
|
+
var errorValue;
|
|
1015
|
+
try {
|
|
1016
|
+
this.work(state);
|
|
1017
|
+
}
|
|
1018
|
+
catch (e) {
|
|
1019
|
+
errored = true;
|
|
1020
|
+
errorValue = e ? e : new Error('Scheduled action threw falsy error');
|
|
1021
|
+
}
|
|
1022
|
+
if (errored) {
|
|
1023
|
+
this.unsubscribe();
|
|
1024
|
+
return errorValue;
|
|
1025
|
+
}
|
|
1026
|
+
};
|
|
1027
|
+
AsyncAction.prototype.unsubscribe = function () {
|
|
1028
|
+
if (!this.closed) {
|
|
1029
|
+
var _a = this, id = _a.id, scheduler = _a.scheduler;
|
|
1030
|
+
var actions = scheduler.actions;
|
|
1031
|
+
this.work = this.state = this.scheduler = null;
|
|
1032
|
+
this.pending = false;
|
|
1033
|
+
arrRemove(actions, this);
|
|
1034
|
+
if (id != null) {
|
|
1035
|
+
this.id = this.recycleAsyncId(scheduler, id, null);
|
|
1036
|
+
}
|
|
1037
|
+
this.delay = null;
|
|
1038
|
+
_super.prototype.unsubscribe.call(this);
|
|
1039
|
+
}
|
|
1040
|
+
};
|
|
1041
|
+
return AsyncAction;
|
|
1042
|
+
}(Action));
|
|
1043
|
+
|
|
1044
|
+
var Scheduler = (function () {
|
|
1045
|
+
function Scheduler(schedulerActionCtor, now) {
|
|
1046
|
+
if (now === void 0) { now = Scheduler.now; }
|
|
1047
|
+
this.schedulerActionCtor = schedulerActionCtor;
|
|
1048
|
+
this.now = now;
|
|
1049
|
+
}
|
|
1050
|
+
Scheduler.prototype.schedule = function (work, delay, state) {
|
|
1051
|
+
if (delay === void 0) { delay = 0; }
|
|
1052
|
+
return new this.schedulerActionCtor(this, work).schedule(state, delay);
|
|
1053
|
+
};
|
|
1054
|
+
Scheduler.now = dateTimestampProvider.now;
|
|
1055
|
+
return Scheduler;
|
|
1056
|
+
}());
|
|
1057
|
+
|
|
1058
|
+
var AsyncScheduler = (function (_super) {
|
|
1059
|
+
__extends(AsyncScheduler, _super);
|
|
1060
|
+
function AsyncScheduler(SchedulerAction, now) {
|
|
1061
|
+
if (now === void 0) { now = Scheduler.now; }
|
|
1062
|
+
var _this = _super.call(this, SchedulerAction, now) || this;
|
|
1063
|
+
_this.actions = [];
|
|
1064
|
+
_this._active = false;
|
|
1065
|
+
return _this;
|
|
1066
|
+
}
|
|
1067
|
+
AsyncScheduler.prototype.flush = function (action) {
|
|
1068
|
+
var actions = this.actions;
|
|
1069
|
+
if (this._active) {
|
|
1070
|
+
actions.push(action);
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
var error;
|
|
1074
|
+
this._active = true;
|
|
1075
|
+
do {
|
|
1076
|
+
if ((error = action.execute(action.state, action.delay))) {
|
|
1077
|
+
break;
|
|
1078
|
+
}
|
|
1079
|
+
} while ((action = actions.shift()));
|
|
1080
|
+
this._active = false;
|
|
1081
|
+
if (error) {
|
|
1082
|
+
while ((action = actions.shift())) {
|
|
1083
|
+
action.unsubscribe();
|
|
1084
|
+
}
|
|
1085
|
+
throw error;
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1088
|
+
return AsyncScheduler;
|
|
1089
|
+
}(Scheduler));
|
|
1090
|
+
|
|
1091
|
+
var asyncScheduler = new AsyncScheduler(AsyncAction);
|
|
1092
|
+
var async = asyncScheduler;
|
|
1093
|
+
|
|
1094
|
+
var EMPTY = new Observable(function (subscriber) { return subscriber.complete(); });
|
|
1095
|
+
|
|
1096
|
+
function isScheduler(value) {
|
|
1097
|
+
return value && isFunction(value.schedule);
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
function last(arr) {
|
|
1101
|
+
return arr[arr.length - 1];
|
|
1102
|
+
}
|
|
1103
|
+
function popScheduler(args) {
|
|
1104
|
+
return isScheduler(last(args)) ? args.pop() : undefined;
|
|
1105
|
+
}
|
|
1106
|
+
function popNumber(args, defaultValue) {
|
|
1107
|
+
return typeof last(args) === 'number' ? args.pop() : defaultValue;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
var isArrayLike = (function (x) { return x && typeof x.length === 'number' && typeof x !== 'function'; });
|
|
1111
|
+
|
|
1112
|
+
function isPromise(value) {
|
|
1113
|
+
return isFunction(value === null || value === void 0 ? void 0 : value.then);
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
function isInteropObservable(input) {
|
|
1117
|
+
return isFunction(input[observable]);
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
function isAsyncIterable(obj) {
|
|
1121
|
+
return Symbol.asyncIterator && isFunction(obj === null || obj === void 0 ? void 0 : obj[Symbol.asyncIterator]);
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
function createInvalidObservableTypeError(input) {
|
|
1125
|
+
return new TypeError("You provided " + (input !== null && typeof input === 'object' ? 'an invalid object' : "'" + input + "'") + " where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.");
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
function getSymbolIterator() {
|
|
1129
|
+
if (typeof Symbol !== 'function' || !Symbol.iterator) {
|
|
1130
|
+
return '@@iterator';
|
|
1131
|
+
}
|
|
1132
|
+
return Symbol.iterator;
|
|
1133
|
+
}
|
|
1134
|
+
var iterator = getSymbolIterator();
|
|
1135
|
+
|
|
1136
|
+
function isIterable(input) {
|
|
1137
|
+
return isFunction(input === null || input === void 0 ? void 0 : input[iterator]);
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
function readableStreamLikeToAsyncGenerator(readableStream) {
|
|
1141
|
+
return __asyncGenerator(this, arguments, function readableStreamLikeToAsyncGenerator_1() {
|
|
1142
|
+
var reader, _a, value, done;
|
|
1143
|
+
return __generator(this, function (_b) {
|
|
1144
|
+
switch (_b.label) {
|
|
1145
|
+
case 0:
|
|
1146
|
+
reader = readableStream.getReader();
|
|
1147
|
+
_b.label = 1;
|
|
1148
|
+
case 1:
|
|
1149
|
+
_b.trys.push([1, , 9, 10]);
|
|
1150
|
+
_b.label = 2;
|
|
1151
|
+
case 2:
|
|
1152
|
+
return [4, __await(reader.read())];
|
|
1153
|
+
case 3:
|
|
1154
|
+
_a = _b.sent(), value = _a.value, done = _a.done;
|
|
1155
|
+
if (!done) return [3, 5];
|
|
1156
|
+
return [4, __await(void 0)];
|
|
1157
|
+
case 4: return [2, _b.sent()];
|
|
1158
|
+
case 5: return [4, __await(value)];
|
|
1159
|
+
case 6: return [4, _b.sent()];
|
|
1160
|
+
case 7:
|
|
1161
|
+
_b.sent();
|
|
1162
|
+
return [3, 2];
|
|
1163
|
+
case 8: return [3, 10];
|
|
1164
|
+
case 9:
|
|
1165
|
+
reader.releaseLock();
|
|
1166
|
+
return [7];
|
|
1167
|
+
case 10: return [2];
|
|
1168
|
+
}
|
|
1169
|
+
});
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1172
|
+
function isReadableStreamLike(obj) {
|
|
1173
|
+
return isFunction(obj === null || obj === void 0 ? void 0 : obj.getReader);
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
function innerFrom(input) {
|
|
1177
|
+
if (input instanceof Observable) {
|
|
1178
|
+
return input;
|
|
1179
|
+
}
|
|
1180
|
+
if (input != null) {
|
|
1181
|
+
if (isInteropObservable(input)) {
|
|
1182
|
+
return fromInteropObservable(input);
|
|
1183
|
+
}
|
|
1184
|
+
if (isArrayLike(input)) {
|
|
1185
|
+
return fromArrayLike(input);
|
|
1186
|
+
}
|
|
1187
|
+
if (isPromise(input)) {
|
|
1188
|
+
return fromPromise(input);
|
|
1189
|
+
}
|
|
1190
|
+
if (isAsyncIterable(input)) {
|
|
1191
|
+
return fromAsyncIterable(input);
|
|
1192
|
+
}
|
|
1193
|
+
if (isIterable(input)) {
|
|
1194
|
+
return fromIterable(input);
|
|
1195
|
+
}
|
|
1196
|
+
if (isReadableStreamLike(input)) {
|
|
1197
|
+
return fromReadableStreamLike(input);
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
throw createInvalidObservableTypeError(input);
|
|
1201
|
+
}
|
|
1202
|
+
function fromInteropObservable(obj) {
|
|
1203
|
+
return new Observable(function (subscriber) {
|
|
1204
|
+
var obs = obj[observable]();
|
|
1205
|
+
if (isFunction(obs.subscribe)) {
|
|
1206
|
+
return obs.subscribe(subscriber);
|
|
1207
|
+
}
|
|
1208
|
+
throw new TypeError('Provided object does not correctly implement Symbol.observable');
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
function fromArrayLike(array) {
|
|
1212
|
+
return new Observable(function (subscriber) {
|
|
1213
|
+
for (var i = 0; i < array.length && !subscriber.closed; i++) {
|
|
1214
|
+
subscriber.next(array[i]);
|
|
1215
|
+
}
|
|
1216
|
+
subscriber.complete();
|
|
1217
|
+
});
|
|
1218
|
+
}
|
|
1219
|
+
function fromPromise(promise) {
|
|
1220
|
+
return new Observable(function (subscriber) {
|
|
1221
|
+
promise
|
|
1222
|
+
.then(function (value) {
|
|
1223
|
+
if (!subscriber.closed) {
|
|
1224
|
+
subscriber.next(value);
|
|
1225
|
+
subscriber.complete();
|
|
1226
|
+
}
|
|
1227
|
+
}, function (err) { return subscriber.error(err); })
|
|
1228
|
+
.then(null, reportUnhandledError);
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
function fromIterable(iterable) {
|
|
1232
|
+
return new Observable(function (subscriber) {
|
|
1233
|
+
var e_1, _a;
|
|
1234
|
+
try {
|
|
1235
|
+
for (var iterable_1 = __values(iterable), iterable_1_1 = iterable_1.next(); !iterable_1_1.done; iterable_1_1 = iterable_1.next()) {
|
|
1236
|
+
var value = iterable_1_1.value;
|
|
1237
|
+
subscriber.next(value);
|
|
1238
|
+
if (subscriber.closed) {
|
|
1239
|
+
return;
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1244
|
+
finally {
|
|
1245
|
+
try {
|
|
1246
|
+
if (iterable_1_1 && !iterable_1_1.done && (_a = iterable_1.return)) _a.call(iterable_1);
|
|
1247
|
+
}
|
|
1248
|
+
finally { if (e_1) throw e_1.error; }
|
|
1249
|
+
}
|
|
1250
|
+
subscriber.complete();
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
function fromAsyncIterable(asyncIterable) {
|
|
1254
|
+
return new Observable(function (subscriber) {
|
|
1255
|
+
process(asyncIterable, subscriber).catch(function (err) { return subscriber.error(err); });
|
|
1256
|
+
});
|
|
1257
|
+
}
|
|
1258
|
+
function fromReadableStreamLike(readableStream) {
|
|
1259
|
+
return fromAsyncIterable(readableStreamLikeToAsyncGenerator(readableStream));
|
|
1260
|
+
}
|
|
1261
|
+
function process(asyncIterable, subscriber) {
|
|
1262
|
+
var asyncIterable_1, asyncIterable_1_1;
|
|
1263
|
+
var e_2, _a;
|
|
1264
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1265
|
+
var value, e_2_1;
|
|
1266
|
+
return __generator(this, function (_b) {
|
|
1267
|
+
switch (_b.label) {
|
|
1268
|
+
case 0:
|
|
1269
|
+
_b.trys.push([0, 5, 6, 11]);
|
|
1270
|
+
asyncIterable_1 = __asyncValues(asyncIterable);
|
|
1271
|
+
_b.label = 1;
|
|
1272
|
+
case 1: return [4, asyncIterable_1.next()];
|
|
1273
|
+
case 2:
|
|
1274
|
+
if (!(asyncIterable_1_1 = _b.sent(), !asyncIterable_1_1.done)) return [3, 4];
|
|
1275
|
+
value = asyncIterable_1_1.value;
|
|
1276
|
+
subscriber.next(value);
|
|
1277
|
+
if (subscriber.closed) {
|
|
1278
|
+
return [2];
|
|
1279
|
+
}
|
|
1280
|
+
_b.label = 3;
|
|
1281
|
+
case 3: return [3, 1];
|
|
1282
|
+
case 4: return [3, 11];
|
|
1283
|
+
case 5:
|
|
1284
|
+
e_2_1 = _b.sent();
|
|
1285
|
+
e_2 = { error: e_2_1 };
|
|
1286
|
+
return [3, 11];
|
|
1287
|
+
case 6:
|
|
1288
|
+
_b.trys.push([6, , 9, 10]);
|
|
1289
|
+
if (!(asyncIterable_1_1 && !asyncIterable_1_1.done && (_a = asyncIterable_1.return))) return [3, 8];
|
|
1290
|
+
return [4, _a.call(asyncIterable_1)];
|
|
1291
|
+
case 7:
|
|
1292
|
+
_b.sent();
|
|
1293
|
+
_b.label = 8;
|
|
1294
|
+
case 8: return [3, 10];
|
|
1295
|
+
case 9:
|
|
1296
|
+
if (e_2) throw e_2.error;
|
|
1297
|
+
return [7];
|
|
1298
|
+
case 10: return [7];
|
|
1299
|
+
case 11:
|
|
1300
|
+
subscriber.complete();
|
|
1301
|
+
return [2];
|
|
1302
|
+
}
|
|
1303
|
+
});
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
function executeSchedule(parentSubscription, scheduler, work, delay, repeat) {
|
|
1308
|
+
if (delay === void 0) { delay = 0; }
|
|
1309
|
+
if (repeat === void 0) { repeat = false; }
|
|
1310
|
+
var scheduleSubscription = scheduler.schedule(function () {
|
|
1311
|
+
work();
|
|
1312
|
+
if (repeat) {
|
|
1313
|
+
parentSubscription.add(this.schedule(null, delay));
|
|
1314
|
+
}
|
|
1315
|
+
else {
|
|
1316
|
+
this.unsubscribe();
|
|
1317
|
+
}
|
|
1318
|
+
}, delay);
|
|
1319
|
+
parentSubscription.add(scheduleSubscription);
|
|
1320
|
+
if (!repeat) {
|
|
1321
|
+
return scheduleSubscription;
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
function observeOn(scheduler, delay) {
|
|
1326
|
+
if (delay === void 0) { delay = 0; }
|
|
1327
|
+
return operate(function (source, subscriber) {
|
|
1328
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) { return executeSchedule(subscriber, scheduler, function () { return subscriber.next(value); }, delay); }, function () { return executeSchedule(subscriber, scheduler, function () { return subscriber.complete(); }, delay); }, function (err) { return executeSchedule(subscriber, scheduler, function () { return subscriber.error(err); }, delay); }));
|
|
1329
|
+
});
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
function subscribeOn(scheduler, delay) {
|
|
1333
|
+
if (delay === void 0) { delay = 0; }
|
|
1334
|
+
return operate(function (source, subscriber) {
|
|
1335
|
+
subscriber.add(scheduler.schedule(function () { return source.subscribe(subscriber); }, delay));
|
|
1336
|
+
});
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
function scheduleObservable(input, scheduler) {
|
|
1340
|
+
return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
function schedulePromise(input, scheduler) {
|
|
1344
|
+
return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
function scheduleArray(input, scheduler) {
|
|
1348
|
+
return new Observable(function (subscriber) {
|
|
1349
|
+
var i = 0;
|
|
1350
|
+
return scheduler.schedule(function () {
|
|
1351
|
+
if (i === input.length) {
|
|
1352
|
+
subscriber.complete();
|
|
1353
|
+
}
|
|
1354
|
+
else {
|
|
1355
|
+
subscriber.next(input[i++]);
|
|
1356
|
+
if (!subscriber.closed) {
|
|
1357
|
+
this.schedule();
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
});
|
|
1361
|
+
});
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
function scheduleIterable(input, scheduler) {
|
|
1365
|
+
return new Observable(function (subscriber) {
|
|
1366
|
+
var iterator$1;
|
|
1367
|
+
executeSchedule(subscriber, scheduler, function () {
|
|
1368
|
+
iterator$1 = input[iterator]();
|
|
1369
|
+
executeSchedule(subscriber, scheduler, function () {
|
|
1370
|
+
var _a;
|
|
1371
|
+
var value;
|
|
1372
|
+
var done;
|
|
1373
|
+
try {
|
|
1374
|
+
(_a = iterator$1.next(), value = _a.value, done = _a.done);
|
|
1375
|
+
}
|
|
1376
|
+
catch (err) {
|
|
1377
|
+
subscriber.error(err);
|
|
1378
|
+
return;
|
|
1379
|
+
}
|
|
1380
|
+
if (done) {
|
|
1381
|
+
subscriber.complete();
|
|
1382
|
+
}
|
|
1383
|
+
else {
|
|
1384
|
+
subscriber.next(value);
|
|
1385
|
+
}
|
|
1386
|
+
}, 0, true);
|
|
1387
|
+
});
|
|
1388
|
+
return function () { return isFunction(iterator$1 === null || iterator$1 === void 0 ? void 0 : iterator$1.return) && iterator$1.return(); };
|
|
1389
|
+
});
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
function scheduleAsyncIterable(input, scheduler) {
|
|
1393
|
+
if (!input) {
|
|
1394
|
+
throw new Error('Iterable cannot be null');
|
|
1395
|
+
}
|
|
1396
|
+
return new Observable(function (subscriber) {
|
|
1397
|
+
executeSchedule(subscriber, scheduler, function () {
|
|
1398
|
+
var iterator = input[Symbol.asyncIterator]();
|
|
1399
|
+
executeSchedule(subscriber, scheduler, function () {
|
|
1400
|
+
iterator.next().then(function (result) {
|
|
1401
|
+
if (result.done) {
|
|
1402
|
+
subscriber.complete();
|
|
1403
|
+
}
|
|
1404
|
+
else {
|
|
1405
|
+
subscriber.next(result.value);
|
|
1406
|
+
}
|
|
1407
|
+
});
|
|
1408
|
+
}, 0, true);
|
|
1409
|
+
});
|
|
1410
|
+
});
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
function scheduleReadableStreamLike(input, scheduler) {
|
|
1414
|
+
return scheduleAsyncIterable(readableStreamLikeToAsyncGenerator(input), scheduler);
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
function scheduled(input, scheduler) {
|
|
1418
|
+
if (input != null) {
|
|
1419
|
+
if (isInteropObservable(input)) {
|
|
1420
|
+
return scheduleObservable(input, scheduler);
|
|
1421
|
+
}
|
|
1422
|
+
if (isArrayLike(input)) {
|
|
1423
|
+
return scheduleArray(input, scheduler);
|
|
1424
|
+
}
|
|
1425
|
+
if (isPromise(input)) {
|
|
1426
|
+
return schedulePromise(input, scheduler);
|
|
1427
|
+
}
|
|
1428
|
+
if (isAsyncIterable(input)) {
|
|
1429
|
+
return scheduleAsyncIterable(input, scheduler);
|
|
1430
|
+
}
|
|
1431
|
+
if (isIterable(input)) {
|
|
1432
|
+
return scheduleIterable(input, scheduler);
|
|
1433
|
+
}
|
|
1434
|
+
if (isReadableStreamLike(input)) {
|
|
1435
|
+
return scheduleReadableStreamLike(input, scheduler);
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
throw createInvalidObservableTypeError(input);
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
function from(input, scheduler) {
|
|
1442
|
+
return scheduler ? scheduled(input, scheduler) : innerFrom(input);
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
function of() {
|
|
1446
|
+
var args = [];
|
|
1447
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1448
|
+
args[_i] = arguments[_i];
|
|
1449
|
+
}
|
|
1450
|
+
var scheduler = popScheduler(args);
|
|
1451
|
+
return from(args, scheduler);
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
function isValidDate(value) {
|
|
1455
|
+
return value instanceof Date && !isNaN(value);
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
function map(project, thisArg) {
|
|
1459
|
+
return operate(function (source, subscriber) {
|
|
1460
|
+
var index = 0;
|
|
1461
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1462
|
+
subscriber.next(project.call(thisArg, value, index++));
|
|
1463
|
+
}));
|
|
1464
|
+
});
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
function mergeInternals(source, subscriber, project, concurrent, onBeforeNext, expand, innerSubScheduler, additionalFinalizer) {
|
|
1468
|
+
var buffer = [];
|
|
1469
|
+
var active = 0;
|
|
1470
|
+
var index = 0;
|
|
1471
|
+
var isComplete = false;
|
|
1472
|
+
var checkComplete = function () {
|
|
1473
|
+
if (isComplete && !buffer.length && !active) {
|
|
1474
|
+
subscriber.complete();
|
|
1475
|
+
}
|
|
1476
|
+
};
|
|
1477
|
+
var outerNext = function (value) { return (active < concurrent ? doInnerSub(value) : buffer.push(value)); };
|
|
1478
|
+
var doInnerSub = function (value) {
|
|
1479
|
+
active++;
|
|
1480
|
+
var innerComplete = false;
|
|
1481
|
+
innerFrom(project(value, index++)).subscribe(createOperatorSubscriber(subscriber, function (innerValue) {
|
|
1482
|
+
{
|
|
1483
|
+
subscriber.next(innerValue);
|
|
1484
|
+
}
|
|
1485
|
+
}, function () {
|
|
1486
|
+
innerComplete = true;
|
|
1487
|
+
}, undefined, function () {
|
|
1488
|
+
if (innerComplete) {
|
|
1489
|
+
try {
|
|
1490
|
+
active--;
|
|
1491
|
+
var _loop_1 = function () {
|
|
1492
|
+
var bufferedValue = buffer.shift();
|
|
1493
|
+
if (innerSubScheduler) ;
|
|
1494
|
+
else {
|
|
1495
|
+
doInnerSub(bufferedValue);
|
|
1496
|
+
}
|
|
1497
|
+
};
|
|
1498
|
+
while (buffer.length && active < concurrent) {
|
|
1499
|
+
_loop_1();
|
|
1500
|
+
}
|
|
1501
|
+
checkComplete();
|
|
1502
|
+
}
|
|
1503
|
+
catch (err) {
|
|
1504
|
+
subscriber.error(err);
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
}));
|
|
1508
|
+
};
|
|
1509
|
+
source.subscribe(createOperatorSubscriber(subscriber, outerNext, function () {
|
|
1510
|
+
isComplete = true;
|
|
1511
|
+
checkComplete();
|
|
1512
|
+
}));
|
|
1513
|
+
return function () {
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
function mergeMap(project, resultSelector, concurrent) {
|
|
1518
|
+
if (concurrent === void 0) { concurrent = Infinity; }
|
|
1519
|
+
if (isFunction(resultSelector)) {
|
|
1520
|
+
return mergeMap(function (a, i) { return map(function (b, ii) { return resultSelector(a, b, i, ii); })(innerFrom(project(a, i))); }, concurrent);
|
|
1521
|
+
}
|
|
1522
|
+
else if (typeof resultSelector === 'number') {
|
|
1523
|
+
concurrent = resultSelector;
|
|
1524
|
+
}
|
|
1525
|
+
return operate(function (source, subscriber) { return mergeInternals(source, subscriber, project, concurrent); });
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
function mergeAll(concurrent) {
|
|
1529
|
+
if (concurrent === void 0) { concurrent = Infinity; }
|
|
1530
|
+
return mergeMap(identity, concurrent);
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
function concatAll() {
|
|
1534
|
+
return mergeAll(1);
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
function concat() {
|
|
1538
|
+
var args = [];
|
|
1539
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1540
|
+
args[_i] = arguments[_i];
|
|
1541
|
+
}
|
|
1542
|
+
return concatAll()(from(args, popScheduler(args)));
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
function defer(observableFactory) {
|
|
1546
|
+
return new Observable(function (subscriber) {
|
|
1547
|
+
innerFrom(observableFactory()).subscribe(subscriber);
|
|
1548
|
+
});
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
function timer(dueTime, intervalOrScheduler, scheduler) {
|
|
1552
|
+
if (dueTime === void 0) { dueTime = 0; }
|
|
1553
|
+
if (scheduler === void 0) { scheduler = async; }
|
|
1554
|
+
var intervalDuration = -1;
|
|
1555
|
+
if (intervalOrScheduler != null) {
|
|
1556
|
+
if (isScheduler(intervalOrScheduler)) {
|
|
1557
|
+
scheduler = intervalOrScheduler;
|
|
1558
|
+
}
|
|
1559
|
+
else {
|
|
1560
|
+
intervalDuration = intervalOrScheduler;
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
return new Observable(function (subscriber) {
|
|
1564
|
+
var due = isValidDate(dueTime) ? +dueTime - scheduler.now() : dueTime;
|
|
1565
|
+
if (due < 0) {
|
|
1566
|
+
due = 0;
|
|
1567
|
+
}
|
|
1568
|
+
var n = 0;
|
|
1569
|
+
return scheduler.schedule(function () {
|
|
1570
|
+
if (!subscriber.closed) {
|
|
1571
|
+
subscriber.next(n++);
|
|
1572
|
+
if (0 <= intervalDuration) {
|
|
1573
|
+
this.schedule(undefined, intervalDuration);
|
|
1574
|
+
}
|
|
1575
|
+
else {
|
|
1576
|
+
subscriber.complete();
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
}, due);
|
|
1580
|
+
});
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
function merge() {
|
|
1584
|
+
var args = [];
|
|
1585
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1586
|
+
args[_i] = arguments[_i];
|
|
1587
|
+
}
|
|
1588
|
+
var scheduler = popScheduler(args);
|
|
1589
|
+
var concurrent = popNumber(args, Infinity);
|
|
1590
|
+
var sources = args;
|
|
1591
|
+
return !sources.length
|
|
1592
|
+
?
|
|
1593
|
+
EMPTY
|
|
1594
|
+
: sources.length === 1
|
|
1595
|
+
?
|
|
1596
|
+
innerFrom(sources[0])
|
|
1597
|
+
:
|
|
1598
|
+
mergeAll(concurrent)(from(sources, scheduler));
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
function filter(predicate, thisArg) {
|
|
1602
|
+
return operate(function (source, subscriber) {
|
|
1603
|
+
var index = 0;
|
|
1604
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) { return predicate.call(thisArg, value, index++) && subscriber.next(value); }));
|
|
1605
|
+
});
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
function catchError(selector) {
|
|
1609
|
+
return operate(function (source, subscriber) {
|
|
1610
|
+
var innerSub = null;
|
|
1611
|
+
var syncUnsub = false;
|
|
1612
|
+
var handledResult;
|
|
1613
|
+
innerSub = source.subscribe(createOperatorSubscriber(subscriber, undefined, undefined, function (err) {
|
|
1614
|
+
handledResult = innerFrom(selector(err, catchError(selector)(source)));
|
|
1615
|
+
if (innerSub) {
|
|
1616
|
+
innerSub.unsubscribe();
|
|
1617
|
+
innerSub = null;
|
|
1618
|
+
handledResult.subscribe(subscriber);
|
|
1619
|
+
}
|
|
1620
|
+
else {
|
|
1621
|
+
syncUnsub = true;
|
|
1622
|
+
}
|
|
1623
|
+
}));
|
|
1624
|
+
if (syncUnsub) {
|
|
1625
|
+
innerSub.unsubscribe();
|
|
1626
|
+
innerSub = null;
|
|
1627
|
+
handledResult.subscribe(subscriber);
|
|
1628
|
+
}
|
|
1629
|
+
});
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
function scanInternals(accumulator, seed, hasSeed, emitOnNext, emitBeforeComplete) {
|
|
1633
|
+
return function (source, subscriber) {
|
|
1634
|
+
var hasState = hasSeed;
|
|
1635
|
+
var state = seed;
|
|
1636
|
+
var index = 0;
|
|
1637
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1638
|
+
var i = index++;
|
|
1639
|
+
state = hasState
|
|
1640
|
+
?
|
|
1641
|
+
accumulator(state, value, i)
|
|
1642
|
+
:
|
|
1643
|
+
((hasState = true), value);
|
|
1644
|
+
subscriber.next(state);
|
|
1645
|
+
}, emitBeforeComplete));
|
|
1646
|
+
};
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
function concatMap(project, resultSelector) {
|
|
1650
|
+
return isFunction(resultSelector) ? mergeMap(project, resultSelector, 1) : mergeMap(project, 1);
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
function take(count) {
|
|
1654
|
+
return count <= 0
|
|
1655
|
+
?
|
|
1656
|
+
function () { return EMPTY; }
|
|
1657
|
+
: operate(function (source, subscriber) {
|
|
1658
|
+
var seen = 0;
|
|
1659
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1660
|
+
if (++seen <= count) {
|
|
1661
|
+
subscriber.next(value);
|
|
1662
|
+
if (count <= seen) {
|
|
1663
|
+
subscriber.complete();
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
}));
|
|
1667
|
+
});
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
function mapTo(value) {
|
|
1671
|
+
return map(function () { return value; });
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
function delayWhen(delayDurationSelector, subscriptionDelay) {
|
|
1675
|
+
return mergeMap(function (value, index) { return innerFrom(delayDurationSelector(value, index)).pipe(take(1), mapTo(value)); });
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
function delay(due, scheduler) {
|
|
1679
|
+
if (scheduler === void 0) { scheduler = asyncScheduler; }
|
|
1680
|
+
var duration = timer(due, scheduler);
|
|
1681
|
+
return delayWhen(function () { return duration; });
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
function distinctUntilChanged(comparator, keySelector) {
|
|
1685
|
+
if (keySelector === void 0) { keySelector = identity; }
|
|
1686
|
+
comparator = comparator !== null && comparator !== void 0 ? comparator : defaultCompare;
|
|
1687
|
+
return operate(function (source, subscriber) {
|
|
1688
|
+
var previousKey;
|
|
1689
|
+
var first = true;
|
|
1690
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1691
|
+
var currentKey = keySelector(value);
|
|
1692
|
+
if (first || !comparator(previousKey, currentKey)) {
|
|
1693
|
+
first = false;
|
|
1694
|
+
previousKey = currentKey;
|
|
1695
|
+
subscriber.next(value);
|
|
1696
|
+
}
|
|
1697
|
+
}));
|
|
1698
|
+
});
|
|
1699
|
+
}
|
|
1700
|
+
function defaultCompare(a, b) {
|
|
1701
|
+
return a === b;
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
function exhaustMap(project, resultSelector) {
|
|
1705
|
+
if (resultSelector) {
|
|
1706
|
+
return function (source) {
|
|
1707
|
+
return source.pipe(exhaustMap(function (a, i) { return innerFrom(project(a, i)).pipe(map(function (b, ii) { return resultSelector(a, b, i, ii); })); }));
|
|
1708
|
+
};
|
|
1709
|
+
}
|
|
1710
|
+
return operate(function (source, subscriber) {
|
|
1711
|
+
var index = 0;
|
|
1712
|
+
var innerSub = null;
|
|
1713
|
+
var isComplete = false;
|
|
1714
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (outerValue) {
|
|
1715
|
+
if (!innerSub) {
|
|
1716
|
+
innerSub = createOperatorSubscriber(subscriber, undefined, function () {
|
|
1717
|
+
innerSub = null;
|
|
1718
|
+
isComplete && subscriber.complete();
|
|
1719
|
+
});
|
|
1720
|
+
innerFrom(project(outerValue, index++)).subscribe(innerSub);
|
|
1721
|
+
}
|
|
1722
|
+
}, function () {
|
|
1723
|
+
isComplete = true;
|
|
1724
|
+
!innerSub && subscriber.complete();
|
|
1725
|
+
}));
|
|
1726
|
+
});
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
function scan(accumulator, seed) {
|
|
1730
|
+
return operate(scanInternals(accumulator, seed, arguments.length >= 2, true));
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
function share(options) {
|
|
1734
|
+
if (options === void 0) { options = {}; }
|
|
1735
|
+
var _a = options.connector, connector = _a === void 0 ? function () { return new Subject(); } : _a, _b = options.resetOnError, resetOnError = _b === void 0 ? true : _b, _c = options.resetOnComplete, resetOnComplete = _c === void 0 ? true : _c, _d = options.resetOnRefCountZero, resetOnRefCountZero = _d === void 0 ? true : _d;
|
|
1736
|
+
return function (wrapperSource) {
|
|
1737
|
+
var connection;
|
|
1738
|
+
var resetConnection;
|
|
1739
|
+
var subject;
|
|
1740
|
+
var refCount = 0;
|
|
1741
|
+
var hasCompleted = false;
|
|
1742
|
+
var hasErrored = false;
|
|
1743
|
+
var cancelReset = function () {
|
|
1744
|
+
resetConnection === null || resetConnection === void 0 ? void 0 : resetConnection.unsubscribe();
|
|
1745
|
+
resetConnection = undefined;
|
|
1746
|
+
};
|
|
1747
|
+
var reset = function () {
|
|
1748
|
+
cancelReset();
|
|
1749
|
+
connection = subject = undefined;
|
|
1750
|
+
hasCompleted = hasErrored = false;
|
|
1751
|
+
};
|
|
1752
|
+
var resetAndUnsubscribe = function () {
|
|
1753
|
+
var conn = connection;
|
|
1754
|
+
reset();
|
|
1755
|
+
conn === null || conn === void 0 ? void 0 : conn.unsubscribe();
|
|
1756
|
+
};
|
|
1757
|
+
return operate(function (source, subscriber) {
|
|
1758
|
+
refCount++;
|
|
1759
|
+
if (!hasErrored && !hasCompleted) {
|
|
1760
|
+
cancelReset();
|
|
1761
|
+
}
|
|
1762
|
+
var dest = (subject = subject !== null && subject !== void 0 ? subject : connector());
|
|
1763
|
+
subscriber.add(function () {
|
|
1764
|
+
refCount--;
|
|
1765
|
+
if (refCount === 0 && !hasErrored && !hasCompleted) {
|
|
1766
|
+
resetConnection = handleReset(resetAndUnsubscribe, resetOnRefCountZero);
|
|
1767
|
+
}
|
|
1768
|
+
});
|
|
1769
|
+
dest.subscribe(subscriber);
|
|
1770
|
+
if (!connection &&
|
|
1771
|
+
refCount > 0) {
|
|
1772
|
+
connection = new SafeSubscriber({
|
|
1773
|
+
next: function (value) { return dest.next(value); },
|
|
1774
|
+
error: function (err) {
|
|
1775
|
+
hasErrored = true;
|
|
1776
|
+
cancelReset();
|
|
1777
|
+
resetConnection = handleReset(reset, resetOnError, err);
|
|
1778
|
+
dest.error(err);
|
|
1779
|
+
},
|
|
1780
|
+
complete: function () {
|
|
1781
|
+
hasCompleted = true;
|
|
1782
|
+
cancelReset();
|
|
1783
|
+
resetConnection = handleReset(reset, resetOnComplete);
|
|
1784
|
+
dest.complete();
|
|
1785
|
+
},
|
|
1786
|
+
});
|
|
1787
|
+
innerFrom(source).subscribe(connection);
|
|
1788
|
+
}
|
|
1789
|
+
})(wrapperSource);
|
|
1790
|
+
};
|
|
1791
|
+
}
|
|
1792
|
+
function handleReset(reset, on) {
|
|
1793
|
+
var args = [];
|
|
1794
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
1795
|
+
args[_i - 2] = arguments[_i];
|
|
1796
|
+
}
|
|
1797
|
+
if (on === true) {
|
|
1798
|
+
reset();
|
|
1799
|
+
return;
|
|
1800
|
+
}
|
|
1801
|
+
if (on === false) {
|
|
1802
|
+
return;
|
|
1803
|
+
}
|
|
1804
|
+
var onSubscriber = new SafeSubscriber({
|
|
1805
|
+
next: function () {
|
|
1806
|
+
onSubscriber.unsubscribe();
|
|
1807
|
+
reset();
|
|
1808
|
+
},
|
|
1809
|
+
});
|
|
1810
|
+
return innerFrom(on.apply(void 0, __spreadArray([], __read(args)))).subscribe(onSubscriber);
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
function shareReplay(configOrBufferSize, windowTime, scheduler) {
|
|
1814
|
+
var bufferSize;
|
|
1815
|
+
var refCount = false;
|
|
1816
|
+
{
|
|
1817
|
+
bufferSize = (configOrBufferSize );
|
|
1818
|
+
}
|
|
1819
|
+
return share({
|
|
1820
|
+
connector: function () { return new ReplaySubject(bufferSize, windowTime, scheduler); },
|
|
1821
|
+
resetOnError: true,
|
|
1822
|
+
resetOnComplete: false,
|
|
1823
|
+
resetOnRefCountZero: refCount,
|
|
1824
|
+
});
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
function startWith() {
|
|
1828
|
+
var values = [];
|
|
1829
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1830
|
+
values[_i] = arguments[_i];
|
|
1831
|
+
}
|
|
1832
|
+
var scheduler = popScheduler(values);
|
|
1833
|
+
return operate(function (source, subscriber) {
|
|
1834
|
+
(scheduler ? concat(values, source, scheduler) : concat(values, source)).subscribe(subscriber);
|
|
1835
|
+
});
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1838
|
+
function switchMap(project, resultSelector) {
|
|
1839
|
+
return operate(function (source, subscriber) {
|
|
1840
|
+
var innerSubscriber = null;
|
|
1841
|
+
var index = 0;
|
|
1842
|
+
var isComplete = false;
|
|
1843
|
+
var checkComplete = function () { return isComplete && !innerSubscriber && subscriber.complete(); };
|
|
1844
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1845
|
+
innerSubscriber === null || innerSubscriber === void 0 ? void 0 : innerSubscriber.unsubscribe();
|
|
1846
|
+
var innerIndex = 0;
|
|
1847
|
+
var outerIndex = index++;
|
|
1848
|
+
innerFrom(project(value, outerIndex)).subscribe((innerSubscriber = createOperatorSubscriber(subscriber, function (innerValue) { return subscriber.next(resultSelector ? resultSelector(value, innerValue, outerIndex, innerIndex++) : innerValue); }, function () {
|
|
1849
|
+
innerSubscriber = null;
|
|
1850
|
+
checkComplete();
|
|
1851
|
+
})));
|
|
1852
|
+
}, function () {
|
|
1853
|
+
isComplete = true;
|
|
1854
|
+
checkComplete();
|
|
1855
|
+
}));
|
|
1856
|
+
});
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
function tap(observerOrNext, error, complete) {
|
|
1860
|
+
var tapObserver = isFunction(observerOrNext) || error || complete
|
|
1861
|
+
?
|
|
1862
|
+
{ next: observerOrNext, error: error, complete: complete }
|
|
1863
|
+
: observerOrNext;
|
|
1864
|
+
return tapObserver
|
|
1865
|
+
? operate(function (source, subscriber) {
|
|
1866
|
+
var _a;
|
|
1867
|
+
(_a = tapObserver.subscribe) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
|
|
1868
|
+
var isUnsub = true;
|
|
1869
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1870
|
+
var _a;
|
|
1871
|
+
(_a = tapObserver.next) === null || _a === void 0 ? void 0 : _a.call(tapObserver, value);
|
|
1872
|
+
subscriber.next(value);
|
|
1873
|
+
}, function () {
|
|
1874
|
+
var _a;
|
|
1875
|
+
isUnsub = false;
|
|
1876
|
+
(_a = tapObserver.complete) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
|
|
1877
|
+
subscriber.complete();
|
|
1878
|
+
}, function (err) {
|
|
1879
|
+
var _a;
|
|
1880
|
+
isUnsub = false;
|
|
1881
|
+
(_a = tapObserver.error) === null || _a === void 0 ? void 0 : _a.call(tapObserver, err);
|
|
1882
|
+
subscriber.error(err);
|
|
1883
|
+
}, function () {
|
|
1884
|
+
var _a, _b;
|
|
1885
|
+
if (isUnsub) {
|
|
1886
|
+
(_a = tapObserver.unsubscribe) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
|
|
1887
|
+
}
|
|
1888
|
+
(_b = tapObserver.finalize) === null || _b === void 0 ? void 0 : _b.call(tapObserver);
|
|
1889
|
+
}));
|
|
1890
|
+
})
|
|
1891
|
+
:
|
|
1892
|
+
identity;
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1895
|
+
/**
|
|
1896
|
+
* @typedef {import('./actions').Action} Action
|
|
1897
|
+
*/
|
|
1898
|
+
|
|
1899
|
+
class Store {
|
|
1900
|
+
/**
|
|
1901
|
+
* @private
|
|
1902
|
+
* @type {BehaviorSubject<object>}
|
|
1903
|
+
*/
|
|
1904
|
+
_state$;
|
|
1905
|
+
|
|
1906
|
+
/**
|
|
1907
|
+
* @private
|
|
1908
|
+
* @type {Subject<Action>}
|
|
1909
|
+
*/
|
|
1910
|
+
_actions$ = new Subject();
|
|
1911
|
+
|
|
1912
|
+
/**
|
|
1913
|
+
* @private
|
|
1914
|
+
* @type {Array<{path: string, initialState: any, reducerFn: function(any, Action): any}>}
|
|
1915
|
+
*/
|
|
1916
|
+
_reducers = [];
|
|
1917
|
+
|
|
1918
|
+
/**
|
|
1919
|
+
* @param {object} initialState - The initial state of the application.
|
|
1920
|
+
*/
|
|
1921
|
+
constructor(initialState = {}) {
|
|
1922
|
+
// The initial state is now deep-cloned to prevent external mutations.
|
|
1923
|
+
// `structuredClone` is modern and ideal, but `JSON.parse` is a safe fallback.
|
|
1924
|
+
const initialStoreState = typeof structuredClone === 'function' ? structuredClone(initialState) : JSON.parse(JSON.stringify(initialState));
|
|
1925
|
+
this._state$ = new BehaviorSubject(initialStoreState);
|
|
1926
|
+
|
|
1927
|
+
const dispatcher$ = this._actions$.pipe(
|
|
1928
|
+
// Optional: log for debugging
|
|
1929
|
+
tap((action) => console.log('Action Dispatched:', action))
|
|
1930
|
+
);
|
|
1931
|
+
|
|
1932
|
+
const state$ = dispatcher$.pipe(
|
|
1933
|
+
scan((currentState, action) => {
|
|
1934
|
+
// Clones the state to ensure immutability.
|
|
1935
|
+
// For larger apps, a library like `lodash.cloneDeep` would be more robust.
|
|
1936
|
+
const nextState = JSON.parse(JSON.stringify(currentState));
|
|
1937
|
+
|
|
1938
|
+
this._reducers.forEach(({ path: featureKey, reducerFn }) => {
|
|
1939
|
+
// Gets the current state slice.
|
|
1940
|
+
const stateSlice = nextState[featureKey];
|
|
1941
|
+
|
|
1942
|
+
// Executes the reducer to get the new slice.
|
|
1943
|
+
const nextStateSlice = reducerFn(stateSlice, action);
|
|
1944
|
+
|
|
1945
|
+
// If the reducer returned a new value (not undefined) and it's different from the previous one,
|
|
1946
|
+
// apply the change to the state object.
|
|
1947
|
+
if (nextStateSlice !== undefined && stateSlice !== nextStateSlice) {
|
|
1948
|
+
// Directly assign the new slice to the corresponding key in the state.
|
|
1949
|
+
nextState[featureKey] = nextStateSlice;
|
|
1950
|
+
}
|
|
1951
|
+
});
|
|
1952
|
+
|
|
1953
|
+
return nextState;
|
|
1954
|
+
}, initialStoreState),
|
|
1955
|
+
startWith(initialState),
|
|
1956
|
+
// Ensures new subscribers receive the last emitted state and shares the execution.
|
|
1957
|
+
shareReplay(1)
|
|
1958
|
+
);
|
|
1959
|
+
|
|
1960
|
+
// Connects the calculated state stream back to our main BehaviorSubject.
|
|
1961
|
+
state$.subscribe(this._state$);
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1964
|
+
/**
|
|
1965
|
+
* Registers reducers in the store.
|
|
1966
|
+
* @param {...{path: string, initialState: any, reducerFn: function(any, Action): any}} reducers
|
|
1967
|
+
*/
|
|
1968
|
+
registerReducers(...reducers) {
|
|
1969
|
+
this._reducers.push(...reducers);
|
|
1970
|
+
|
|
1971
|
+
// Builds the initial state from the registered reducers
|
|
1972
|
+
const currentState = this._state$.getValue();
|
|
1973
|
+
const nextState = JSON.parse(JSON.stringify(currentState));
|
|
1974
|
+
|
|
1975
|
+
reducers.forEach(({ path: featureKey, initialState }) => {
|
|
1976
|
+
// If the state slice has not been defined yet, apply the reducer's initial state.
|
|
1977
|
+
if (nextState[featureKey] === undefined) {
|
|
1978
|
+
nextState[featureKey] = initialState;
|
|
1979
|
+
}
|
|
1980
|
+
});
|
|
1981
|
+
|
|
1982
|
+
// Emits the new constructed state
|
|
1983
|
+
this._state$.next(nextState);
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
/**
|
|
1987
|
+
* Registers effects in the store.
|
|
1988
|
+
* @param {...function(import('rxjs').Observable<Action>): import('rxjs').Observable<Action>} effects
|
|
1989
|
+
*/
|
|
1990
|
+
registerEffects(...effects) {
|
|
1991
|
+
const effectStreams = effects.map((effect) => effect(this._actions$));
|
|
1992
|
+
// Merges all action streams returned by the effects and dispatches them back into the store.
|
|
1993
|
+
merge(...effectStreams).subscribe((action) => this.dispatch(action));
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1996
|
+
/**
|
|
1997
|
+
* Dispatches an action to the store, initiating the state update cycle.
|
|
1998
|
+
* @param {Action} action
|
|
1999
|
+
*/
|
|
2000
|
+
dispatch(action) {
|
|
2001
|
+
this._actions$.next(action);
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
/**
|
|
2005
|
+
* Selects a slice of the state and returns it as an Observable.
|
|
2006
|
+
* @param {function(object): any} selectorFn - The selector function.
|
|
2007
|
+
* @returns {import('rxjs').Observable<any>}
|
|
2008
|
+
*/
|
|
2009
|
+
select(selectorFn) {
|
|
2010
|
+
return this._state$.pipe(
|
|
2011
|
+
map(state => selectorFn(state)),
|
|
2012
|
+
// Emits only when the selected value has actually changed.
|
|
2013
|
+
distinctUntilChanged()
|
|
2014
|
+
);
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
/**
|
|
2019
|
+
* @typedef {Object} Action
|
|
2020
|
+
* @property {string} type - The action type, a unique string describing it.
|
|
2021
|
+
* @property {any} [payload] - The data associated with the action.
|
|
2022
|
+
*/
|
|
2023
|
+
|
|
2024
|
+
/**
|
|
2025
|
+
* Factory function to create an action.
|
|
2026
|
+
* @param {string} type - The action type.
|
|
2027
|
+
* @returns {function(any=): Action} A function that creates the action with an optional payload.
|
|
2028
|
+
*/
|
|
2029
|
+
function createAction(type) {
|
|
2030
|
+
const actionCreator = (payload) => ({ type, payload });
|
|
2031
|
+
actionCreator.type = type; // Attaches the type directly to the function for easy access
|
|
2032
|
+
return actionCreator;
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
/**
|
|
2036
|
+
* @typedef {import('./actions').Action} Action
|
|
2037
|
+
*/
|
|
2038
|
+
|
|
2039
|
+
/**
|
|
2040
|
+
* A token to be used with `on` to catch any action.
|
|
2041
|
+
*/
|
|
2042
|
+
function anyAction() {}
|
|
2043
|
+
|
|
2044
|
+
/**
|
|
2045
|
+
* Associates one or more action creators with a reducer function.
|
|
2046
|
+
* @param {...(function|function(any, Action): any)} args - A list of action creators, followed by the reducer function.
|
|
2047
|
+
* @returns {{ types: string[], reducerFn: function(any, Action): any }}
|
|
2048
|
+
*/
|
|
2049
|
+
function on(...args) {
|
|
2050
|
+
// The last argument is the reducer function.
|
|
2051
|
+
const reducerFn = args.pop();
|
|
2052
|
+
// All previous arguments are the action creators.
|
|
2053
|
+
const actionCreators = args;
|
|
2054
|
+
|
|
2055
|
+
// Checks if the `anyAction` token was used.
|
|
2056
|
+
const isCatchAll = actionCreators.includes(anyAction);
|
|
2057
|
+
if (isCatchAll && actionCreators.length > 1) {
|
|
2058
|
+
throw new Error('The `anyAction` token cannot be mixed with other action creators in a single `on` handler.');
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2061
|
+
const types = actionCreators.map(creator => creator.type);
|
|
2062
|
+
return { types, reducerFn, isCatchAll };
|
|
2063
|
+
}
|
|
2064
|
+
|
|
2065
|
+
/**
|
|
2066
|
+
* Factory function to create a reducer.
|
|
2067
|
+
* A reducer is associated with a key that defines which top-level property of the state it manages.
|
|
2068
|
+
*
|
|
2069
|
+
* @param {string} featureKey - The key for the state slice this reducer manages.
|
|
2070
|
+
* @param {any} initialState - The initial state for this state slice.
|
|
2071
|
+
* @param {...{ types: string[], reducerFn: function(any, Action): any }} ons - A list of handlers created with the `on` function.
|
|
2072
|
+
* @returns {{path: string, initialState: any, reducerFn: function(any, Action): any}} The reducer object.
|
|
2073
|
+
*/
|
|
2074
|
+
function createReducer(featureKey, initialState, ...ons) {
|
|
2075
|
+
if (!featureKey || typeof featureKey !== 'string') {
|
|
2076
|
+
throw new Error('Reducer featureKey must be a non-empty string.');
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2079
|
+
// Separates specific handlers from generic (catch-all) ones.
|
|
2080
|
+
const specificHandlers = ons.filter(o => !o.isCatchAll);
|
|
2081
|
+
const catchAllHandler = ons.find(o => o.isCatchAll);
|
|
2082
|
+
|
|
2083
|
+
const reducerFn = (state = initialState, action) => {
|
|
2084
|
+
// First, try to find a specific 'on' handler for the action.
|
|
2085
|
+
for (const handler of specificHandlers) {
|
|
2086
|
+
if (handler.types.includes(action.type)) {
|
|
2087
|
+
return handler.reducerFn(state, action);
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2090
|
+
|
|
2091
|
+
// If no specific handler matches, execute the 'any' handler, if it exists.
|
|
2092
|
+
if (catchAllHandler) {
|
|
2093
|
+
return catchAllHandler.reducerFn(state, action);
|
|
2094
|
+
}
|
|
2095
|
+
|
|
2096
|
+
// If nothing matches, return the state unchanged.
|
|
2097
|
+
return state;
|
|
2098
|
+
};
|
|
2099
|
+
|
|
2100
|
+
return { path: featureKey, initialState, reducerFn };
|
|
2101
|
+
}
|
|
2102
|
+
|
|
2103
|
+
/**
|
|
2104
|
+
* @typedef {import('./actions').Action} Action
|
|
2105
|
+
* @typedef {import('rxjs').Observable<Action>} ActionStream
|
|
2106
|
+
*/
|
|
2107
|
+
|
|
2108
|
+
/**
|
|
2109
|
+
* Custom RxJS operator to filter actions by type.
|
|
2110
|
+
* @param {...(function(any=): Action)} actionCreators - The action creators whose types will be used for filtering.
|
|
2111
|
+
* @returns {import('rxjs').OperatorFunction<Action, Action>}
|
|
2112
|
+
*/
|
|
2113
|
+
function ofType(...actionCreators) {
|
|
2114
|
+
// Extracts the 'type' string from each action creator passed as an argument.
|
|
2115
|
+
const allowedTypes = actionCreators.map(creator => creator.type);
|
|
2116
|
+
|
|
2117
|
+
return filter(action => allowedTypes.includes(action.type));
|
|
2118
|
+
}
|
|
2119
|
+
|
|
2120
|
+
/**
|
|
2121
|
+
* Factory function to create an effect.
|
|
2122
|
+
* An effect is a function that receives the stream of all actions
|
|
2123
|
+
* and returns a new stream of actions to be dispatched.
|
|
2124
|
+
*
|
|
2125
|
+
* @param {function(ActionStream): ActionStream} effectFn
|
|
2126
|
+
* @returns {function(ActionStream): ActionStream} The effect function.
|
|
2127
|
+
*/
|
|
2128
|
+
function createEffect(effectFn) {
|
|
2129
|
+
if (typeof effectFn !== 'function') {
|
|
2130
|
+
throw new Error('Effect must be a function.');
|
|
2131
|
+
}
|
|
2132
|
+
return effectFn;
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2135
|
+
/**
|
|
2136
|
+
* Creates a selector function that extracts a top-level state slice (feature) using a key.
|
|
2137
|
+
* It is analogous to NgRx's `createFeatureSelector`.
|
|
2138
|
+
*
|
|
2139
|
+
* @param {string} featureKey - The key for the top-level feature in the state object.
|
|
2140
|
+
* @param {function(any): any} [projectionFn] - An optional function to transform the selected value.
|
|
2141
|
+
* @returns {function(object): any} A function that receives the complete state and returns the selected part.
|
|
2142
|
+
*/
|
|
2143
|
+
function createFeatureSelector(featureKey, projectionFn) {
|
|
2144
|
+
return (state) => {
|
|
2145
|
+
const selectedValue = state[featureKey];
|
|
2146
|
+
// If a projection function was provided, apply it to the value. Otherwise, return the value directly.
|
|
2147
|
+
return projectionFn ? projectionFn(selectedValue) : selectedValue;
|
|
2148
|
+
};
|
|
2149
|
+
}
|
|
2150
|
+
|
|
2151
|
+
/**
|
|
2152
|
+
* Creates a selector function that can compose multiple selectors, whose results
|
|
2153
|
+
* are passed as arguments to a final projection function.
|
|
2154
|
+
* It is analogous to NgRx's `createSelector`.
|
|
2155
|
+
*
|
|
2156
|
+
* @param {...Function} args - A list of input selector functions, followed by a projection function.
|
|
2157
|
+
* @returns {function(object): any} The final composed selector function.
|
|
2158
|
+
*/
|
|
2159
|
+
function createSelector(...args) {
|
|
2160
|
+
// The last argument is always the projection function.
|
|
2161
|
+
const projectionFn = args.pop();
|
|
2162
|
+
// All previous arguments are the input selectors.
|
|
2163
|
+
const inputSelectors = args;
|
|
2164
|
+
|
|
2165
|
+
if (typeof projectionFn !== 'function') {
|
|
2166
|
+
throw new Error('The last argument to createSelector must be a projection function.');
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
return (state) => {
|
|
2170
|
+
const inputs = inputSelectors.map(selector => selector(state));
|
|
2171
|
+
return projectionFn(...inputs);
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
|
|
2175
|
+
export { Store, anyAction, catchError, concatMap, createAction, createEffect, createFeatureSelector, createReducer, createSelector, defer, delay, exhaustMap, filter, from, map, mergeMap, of, ofType, on, switchMap, tap };
|