UNPKG

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