1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
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;
|
44 | return g = { next: verb(0), "throw": verb(1), "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 (_) 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) {
|
100 | for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
101 | to[j] = from[i];
|
102 | return to;
|
103 | }
|
104 |
|
105 | function __await(v) {
|
106 | return this instanceof __await ? (this.v = v, this) : new __await(v);
|
107 | }
|
108 |
|
109 | function __asyncGenerator(thisArg, _arguments, generator) {
|
110 | if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
111 | var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
112 | return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
113 | function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
114 | function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
115 | function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
116 | function fulfill(value) { resume("next", value); }
|
117 | function reject(value) { resume("throw", value); }
|
118 | function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
119 | }
|
120 |
|
121 | function __asyncValues(o) {
|
122 | if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
123 | var m = o[Symbol.asyncIterator], i;
|
124 | 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);
|
125 | 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); }); }; }
|
126 | function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
127 | }
|
128 |
|
129 | function isFunction(value) {
|
130 | return typeof value === 'function';
|
131 | }
|
132 |
|
133 | function createErrorClass(createImpl) {
|
134 | var _super = function (instance) {
|
135 | Error.call(instance);
|
136 | instance.stack = new Error().stack;
|
137 | };
|
138 | var ctorFunc = createImpl(_super);
|
139 | ctorFunc.prototype = Object.create(Error.prototype);
|
140 | ctorFunc.prototype.constructor = ctorFunc;
|
141 | return ctorFunc;
|
142 | }
|
143 |
|
144 | var UnsubscriptionError = createErrorClass(function (_super) {
|
145 | return function UnsubscriptionErrorImpl(errors) {
|
146 | _super(this);
|
147 | this.message = errors
|
148 | ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n ')
|
149 | : '';
|
150 | this.name = 'UnsubscriptionError';
|
151 | this.errors = errors;
|
152 | };
|
153 | });
|
154 |
|
155 | function arrRemove(arr, item) {
|
156 | if (arr) {
|
157 | var index = arr.indexOf(item);
|
158 | 0 <= index && arr.splice(index, 1);
|
159 | }
|
160 | }
|
161 |
|
162 | var Subscription = (function () {
|
163 | function Subscription(initialTeardown) {
|
164 | this.initialTeardown = initialTeardown;
|
165 | this.closed = false;
|
166 | this._parentage = null;
|
167 | this._teardowns = null;
|
168 | }
|
169 | Subscription.prototype.unsubscribe = function () {
|
170 | var e_1, _a, e_2, _b;
|
171 | var errors;
|
172 | if (!this.closed) {
|
173 | this.closed = true;
|
174 | var _parentage = this._parentage;
|
175 | if (_parentage) {
|
176 | this._parentage = null;
|
177 | if (Array.isArray(_parentage)) {
|
178 | try {
|
179 | for (var _parentage_1 = __values(_parentage), _parentage_1_1 = _parentage_1.next(); !_parentage_1_1.done; _parentage_1_1 = _parentage_1.next()) {
|
180 | var parent_1 = _parentage_1_1.value;
|
181 | parent_1.remove(this);
|
182 | }
|
183 | }
|
184 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
185 | finally {
|
186 | try {
|
187 | if (_parentage_1_1 && !_parentage_1_1.done && (_a = _parentage_1.return)) _a.call(_parentage_1);
|
188 | }
|
189 | finally { if (e_1) throw e_1.error; }
|
190 | }
|
191 | }
|
192 | else {
|
193 | _parentage.remove(this);
|
194 | }
|
195 | }
|
196 | var initialTeardown = this.initialTeardown;
|
197 | if (isFunction(initialTeardown)) {
|
198 | try {
|
199 | initialTeardown();
|
200 | }
|
201 | catch (e) {
|
202 | errors = e instanceof UnsubscriptionError ? e.errors : [e];
|
203 | }
|
204 | }
|
205 | var _teardowns = this._teardowns;
|
206 | if (_teardowns) {
|
207 | this._teardowns = null;
|
208 | try {
|
209 | for (var _teardowns_1 = __values(_teardowns), _teardowns_1_1 = _teardowns_1.next(); !_teardowns_1_1.done; _teardowns_1_1 = _teardowns_1.next()) {
|
210 | var teardown_1 = _teardowns_1_1.value;
|
211 | try {
|
212 | execTeardown(teardown_1);
|
213 | }
|
214 | catch (err) {
|
215 | errors = errors !== null && errors !== void 0 ? errors : [];
|
216 | if (err instanceof UnsubscriptionError) {
|
217 | errors = __spreadArray(__spreadArray([], __read(errors)), __read(err.errors));
|
218 | }
|
219 | else {
|
220 | errors.push(err);
|
221 | }
|
222 | }
|
223 | }
|
224 | }
|
225 | catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
226 | finally {
|
227 | try {
|
228 | if (_teardowns_1_1 && !_teardowns_1_1.done && (_b = _teardowns_1.return)) _b.call(_teardowns_1);
|
229 | }
|
230 | finally { if (e_2) throw e_2.error; }
|
231 | }
|
232 | }
|
233 | if (errors) {
|
234 | throw new UnsubscriptionError(errors);
|
235 | }
|
236 | }
|
237 | };
|
238 | Subscription.prototype.add = function (teardown) {
|
239 | var _a;
|
240 | if (teardown && teardown !== this) {
|
241 | if (this.closed) {
|
242 | execTeardown(teardown);
|
243 | }
|
244 | else {
|
245 | if (teardown instanceof Subscription) {
|
246 | if (teardown.closed || teardown._hasParent(this)) {
|
247 | return;
|
248 | }
|
249 | teardown._addParent(this);
|
250 | }
|
251 | (this._teardowns = (_a = this._teardowns) !== null && _a !== void 0 ? _a : []).push(teardown);
|
252 | }
|
253 | }
|
254 | };
|
255 | Subscription.prototype._hasParent = function (parent) {
|
256 | var _parentage = this._parentage;
|
257 | return _parentage === parent || (Array.isArray(_parentage) && _parentage.includes(parent));
|
258 | };
|
259 | Subscription.prototype._addParent = function (parent) {
|
260 | var _parentage = this._parentage;
|
261 | this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
|
262 | };
|
263 | Subscription.prototype._removeParent = function (parent) {
|
264 | var _parentage = this._parentage;
|
265 | if (_parentage === parent) {
|
266 | this._parentage = null;
|
267 | }
|
268 | else if (Array.isArray(_parentage)) {
|
269 | arrRemove(_parentage, parent);
|
270 | }
|
271 | };
|
272 | Subscription.prototype.remove = function (teardown) {
|
273 | var _teardowns = this._teardowns;
|
274 | _teardowns && arrRemove(_teardowns, teardown);
|
275 | if (teardown instanceof Subscription) {
|
276 | teardown._removeParent(this);
|
277 | }
|
278 | };
|
279 | Subscription.EMPTY = (function () {
|
280 | var empty = new Subscription();
|
281 | empty.closed = true;
|
282 | return empty;
|
283 | })();
|
284 | return Subscription;
|
285 | }());
|
286 | var EMPTY_SUBSCRIPTION = Subscription.EMPTY;
|
287 | function isSubscription(value) {
|
288 | return (value instanceof Subscription ||
|
289 | (value && 'closed' in value && isFunction(value.remove) && isFunction(value.add) && isFunction(value.unsubscribe)));
|
290 | }
|
291 | function execTeardown(teardown) {
|
292 | if (isFunction(teardown)) {
|
293 | teardown();
|
294 | }
|
295 | else {
|
296 | teardown.unsubscribe();
|
297 | }
|
298 | }
|
299 |
|
300 | var config = {
|
301 | onUnhandledError: null,
|
302 | onStoppedNotification: null,
|
303 | Promise: undefined,
|
304 | useDeprecatedSynchronousErrorHandling: false,
|
305 | useDeprecatedNextContext: false,
|
306 | };
|
307 |
|
308 | var timeoutProvider = {
|
309 | setTimeout: function () {
|
310 | var args = [];
|
311 | for (var _i = 0; _i < arguments.length; _i++) {
|
312 | args[_i] = arguments[_i];
|
313 | }
|
314 | return (setTimeout).apply(void 0, __spreadArray([], __read(args)));
|
315 | },
|
316 | clearTimeout: function (handle) {
|
317 | return (clearTimeout)(handle);
|
318 | },
|
319 | delegate: undefined,
|
320 | };
|
321 |
|
322 | function reportUnhandledError(err) {
|
323 | timeoutProvider.setTimeout(function () {
|
324 | {
|
325 | throw err;
|
326 | }
|
327 | });
|
328 | }
|
329 |
|
330 | function noop() { }
|
331 |
|
332 | function errorContext(cb) {
|
333 | {
|
334 | cb();
|
335 | }
|
336 | }
|
337 |
|
338 | var Subscriber = (function (_super) {
|
339 | __extends(Subscriber, _super);
|
340 | function Subscriber(destination) {
|
341 | var _this = _super.call(this) || this;
|
342 | _this.isStopped = false;
|
343 | if (destination) {
|
344 | _this.destination = destination;
|
345 | if (isSubscription(destination)) {
|
346 | destination.add(_this);
|
347 | }
|
348 | }
|
349 | else {
|
350 | _this.destination = EMPTY_OBSERVER;
|
351 | }
|
352 | return _this;
|
353 | }
|
354 | Subscriber.create = function (next, error, complete) {
|
355 | return new SafeSubscriber(next, error, complete);
|
356 | };
|
357 | Subscriber.prototype.next = function (value) {
|
358 | if (this.isStopped) ;
|
359 | else {
|
360 | this._next(value);
|
361 | }
|
362 | };
|
363 | Subscriber.prototype.error = function (err) {
|
364 | if (this.isStopped) ;
|
365 | else {
|
366 | this.isStopped = true;
|
367 | this._error(err);
|
368 | }
|
369 | };
|
370 | Subscriber.prototype.complete = function () {
|
371 | if (this.isStopped) ;
|
372 | else {
|
373 | this.isStopped = true;
|
374 | this._complete();
|
375 | }
|
376 | };
|
377 | Subscriber.prototype.unsubscribe = function () {
|
378 | if (!this.closed) {
|
379 | this.isStopped = true;
|
380 | _super.prototype.unsubscribe.call(this);
|
381 | this.destination = null;
|
382 | }
|
383 | };
|
384 | Subscriber.prototype._next = function (value) {
|
385 | this.destination.next(value);
|
386 | };
|
387 | Subscriber.prototype._error = function (err) {
|
388 | try {
|
389 | this.destination.error(err);
|
390 | }
|
391 | finally {
|
392 | this.unsubscribe();
|
393 | }
|
394 | };
|
395 | Subscriber.prototype._complete = function () {
|
396 | try {
|
397 | this.destination.complete();
|
398 | }
|
399 | finally {
|
400 | this.unsubscribe();
|
401 | }
|
402 | };
|
403 | return Subscriber;
|
404 | }(Subscription));
|
405 | var _bind = Function.prototype.bind;
|
406 | function bind(fn, thisArg) {
|
407 | return _bind.call(fn, thisArg);
|
408 | }
|
409 | var ConsumerObserver = (function () {
|
410 | function ConsumerObserver(partialObserver) {
|
411 | this.partialObserver = partialObserver;
|
412 | }
|
413 | ConsumerObserver.prototype.next = function (value) {
|
414 | var partialObserver = this.partialObserver;
|
415 | if (partialObserver.next) {
|
416 | try {
|
417 | partialObserver.next(value);
|
418 | }
|
419 | catch (error) {
|
420 | handleUnhandledError(error);
|
421 | }
|
422 | }
|
423 | };
|
424 | ConsumerObserver.prototype.error = function (err) {
|
425 | var partialObserver = this.partialObserver;
|
426 | if (partialObserver.error) {
|
427 | try {
|
428 | partialObserver.error(err);
|
429 | }
|
430 | catch (error) {
|
431 | handleUnhandledError(error);
|
432 | }
|
433 | }
|
434 | else {
|
435 | handleUnhandledError(err);
|
436 | }
|
437 | };
|
438 | ConsumerObserver.prototype.complete = function () {
|
439 | var partialObserver = this.partialObserver;
|
440 | if (partialObserver.complete) {
|
441 | try {
|
442 | partialObserver.complete();
|
443 | }
|
444 | catch (error) {
|
445 | handleUnhandledError(error);
|
446 | }
|
447 | }
|
448 | };
|
449 | return ConsumerObserver;
|
450 | }());
|
451 | var SafeSubscriber = (function (_super) {
|
452 | __extends(SafeSubscriber, _super);
|
453 | function SafeSubscriber(observerOrNext, error, complete) {
|
454 | var _this = _super.call(this) || this;
|
455 | var partialObserver;
|
456 | if (isFunction(observerOrNext) || !observerOrNext) {
|
457 | partialObserver = {
|
458 | next: observerOrNext !== null && observerOrNext !== void 0 ? observerOrNext : undefined,
|
459 | error: error !== null && error !== void 0 ? error : undefined,
|
460 | complete: complete !== null && complete !== void 0 ? complete : undefined,
|
461 | };
|
462 | }
|
463 | else {
|
464 | var context_1;
|
465 | if (_this && config.useDeprecatedNextContext) {
|
466 | context_1 = Object.create(observerOrNext);
|
467 | context_1.unsubscribe = function () { return _this.unsubscribe(); };
|
468 | partialObserver = {
|
469 | next: observerOrNext.next && bind(observerOrNext.next, context_1),
|
470 | error: observerOrNext.error && bind(observerOrNext.error, context_1),
|
471 | complete: observerOrNext.complete && bind(observerOrNext.complete, context_1),
|
472 | };
|
473 | }
|
474 | else {
|
475 | partialObserver = observerOrNext;
|
476 | }
|
477 | }
|
478 | _this.destination = new ConsumerObserver(partialObserver);
|
479 | return _this;
|
480 | }
|
481 | return SafeSubscriber;
|
482 | }(Subscriber));
|
483 | function handleUnhandledError(error) {
|
484 | {
|
485 | reportUnhandledError(error);
|
486 | }
|
487 | }
|
488 | function defaultErrorHandler(err) {
|
489 | throw err;
|
490 | }
|
491 | var EMPTY_OBSERVER = {
|
492 | closed: true,
|
493 | next: noop,
|
494 | error: defaultErrorHandler,
|
495 | complete: noop,
|
496 | };
|
497 |
|
498 | var observable = (function () { return (typeof Symbol === 'function' && Symbol.observable) || '@@observable'; })();
|
499 |
|
500 | function identity(x) {
|
501 | return x;
|
502 | }
|
503 |
|
504 | function pipeFromArray(fns) {
|
505 | if (fns.length === 0) {
|
506 | return identity;
|
507 | }
|
508 | if (fns.length === 1) {
|
509 | return fns[0];
|
510 | }
|
511 | return function piped(input) {
|
512 | return fns.reduce(function (prev, fn) { return fn(prev); }, input);
|
513 | };
|
514 | }
|
515 |
|
516 | var Observable = (function () {
|
517 | function Observable(subscribe) {
|
518 | if (subscribe) {
|
519 | this._subscribe = subscribe;
|
520 | }
|
521 | }
|
522 | Observable.prototype.lift = function (operator) {
|
523 | var observable = new Observable();
|
524 | observable.source = this;
|
525 | observable.operator = operator;
|
526 | return observable;
|
527 | };
|
528 | Observable.prototype.subscribe = function (observerOrNext, error, complete) {
|
529 | var _this = this;
|
530 | var subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete);
|
531 | errorContext(function () {
|
532 | var _a = _this, operator = _a.operator, source = _a.source;
|
533 | subscriber.add(operator
|
534 | ?
|
535 | operator.call(subscriber, source)
|
536 | : source
|
537 | ?
|
538 | _this._subscribe(subscriber)
|
539 | :
|
540 | _this._trySubscribe(subscriber));
|
541 | });
|
542 | return subscriber;
|
543 | };
|
544 | Observable.prototype._trySubscribe = function (sink) {
|
545 | try {
|
546 | return this._subscribe(sink);
|
547 | }
|
548 | catch (err) {
|
549 | sink.error(err);
|
550 | }
|
551 | };
|
552 | Observable.prototype.forEach = function (next, promiseCtor) {
|
553 | var _this = this;
|
554 | promiseCtor = getPromiseCtor(promiseCtor);
|
555 | return new promiseCtor(function (resolve, reject) {
|
556 | var subscriber = new SafeSubscriber({
|
557 | next: function (value) {
|
558 | try {
|
559 | next(value);
|
560 | }
|
561 | catch (err) {
|
562 | reject(err);
|
563 | subscriber.unsubscribe();
|
564 | }
|
565 | },
|
566 | error: reject,
|
567 | complete: resolve,
|
568 | });
|
569 | _this.subscribe(subscriber);
|
570 | });
|
571 | };
|
572 | Observable.prototype._subscribe = function (subscriber) {
|
573 | var _a;
|
574 | return (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber);
|
575 | };
|
576 | Observable.prototype[observable] = function () {
|
577 | return this;
|
578 | };
|
579 | Observable.prototype.pipe = function () {
|
580 | var operations = [];
|
581 | for (var _i = 0; _i < arguments.length; _i++) {
|
582 | operations[_i] = arguments[_i];
|
583 | }
|
584 | return pipeFromArray(operations)(this);
|
585 | };
|
586 | Observable.prototype.toPromise = function (promiseCtor) {
|
587 | var _this = this;
|
588 | promiseCtor = getPromiseCtor(promiseCtor);
|
589 | return new promiseCtor(function (resolve, reject) {
|
590 | var value;
|
591 | _this.subscribe(function (x) { return (value = x); }, function (err) { return reject(err); }, function () { return resolve(value); });
|
592 | });
|
593 | };
|
594 | Observable.create = function (subscribe) {
|
595 | return new Observable(subscribe);
|
596 | };
|
597 | return Observable;
|
598 | }());
|
599 | function getPromiseCtor(promiseCtor) {
|
600 | var _a;
|
601 | return (_a = promiseCtor !== null && promiseCtor !== void 0 ? promiseCtor : config.Promise) !== null && _a !== void 0 ? _a : Promise;
|
602 | }
|
603 | function isObserver(value) {
|
604 | return value && isFunction(value.next) && isFunction(value.error) && isFunction(value.complete);
|
605 | }
|
606 | function isSubscriber(value) {
|
607 | return (value && value instanceof Subscriber) || (isObserver(value) && isSubscription(value));
|
608 | }
|
609 |
|
610 | function hasLift(source) {
|
611 | return isFunction(source === null || source === void 0 ? void 0 : source.lift);
|
612 | }
|
613 | function operate(init) {
|
614 | return function (source) {
|
615 | if (hasLift(source)) {
|
616 | return source.lift(function (liftedSource) {
|
617 | try {
|
618 | return init(liftedSource, this);
|
619 | }
|
620 | catch (err) {
|
621 | this.error(err);
|
622 | }
|
623 | });
|
624 | }
|
625 | throw new TypeError('Unable to lift unknown Observable type');
|
626 | };
|
627 | }
|
628 |
|
629 | function createOperatorSubscriber(destination, onNext, onComplete, onError, onFinalize) {
|
630 | return new OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize);
|
631 | }
|
632 | var OperatorSubscriber = (function (_super) {
|
633 | __extends(OperatorSubscriber, _super);
|
634 | function OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize, shouldUnsubscribe) {
|
635 | var _this = _super.call(this, destination) || this;
|
636 | _this.onFinalize = onFinalize;
|
637 | _this.shouldUnsubscribe = shouldUnsubscribe;
|
638 | _this._next = onNext
|
639 | ? function (value) {
|
640 | try {
|
641 | onNext(value);
|
642 | }
|
643 | catch (err) {
|
644 | destination.error(err);
|
645 | }
|
646 | }
|
647 | : _super.prototype._next;
|
648 | _this._error = onError
|
649 | ? function (err) {
|
650 | try {
|
651 | onError(err);
|
652 | }
|
653 | catch (err) {
|
654 | destination.error(err);
|
655 | }
|
656 | finally {
|
657 | this.unsubscribe();
|
658 | }
|
659 | }
|
660 | : _super.prototype._error;
|
661 | _this._complete = onComplete
|
662 | ? function () {
|
663 | try {
|
664 | onComplete();
|
665 | }
|
666 | catch (err) {
|
667 | destination.error(err);
|
668 | }
|
669 | finally {
|
670 | this.unsubscribe();
|
671 | }
|
672 | }
|
673 | : _super.prototype._complete;
|
674 | return _this;
|
675 | }
|
676 | OperatorSubscriber.prototype.unsubscribe = function () {
|
677 | var _a;
|
678 | if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
|
679 | var closed_1 = this.closed;
|
680 | _super.prototype.unsubscribe.call(this);
|
681 | !closed_1 && ((_a = this.onFinalize) === null || _a === void 0 ? void 0 : _a.call(this));
|
682 | }
|
683 | };
|
684 | return OperatorSubscriber;
|
685 | }(Subscriber));
|
686 |
|
687 | var ObjectUnsubscribedError = createErrorClass(function (_super) {
|
688 | return function ObjectUnsubscribedErrorImpl() {
|
689 | _super(this);
|
690 | this.name = 'ObjectUnsubscribedError';
|
691 | this.message = 'object unsubscribed';
|
692 | };
|
693 | });
|
694 |
|
695 | var Subject = (function (_super) {
|
696 | __extends(Subject, _super);
|
697 | function Subject() {
|
698 | var _this = _super.call(this) || this;
|
699 | _this.closed = false;
|
700 | _this.observers = [];
|
701 | _this.isStopped = false;
|
702 | _this.hasError = false;
|
703 | _this.thrownError = null;
|
704 | return _this;
|
705 | }
|
706 | Subject.prototype.lift = function (operator) {
|
707 | var subject = new AnonymousSubject(this, this);
|
708 | subject.operator = operator;
|
709 | return subject;
|
710 | };
|
711 | Subject.prototype._throwIfClosed = function () {
|
712 | if (this.closed) {
|
713 | throw new ObjectUnsubscribedError();
|
714 | }
|
715 | };
|
716 | Subject.prototype.next = function (value) {
|
717 | var _this = this;
|
718 | errorContext(function () {
|
719 | var e_1, _a;
|
720 | _this._throwIfClosed();
|
721 | if (!_this.isStopped) {
|
722 | var copy = _this.observers.slice();
|
723 | try {
|
724 | for (var copy_1 = __values(copy), copy_1_1 = copy_1.next(); !copy_1_1.done; copy_1_1 = copy_1.next()) {
|
725 | var observer = copy_1_1.value;
|
726 | observer.next(value);
|
727 | }
|
728 | }
|
729 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
730 | finally {
|
731 | try {
|
732 | if (copy_1_1 && !copy_1_1.done && (_a = copy_1.return)) _a.call(copy_1);
|
733 | }
|
734 | finally { if (e_1) throw e_1.error; }
|
735 | }
|
736 | }
|
737 | });
|
738 | };
|
739 | Subject.prototype.error = function (err) {
|
740 | var _this = this;
|
741 | errorContext(function () {
|
742 | _this._throwIfClosed();
|
743 | if (!_this.isStopped) {
|
744 | _this.hasError = _this.isStopped = true;
|
745 | _this.thrownError = err;
|
746 | var observers = _this.observers;
|
747 | while (observers.length) {
|
748 | observers.shift().error(err);
|
749 | }
|
750 | }
|
751 | });
|
752 | };
|
753 | Subject.prototype.complete = function () {
|
754 | var _this = this;
|
755 | errorContext(function () {
|
756 | _this._throwIfClosed();
|
757 | if (!_this.isStopped) {
|
758 | _this.isStopped = true;
|
759 | var observers = _this.observers;
|
760 | while (observers.length) {
|
761 | observers.shift().complete();
|
762 | }
|
763 | }
|
764 | });
|
765 | };
|
766 | Subject.prototype.unsubscribe = function () {
|
767 | this.isStopped = this.closed = true;
|
768 | this.observers = null;
|
769 | };
|
770 | Object.defineProperty(Subject.prototype, "observed", {
|
771 | get: function () {
|
772 | var _a;
|
773 | return ((_a = this.observers) === null || _a === void 0 ? void 0 : _a.length) > 0;
|
774 | },
|
775 | enumerable: false,
|
776 | configurable: true
|
777 | });
|
778 | Subject.prototype._trySubscribe = function (subscriber) {
|
779 | this._throwIfClosed();
|
780 | return _super.prototype._trySubscribe.call(this, subscriber);
|
781 | };
|
782 | Subject.prototype._subscribe = function (subscriber) {
|
783 | this._throwIfClosed();
|
784 | this._checkFinalizedStatuses(subscriber);
|
785 | return this._innerSubscribe(subscriber);
|
786 | };
|
787 | Subject.prototype._innerSubscribe = function (subscriber) {
|
788 | var _a = this, hasError = _a.hasError, isStopped = _a.isStopped, observers = _a.observers;
|
789 | return hasError || isStopped
|
790 | ? EMPTY_SUBSCRIPTION
|
791 | : (observers.push(subscriber), new Subscription(function () { return arrRemove(observers, subscriber); }));
|
792 | };
|
793 | Subject.prototype._checkFinalizedStatuses = function (subscriber) {
|
794 | var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, isStopped = _a.isStopped;
|
795 | if (hasError) {
|
796 | subscriber.error(thrownError);
|
797 | }
|
798 | else if (isStopped) {
|
799 | subscriber.complete();
|
800 | }
|
801 | };
|
802 | Subject.prototype.asObservable = function () {
|
803 | var observable = new Observable();
|
804 | observable.source = this;
|
805 | return observable;
|
806 | };
|
807 | Subject.create = function (destination, source) {
|
808 | return new AnonymousSubject(destination, source);
|
809 | };
|
810 | return Subject;
|
811 | }(Observable));
|
812 | var AnonymousSubject = (function (_super) {
|
813 | __extends(AnonymousSubject, _super);
|
814 | function AnonymousSubject(destination, source) {
|
815 | var _this = _super.call(this) || this;
|
816 | _this.destination = destination;
|
817 | _this.source = source;
|
818 | return _this;
|
819 | }
|
820 | AnonymousSubject.prototype.next = function (value) {
|
821 | var _a, _b;
|
822 | (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.next) === null || _b === void 0 ? void 0 : _b.call(_a, value);
|
823 | };
|
824 | AnonymousSubject.prototype.error = function (err) {
|
825 | var _a, _b;
|
826 | (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.call(_a, err);
|
827 | };
|
828 | AnonymousSubject.prototype.complete = function () {
|
829 | var _a, _b;
|
830 | (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.complete) === null || _b === void 0 ? void 0 : _b.call(_a);
|
831 | };
|
832 | AnonymousSubject.prototype._subscribe = function (subscriber) {
|
833 | var _a, _b;
|
834 | return (_b = (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber)) !== null && _b !== void 0 ? _b : EMPTY_SUBSCRIPTION;
|
835 | };
|
836 | return AnonymousSubject;
|
837 | }(Subject));
|
838 |
|
839 | var isArrayLike = (function (x) { return x && typeof x.length === 'number' && typeof x !== 'function'; });
|
840 |
|
841 | function isPromise(value) {
|
842 | return isFunction(value === null || value === void 0 ? void 0 : value.then);
|
843 | }
|
844 |
|
845 | function isInteropObservable(input) {
|
846 | return isFunction(input[observable]);
|
847 | }
|
848 |
|
849 | function isAsyncIterable(obj) {
|
850 | return Symbol.asyncIterator && isFunction(obj === null || obj === void 0 ? void 0 : obj[Symbol.asyncIterator]);
|
851 | }
|
852 |
|
853 | function createInvalidObservableTypeError(input) {
|
854 | 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.");
|
855 | }
|
856 |
|
857 | function getSymbolIterator() {
|
858 | if (typeof Symbol !== 'function' || !Symbol.iterator) {
|
859 | return '@@iterator';
|
860 | }
|
861 | return Symbol.iterator;
|
862 | }
|
863 | var iterator = getSymbolIterator();
|
864 |
|
865 | function isIterable(input) {
|
866 | return isFunction(input === null || input === void 0 ? void 0 : input[iterator]);
|
867 | }
|
868 |
|
869 | function readableStreamLikeToAsyncGenerator(readableStream) {
|
870 | return __asyncGenerator(this, arguments, function readableStreamLikeToAsyncGenerator_1() {
|
871 | var reader, _a, value, done;
|
872 | return __generator(this, function (_b) {
|
873 | switch (_b.label) {
|
874 | case 0:
|
875 | reader = readableStream.getReader();
|
876 | _b.label = 1;
|
877 | case 1:
|
878 | _b.trys.push([1, , 9, 10]);
|
879 | _b.label = 2;
|
880 | case 2:
|
881 | return [4, __await(reader.read())];
|
882 | case 3:
|
883 | _a = _b.sent(), value = _a.value, done = _a.done;
|
884 | if (!done) return [3, 5];
|
885 | return [4, __await(void 0)];
|
886 | case 4: return [2, _b.sent()];
|
887 | case 5: return [4, __await(value)];
|
888 | case 6: return [4, _b.sent()];
|
889 | case 7:
|
890 | _b.sent();
|
891 | return [3, 2];
|
892 | case 8: return [3, 10];
|
893 | case 9:
|
894 | reader.releaseLock();
|
895 | return [7];
|
896 | case 10: return [2];
|
897 | }
|
898 | });
|
899 | });
|
900 | }
|
901 | function isReadableStreamLike(obj) {
|
902 | return isFunction(obj === null || obj === void 0 ? void 0 : obj.getReader);
|
903 | }
|
904 |
|
905 | function innerFrom(input) {
|
906 | if (input instanceof Observable) {
|
907 | return input;
|
908 | }
|
909 | if (input != null) {
|
910 | if (isInteropObservable(input)) {
|
911 | return fromInteropObservable(input);
|
912 | }
|
913 | if (isArrayLike(input)) {
|
914 | return fromArrayLike(input);
|
915 | }
|
916 | if (isPromise(input)) {
|
917 | return fromPromise(input);
|
918 | }
|
919 | if (isAsyncIterable(input)) {
|
920 | return fromAsyncIterable(input);
|
921 | }
|
922 | if (isIterable(input)) {
|
923 | return fromIterable(input);
|
924 | }
|
925 | if (isReadableStreamLike(input)) {
|
926 | return fromReadableStreamLike(input);
|
927 | }
|
928 | }
|
929 | throw createInvalidObservableTypeError(input);
|
930 | }
|
931 | function fromInteropObservable(obj) {
|
932 | return new Observable(function (subscriber) {
|
933 | var obs = obj[observable]();
|
934 | if (isFunction(obs.subscribe)) {
|
935 | return obs.subscribe(subscriber);
|
936 | }
|
937 | throw new TypeError('Provided object does not correctly implement Symbol.observable');
|
938 | });
|
939 | }
|
940 | function fromArrayLike(array) {
|
941 | return new Observable(function (subscriber) {
|
942 | for (var i = 0; i < array.length && !subscriber.closed; i++) {
|
943 | subscriber.next(array[i]);
|
944 | }
|
945 | subscriber.complete();
|
946 | });
|
947 | }
|
948 | function fromPromise(promise) {
|
949 | return new Observable(function (subscriber) {
|
950 | promise
|
951 | .then(function (value) {
|
952 | if (!subscriber.closed) {
|
953 | subscriber.next(value);
|
954 | subscriber.complete();
|
955 | }
|
956 | }, function (err) { return subscriber.error(err); })
|
957 | .then(null, reportUnhandledError);
|
958 | });
|
959 | }
|
960 | function fromIterable(iterable) {
|
961 | return new Observable(function (subscriber) {
|
962 | var e_1, _a;
|
963 | try {
|
964 | for (var iterable_1 = __values(iterable), iterable_1_1 = iterable_1.next(); !iterable_1_1.done; iterable_1_1 = iterable_1.next()) {
|
965 | var value = iterable_1_1.value;
|
966 | subscriber.next(value);
|
967 | if (subscriber.closed) {
|
968 | return;
|
969 | }
|
970 | }
|
971 | }
|
972 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
973 | finally {
|
974 | try {
|
975 | if (iterable_1_1 && !iterable_1_1.done && (_a = iterable_1.return)) _a.call(iterable_1);
|
976 | }
|
977 | finally { if (e_1) throw e_1.error; }
|
978 | }
|
979 | subscriber.complete();
|
980 | });
|
981 | }
|
982 | function fromAsyncIterable(asyncIterable) {
|
983 | return new Observable(function (subscriber) {
|
984 | process(asyncIterable, subscriber).catch(function (err) { return subscriber.error(err); });
|
985 | });
|
986 | }
|
987 | function fromReadableStreamLike(readableStream) {
|
988 | return fromAsyncIterable(readableStreamLikeToAsyncGenerator(readableStream));
|
989 | }
|
990 | function process(asyncIterable, subscriber) {
|
991 | var asyncIterable_1, asyncIterable_1_1;
|
992 | var e_2, _a;
|
993 | return __awaiter(this, void 0, void 0, function () {
|
994 | var value, e_2_1;
|
995 | return __generator(this, function (_b) {
|
996 | switch (_b.label) {
|
997 | case 0:
|
998 | _b.trys.push([0, 5, 6, 11]);
|
999 | asyncIterable_1 = __asyncValues(asyncIterable);
|
1000 | _b.label = 1;
|
1001 | case 1: return [4, asyncIterable_1.next()];
|
1002 | case 2:
|
1003 | if (!(asyncIterable_1_1 = _b.sent(), !asyncIterable_1_1.done)) return [3, 4];
|
1004 | value = asyncIterable_1_1.value;
|
1005 | subscriber.next(value);
|
1006 | if (subscriber.closed) {
|
1007 | return [2];
|
1008 | }
|
1009 | _b.label = 3;
|
1010 | case 3: return [3, 1];
|
1011 | case 4: return [3, 11];
|
1012 | case 5:
|
1013 | e_2_1 = _b.sent();
|
1014 | e_2 = { error: e_2_1 };
|
1015 | return [3, 11];
|
1016 | case 6:
|
1017 | _b.trys.push([6, , 9, 10]);
|
1018 | if (!(asyncIterable_1_1 && !asyncIterable_1_1.done && (_a = asyncIterable_1.return))) return [3, 8];
|
1019 | return [4, _a.call(asyncIterable_1)];
|
1020 | case 7:
|
1021 | _b.sent();
|
1022 | _b.label = 8;
|
1023 | case 8: return [3, 10];
|
1024 | case 9:
|
1025 | if (e_2) throw e_2.error;
|
1026 | return [7];
|
1027 | case 10: return [7];
|
1028 | case 11:
|
1029 | subscriber.complete();
|
1030 | return [2];
|
1031 | }
|
1032 | });
|
1033 | });
|
1034 | }
|
1035 |
|
1036 | function takeUntil(notifier) {
|
1037 | return operate(function (source, subscriber) {
|
1038 | innerFrom(notifier).subscribe(createOperatorSubscriber(subscriber, function () { return subscriber.complete(); }, noop));
|
1039 | !subscriber.closed && source.subscribe(subscriber);
|
1040 | });
|
1041 | }
|
1042 |
|
1043 | var entityId = 0;
|
1044 |
|
1045 |
|
1046 |
|
1047 | var Entity = (function () {
|
1048 | function Entity() {
|
1049 | this._componentAddedSubject$ = new Subject();
|
1050 | this._componentRemovedSubject$ = new Subject();
|
1051 | this._componentMap = new Map();
|
1052 | this.id = entityId++;
|
1053 | }
|
1054 | |
1055 |
|
1056 |
|
1057 |
|
1058 | Entity.prototype.hasComponent = function (componentName) {
|
1059 | return this._componentMap.has(componentName);
|
1060 | };
|
1061 | |
1062 |
|
1063 |
|
1064 |
|
1065 | Entity.prototype.getComponent = function (componentName) {
|
1066 | var component = this._componentMap.get(componentName);
|
1067 | if (typeof component !== 'undefined') {
|
1068 | return component;
|
1069 | }
|
1070 | return undefined;
|
1071 | };
|
1072 | |
1073 |
|
1074 |
|
1075 |
|
1076 | Entity.prototype.addComponent = function (component) {
|
1077 | this._componentMap.set(component.name, component);
|
1078 | this._componentAddedSubject$.next(component);
|
1079 | return this;
|
1080 | };
|
1081 | |
1082 |
|
1083 |
|
1084 |
|
1085 | Entity.prototype.removeComponent = function (componentName) {
|
1086 | var component = this._componentMap.get(componentName);
|
1087 | if (typeof component !== 'undefined') {
|
1088 | this._componentMap.delete(componentName);
|
1089 | this._componentRemovedSubject$.next(component);
|
1090 | }
|
1091 | return this;
|
1092 | };
|
1093 | Object.defineProperty(Entity.prototype, "componentAdded$", {
|
1094 | |
1095 |
|
1096 |
|
1097 |
|
1098 | get: function () {
|
1099 | return this._componentAddedSubject$.asObservable();
|
1100 | },
|
1101 | enumerable: false,
|
1102 | configurable: true
|
1103 | });
|
1104 | Object.defineProperty(Entity.prototype, "componentRemoved$", {
|
1105 | |
1106 |
|
1107 |
|
1108 |
|
1109 | get: function () {
|
1110 | return this._componentRemovedSubject$.asObservable();
|
1111 | },
|
1112 | enumerable: false,
|
1113 | configurable: true
|
1114 | });
|
1115 | return Entity;
|
1116 | }());
|
1117 |
|
1118 |
|
1119 |
|
1120 |
|
1121 | var System = (function () {
|
1122 | function System() {
|
1123 | }
|
1124 | |
1125 |
|
1126 |
|
1127 |
|
1128 | System.prototype.addedToWorld = function (world) {
|
1129 | this._world = world;
|
1130 | };
|
1131 | |
1132 |
|
1133 |
|
1134 |
|
1135 | System.prototype.removedFromWorld = function (world) {
|
1136 | this._world = undefined;
|
1137 | };
|
1138 | |
1139 |
|
1140 |
|
1141 |
|
1142 | System.prototype.update = function (tickerData) {
|
1143 |
|
1144 | };
|
1145 | Object.defineProperty(System.prototype, "world", {
|
1146 | |
1147 |
|
1148 |
|
1149 | get: function () {
|
1150 | if (!this._world) {
|
1151 | throw Error('wait till the system is added to the world');
|
1152 | }
|
1153 | return this._world;
|
1154 | },
|
1155 | enumerable: false,
|
1156 | configurable: true
|
1157 | });
|
1158 | return System;
|
1159 | }());
|
1160 |
|
1161 | var EntityNode = (function () {
|
1162 | function EntityNode(entity) {
|
1163 | this.prev = null;
|
1164 | this.next = null;
|
1165 | this.entity = entity;
|
1166 | }
|
1167 | return EntityNode;
|
1168 | }());
|
1169 |
|
1170 |
|
1171 |
|
1172 |
|
1173 |
|
1174 | var EntityList = (function () {
|
1175 | function EntityList() {
|
1176 | this.length = 0;
|
1177 | this.head = null;
|
1178 | this.tail = null;
|
1179 | this._entityMap = new Map();
|
1180 |
|
1181 | }
|
1182 | |
1183 |
|
1184 |
|
1185 |
|
1186 | EntityList.prototype.add = function (entity) {
|
1187 | var node = new EntityNode(entity);
|
1188 | if (this.head === null) {
|
1189 | this.head = this.tail = node;
|
1190 | }
|
1191 | else {
|
1192 | node.prev = this.tail;
|
1193 | if (this.tail) {
|
1194 | this.tail.next = node;
|
1195 | }
|
1196 | this.tail = node;
|
1197 | }
|
1198 | this.length += 1;
|
1199 | this._entityMap.set(entity.id, node);
|
1200 | };
|
1201 | |
1202 |
|
1203 |
|
1204 |
|
1205 | EntityList.prototype.remove = function (entity) {
|
1206 | var entityId = entity.id;
|
1207 | var node = this._entityMap.get(entityId);
|
1208 | if (typeof node === 'undefined') {
|
1209 | return;
|
1210 | }
|
1211 | if (node.prev === null) {
|
1212 | this.head = node.next;
|
1213 | }
|
1214 | else {
|
1215 | node.prev.next = node.next;
|
1216 | }
|
1217 | if (node.next === null) {
|
1218 | this.tail = node.prev;
|
1219 | }
|
1220 | else {
|
1221 | node.next.prev = node.prev;
|
1222 | }
|
1223 | this.length -= 1;
|
1224 | this._entityMap.delete(entityId);
|
1225 | };
|
1226 | |
1227 |
|
1228 |
|
1229 |
|
1230 | EntityList.prototype.has = function (entity) {
|
1231 | return this._entityMap.has(entity.id);
|
1232 | };
|
1233 | |
1234 |
|
1235 |
|
1236 | EntityList.prototype.clear = function () {
|
1237 | this.head = this.tail = null;
|
1238 | this.length = 0;
|
1239 | this._entityMap.clear();
|
1240 | };
|
1241 | |
1242 |
|
1243 |
|
1244 | EntityList.prototype.toArray = function () {
|
1245 | var array = [], node;
|
1246 | for (node = this.head; node; node = node.next) {
|
1247 | array.push(node.entity);
|
1248 | }
|
1249 | return array;
|
1250 | };
|
1251 | return EntityList;
|
1252 | }());
|
1253 |
|
1254 | var Family = (function () {
|
1255 | function Family(componentNames) {
|
1256 | this._entityAddedSubject$ = new Subject();
|
1257 | this._entityRemovedSubject$ = new Subject();
|
1258 | this._entities = new EntityList();
|
1259 | this._componentNames = componentNames;
|
1260 | }
|
1261 | |
1262 |
|
1263 |
|
1264 | Family.prototype.getEntities = function () {
|
1265 | return this._entities.toArray();
|
1266 | };
|
1267 | |
1268 |
|
1269 |
|
1270 |
|
1271 | Family.prototype.addEntityIfMatch = function (entity) {
|
1272 | if (!this._entities.has(entity) && this.matchEntity(entity)) {
|
1273 | this._entities.add(entity);
|
1274 | this._entityAddedSubject$.next(entity);
|
1275 | }
|
1276 | };
|
1277 | |
1278 |
|
1279 |
|
1280 |
|
1281 | Family.prototype.removeEntity = function (entity) {
|
1282 | if (this._entities.has(entity)) {
|
1283 | this._entities.remove(entity);
|
1284 | this._entityRemovedSubject$.next(entity);
|
1285 | }
|
1286 | };
|
1287 | Family.prototype.onComponentAdded = function (entity, component) {
|
1288 | this.addEntityIfMatch(entity);
|
1289 | };
|
1290 | Family.prototype.onComponentRemoved = function (entity, component) {
|
1291 |
|
1292 | if (!this._entities.has(entity)) {
|
1293 | return;
|
1294 | }
|
1295 |
|
1296 | var names = this._componentNames;
|
1297 | var len = names.length;
|
1298 | for (var i = 0; i < len; ++i) {
|
1299 | if (names[i] === component.name) {
|
1300 | this._entities.remove(entity);
|
1301 | this._entityRemovedSubject$.next(entity);
|
1302 | }
|
1303 | }
|
1304 | };
|
1305 | Object.defineProperty(Family.prototype, "entityAdded$", {
|
1306 | |
1307 |
|
1308 |
|
1309 | get: function () {
|
1310 | return this._entityAddedSubject$.asObservable();
|
1311 | },
|
1312 | enumerable: false,
|
1313 | configurable: true
|
1314 | });
|
1315 | Object.defineProperty(Family.prototype, "entityRemoved$", {
|
1316 | |
1317 |
|
1318 |
|
1319 | get: function () {
|
1320 | return this._entityRemovedSubject$.asObservable();
|
1321 | },
|
1322 | enumerable: false,
|
1323 | configurable: true
|
1324 | });
|
1325 | Family.prototype.matchEntity = function (entity) {
|
1326 | var componentNames = this._componentNames;
|
1327 | var len = componentNames.length;
|
1328 | for (var i = 0; i < len; ++i) {
|
1329 | if (!entity.hasComponent(componentNames[i])) {
|
1330 | return false;
|
1331 | }
|
1332 | }
|
1333 | return true;
|
1334 | };
|
1335 | return Family;
|
1336 | }());
|
1337 |
|
1338 | var World = (function () {
|
1339 | function World() {
|
1340 | this._systems = [];
|
1341 | this._entities = new EntityList();
|
1342 | this._families = new Map();
|
1343 | this._disposeEntityMap = new Map();
|
1344 |
|
1345 | }
|
1346 | |
1347 |
|
1348 |
|
1349 |
|
1350 | World.prototype.addSystem = function (system) {
|
1351 | this._systems.push(system);
|
1352 | system.addedToWorld(this);
|
1353 | return this;
|
1354 | };
|
1355 | |
1356 |
|
1357 |
|
1358 |
|
1359 | World.prototype.removeSystem = function (system) {
|
1360 | var systems = this._systems;
|
1361 | var len = systems.length;
|
1362 | for (var i = 0; i < len; ++i) {
|
1363 | if (systems[i] === system) {
|
1364 | systems.splice(i, 1);
|
1365 | system.removedFromWorld(this);
|
1366 | }
|
1367 | }
|
1368 | return this;
|
1369 | };
|
1370 | |
1371 |
|
1372 |
|
1373 | World.prototype.removeAllSystems = function () {
|
1374 | var _this = this;
|
1375 | this._systems.forEach(function (system) { return system.removedFromWorld(_this); });
|
1376 | this._systems.length = 0;
|
1377 | return this;
|
1378 | };
|
1379 | |
1380 |
|
1381 |
|
1382 |
|
1383 | World.prototype.addEntity = function (entity) {
|
1384 | var _this = this;
|
1385 |
|
1386 | this._families.forEach(function (family) { return family.addEntityIfMatch(entity); });
|
1387 | var dispose$ = new Subject();
|
1388 | this._disposeEntityMap.set(entity, dispose$);
|
1389 |
|
1390 |
|
1391 | var componentAdded$ = entity.componentAdded$, componentRemoved$ = entity.componentRemoved$;
|
1392 | componentAdded$.pipe(takeUntil(dispose$)).subscribe(function (component) { return _this.onComponentAdded(entity, component); });
|
1393 | componentRemoved$.pipe(takeUntil(dispose$)).subscribe(function (component) { return _this.onComponentRemoved(entity, component); });
|
1394 | this._entities.add(entity);
|
1395 | return this;
|
1396 | };
|
1397 | |
1398 |
|
1399 |
|
1400 |
|
1401 | World.prototype.removeEntity = function (entity) {
|
1402 | this._families.forEach(function (family) { return family.removeEntity(entity); });
|
1403 | this._entities.remove(entity);
|
1404 | var dispose$ = this._disposeEntityMap.get(entity);
|
1405 | if (typeof dispose$ !== 'undefined') {
|
1406 | dispose$.next();
|
1407 | this._disposeEntityMap.delete(entity);
|
1408 | }
|
1409 | return this;
|
1410 | };
|
1411 | |
1412 |
|
1413 |
|
1414 | World.prototype.removeAllEntities = function () {
|
1415 | var _this = this;
|
1416 | this._entities.toArray().forEach(function (entity) { return _this.removeEntity(entity); });
|
1417 | return this;
|
1418 | };
|
1419 | |
1420 |
|
1421 |
|
1422 |
|
1423 | World.prototype.getEntities = function (componentNames) {
|
1424 | var familyId = this.generateFamilyId(componentNames);
|
1425 | this.ensureFamilyExists(componentNames, familyId);
|
1426 | var family = this._families.get(familyId);
|
1427 | if (typeof family !== 'undefined') {
|
1428 | return family.getEntities();
|
1429 | }
|
1430 | throw Error("unable to getEntities, " + componentNames);
|
1431 | };
|
1432 | |
1433 |
|
1434 |
|
1435 |
|
1436 | World.prototype.update = function (tickerData) {
|
1437 | var systems = this._systems;
|
1438 | var len = systems.length;
|
1439 | for (var i = 0; i < len; ++i) {
|
1440 | systems[i].update(tickerData);
|
1441 | }
|
1442 | };
|
1443 | |
1444 |
|
1445 |
|
1446 |
|
1447 |
|
1448 |
|
1449 |
|
1450 | World.prototype.entityAdded$ = function (componentNames) {
|
1451 | var familyId = this.generateFamilyId(componentNames);
|
1452 | this.ensureFamilyExists(componentNames, familyId);
|
1453 | var family = this._families.get(familyId);
|
1454 | if (typeof family !== 'undefined') {
|
1455 | return family.entityAdded$;
|
1456 | }
|
1457 | throw Error("unable to perform entityAdded, " + componentNames);
|
1458 | };
|
1459 | |
1460 |
|
1461 |
|
1462 |
|
1463 |
|
1464 |
|
1465 |
|
1466 | World.prototype.entityRemoved$ = function (componentNames) {
|
1467 | var familyId = this.generateFamilyId(componentNames);
|
1468 | this.ensureFamilyExists(componentNames, familyId);
|
1469 | var family = this._families.get(familyId);
|
1470 | if (typeof family !== 'undefined') {
|
1471 | return family.entityRemoved$;
|
1472 | }
|
1473 | throw Error("unable to perform entityRemoved, " + componentNames);
|
1474 | };
|
1475 | World.prototype.generateFamilyId = function (componentNames) {
|
1476 | var keys = componentNames.map(function (data) { return data.toString(); });
|
1477 | return "$-" + keys.join(',');
|
1478 | };
|
1479 | World.prototype.ensureFamilyExists = function (componentNames, familyId) {
|
1480 | var families = this._families;
|
1481 | if (families.has(familyId)) {
|
1482 | return;
|
1483 | }
|
1484 | var family = new Family(__spreadArray([], componentNames));
|
1485 | families.set(familyId, family);
|
1486 | for (var node = this._entities.head; node; node = node.next) {
|
1487 | var family_1 = families.get(familyId);
|
1488 | if (typeof family_1 !== 'undefined') {
|
1489 | family_1.addEntityIfMatch(node.entity);
|
1490 | }
|
1491 | }
|
1492 | };
|
1493 | World.prototype.onComponentAdded = function (entity, component) {
|
1494 | this._families.forEach(function (family) { return family.onComponentAdded(entity, component); });
|
1495 | };
|
1496 | World.prototype.onComponentRemoved = function (entity, component) {
|
1497 | this._families.forEach(function (family) { return family.onComponentRemoved(entity, component); });
|
1498 | };
|
1499 | return World;
|
1500 | }());
|
1501 |
|
1502 | export { Entity, System, World };
|
1503 |
|