|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = function (d, b) {
- extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return extendStatics(d, b);
- }
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var isFunction_1 = require("./util/isFunction");
- var Observer_1 = require("./Observer");
- var Subscription_1 = require("./Subscription");
- var rxSubscriber_1 = require("../internal/symbol/rxSubscriber");
- var config_1 = require("./config");
- var hostReportError_1 = require("./util/hostReportError");
- var Subscriber = (function (_super) {
- __extends(Subscriber, _super);
- function Subscriber(destinationOrNext, error, complete) {
- var _this = _super.call(this) || this;
- _this.syncErrorValue = null;
- _this.syncErrorThrown = false;
- _this.syncErrorThrowable = false;
- _this.isStopped = false;
- _this._parentSubscription = null;
- switch (arguments.length) {
- case 0:
- _this.destination = Observer_1.empty;
- break;
- case 1:
- if (!destinationOrNext) {
- _this.destination = Observer_1.empty;
- break;
- }
- if (typeof destinationOrNext === 'object') {
- if (destinationOrNext instanceof Subscriber) {
- _this.syncErrorThrowable = destinationOrNext.syncErrorThrowable;
- _this.destination = destinationOrNext;
- destinationOrNext.add(_this);
- }
- else {
- _this.syncErrorThrowable = true;
- _this.destination = new SafeSubscriber(_this, destinationOrNext);
- }
- break;
- }
- default:
- _this.syncErrorThrowable = true;
- _this.destination = new SafeSubscriber(_this, destinationOrNext, error, complete);
- break;
- }
- return _this;
- }
- Subscriber.prototype[rxSubscriber_1.rxSubscriber] = function () { return this; };
- Subscriber.create = function (next, error, complete) {
- var subscriber = new Subscriber(next, error, complete);
- subscriber.syncErrorThrowable = false;
- return subscriber;
- };
- Subscriber.prototype.next = function (value) {
- if (!this.isStopped) {
- this._next(value);
- }
- };
- Subscriber.prototype.error = function (err) {
- if (!this.isStopped) {
- this.isStopped = true;
- this._error(err);
- }
- };
- Subscriber.prototype.complete = function () {
- if (!this.isStopped) {
- this.isStopped = true;
- this._complete();
- }
- };
- Subscriber.prototype.unsubscribe = function () {
- if (this.closed) {
- return;
- }
- this.isStopped = true;
- _super.prototype.unsubscribe.call(this);
- };
- Subscriber.prototype._next = function (value) {
- this.destination.next(value);
- };
- Subscriber.prototype._error = function (err) {
- this.destination.error(err);
- this.unsubscribe();
- };
- Subscriber.prototype._complete = function () {
- this.destination.complete();
- this.unsubscribe();
- };
- Subscriber.prototype._unsubscribeAndRecycle = function () {
- var _a = this, _parent = _a._parent, _parents = _a._parents;
- this._parent = null;
- this._parents = null;
- this.unsubscribe();
- this.closed = false;
- this.isStopped = false;
- this._parent = _parent;
- this._parents = _parents;
- this._parentSubscription = null;
- return this;
- };
- return Subscriber;
- }(Subscription_1.Subscription));
- exports.Subscriber = Subscriber;
- var SafeSubscriber = (function (_super) {
- __extends(SafeSubscriber, _super);
- function SafeSubscriber(_parentSubscriber, observerOrNext, error, complete) {
- var _this = _super.call(this) || this;
- _this._parentSubscriber = _parentSubscriber;
- var next;
- var context = _this;
- if (isFunction_1.isFunction(observerOrNext)) {
- next = observerOrNext;
- }
- else if (observerOrNext) {
- next = observerOrNext.next;
- error = observerOrNext.error;
- complete = observerOrNext.complete;
- if (observerOrNext !== Observer_1.empty) {
- context = Object.create(observerOrNext);
- if (isFunction_1.isFunction(context.unsubscribe)) {
- _this.add(context.unsubscribe.bind(context));
- }
- context.unsubscribe = _this.unsubscribe.bind(_this);
- }
- }
- _this._context = context;
- _this._next = next;
- _this._error = error;
- _this._complete = complete;
- return _this;
- }
- SafeSubscriber.prototype.next = function (value) {
- if (!this.isStopped && this._next) {
- var _parentSubscriber = this._parentSubscriber;
- if (!config_1.config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
- this.__tryOrUnsub(this._next, value);
- }
- else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) {
- this.unsubscribe();
- }
- }
- };
- SafeSubscriber.prototype.error = function (err) {
- if (!this.isStopped) {
- var _parentSubscriber = this._parentSubscriber;
- var useDeprecatedSynchronousErrorHandling = config_1.config.useDeprecatedSynchronousErrorHandling;
- if (this._error) {
- if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
- this.__tryOrUnsub(this._error, err);
- this.unsubscribe();
- }
- else {
- this.__tryOrSetError(_parentSubscriber, this._error, err);
- this.unsubscribe();
- }
- }
- else if (!_parentSubscriber.syncErrorThrowable) {
- this.unsubscribe();
- if (useDeprecatedSynchronousErrorHandling) {
- throw err;
- }
- hostReportError_1.hostReportError(err);
- }
- else {
- if (useDeprecatedSynchronousErrorHandling) {
- _parentSubscriber.syncErrorValue = err;
- _parentSubscriber.syncErrorThrown = true;
- }
- else {
- hostReportError_1.hostReportError(err);
- }
- this.unsubscribe();
- }
- }
- };
- SafeSubscriber.prototype.complete = function () {
- var _this = this;
- if (!this.isStopped) {
- var _parentSubscriber = this._parentSubscriber;
- if (this._complete) {
- var wrappedComplete = function () { return _this._complete.call(_this._context); };
- if (!config_1.config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
- this.__tryOrUnsub(wrappedComplete);
- this.unsubscribe();
- }
- else {
- this.__tryOrSetError(_parentSubscriber, wrappedComplete);
- this.unsubscribe();
- }
- }
- else {
- this.unsubscribe();
- }
- }
- };
- SafeSubscriber.prototype.__tryOrUnsub = function (fn, value) {
- try {
- fn.call(this._context, value);
- }
- catch (err) {
- this.unsubscribe();
- if (config_1.config.useDeprecatedSynchronousErrorHandling) {
- throw err;
- }
- else {
- hostReportError_1.hostReportError(err);
- }
- }
- };
- SafeSubscriber.prototype.__tryOrSetError = function (parent, fn, value) {
- if (!config_1.config.useDeprecatedSynchronousErrorHandling) {
- throw new Error('bad call');
- }
- try {
- fn.call(this._context, value);
- }
- catch (err) {
- if (config_1.config.useDeprecatedSynchronousErrorHandling) {
- parent.syncErrorValue = err;
- parent.syncErrorThrown = true;
- return true;
- }
- else {
- hostReportError_1.hostReportError(err);
- return true;
- }
- }
- return false;
- };
- SafeSubscriber.prototype._unsubscribe = function () {
- var _parentSubscriber = this._parentSubscriber;
- this._context = null;
- this._parentSubscriber = null;
- _parentSubscriber.unsubscribe();
- };
- return SafeSubscriber;
- }(Subscriber));
- exports.SafeSubscriber = SafeSubscriber;
- //# sourceMappingURL=Subscriber.js.map
|