1 /** PURE_IMPORTS_START tslib,_util_isFunction,_Observer,_Subscription,_internal_symbol_rxSubscriber,_config,_util_hostReportError PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { isFunction } from './util/isFunction';
4 import { empty as emptyObserver } from './Observer';
5 import { Subscription } from './Subscription';
6 import { rxSubscriber as rxSubscriberSymbol } from '../internal/symbol/rxSubscriber';
7 import { config } from './config';
8 import { hostReportError } from './util/hostReportError';
9 var Subscriber = /*@__PURE__*/ (function (_super) {
10 tslib_1.__extends(Subscriber, _super);
11 function Subscriber(destinationOrNext, error, complete) {
12 var _this = _super.call(this) || this;
13 _this.syncErrorValue = null;
14 _this.syncErrorThrown = false;
15 _this.syncErrorThrowable = false;
16 _this.isStopped = false;
17 switch (arguments.length) {
19 _this.destination = emptyObserver;
22 if (!destinationOrNext) {
23 _this.destination = emptyObserver;
26 if (typeof destinationOrNext === 'object') {
27 if (destinationOrNext instanceof Subscriber) {
28 _this.syncErrorThrowable = destinationOrNext.syncErrorThrowable;
29 _this.destination = destinationOrNext;
30 destinationOrNext.add(_this);
33 _this.syncErrorThrowable = true;
34 _this.destination = new SafeSubscriber(_this, destinationOrNext);
39 _this.syncErrorThrowable = true;
40 _this.destination = new SafeSubscriber(_this, destinationOrNext, error, complete);
45 Subscriber.prototype[rxSubscriberSymbol] = function () { return this; };
46 Subscriber.create = function (next, error, complete) {
47 var subscriber = new Subscriber(next, error, complete);
48 subscriber.syncErrorThrowable = false;
51 Subscriber.prototype.next = function (value) {
52 if (!this.isStopped) {
56 Subscriber.prototype.error = function (err) {
57 if (!this.isStopped) {
58 this.isStopped = true;
62 Subscriber.prototype.complete = function () {
63 if (!this.isStopped) {
64 this.isStopped = true;
68 Subscriber.prototype.unsubscribe = function () {
72 this.isStopped = true;
73 _super.prototype.unsubscribe.call(this);
75 Subscriber.prototype._next = function (value) {
76 this.destination.next(value);
78 Subscriber.prototype._error = function (err) {
79 this.destination.error(err);
82 Subscriber.prototype._complete = function () {
83 this.destination.complete();
86 Subscriber.prototype._unsubscribeAndRecycle = function () {
87 var _parentOrParents = this._parentOrParents;
88 this._parentOrParents = null;
91 this.isStopped = false;
92 this._parentOrParents = _parentOrParents;
97 export { Subscriber };
98 var SafeSubscriber = /*@__PURE__*/ (function (_super) {
99 tslib_1.__extends(SafeSubscriber, _super);
100 function SafeSubscriber(_parentSubscriber, observerOrNext, error, complete) {
101 var _this = _super.call(this) || this;
102 _this._parentSubscriber = _parentSubscriber;
105 if (isFunction(observerOrNext)) {
106 next = observerOrNext;
108 else if (observerOrNext) {
109 next = observerOrNext.next;
110 error = observerOrNext.error;
111 complete = observerOrNext.complete;
112 if (observerOrNext !== emptyObserver) {
113 context = Object.create(observerOrNext);
114 if (isFunction(context.unsubscribe)) {
115 _this.add(context.unsubscribe.bind(context));
117 context.unsubscribe = _this.unsubscribe.bind(_this);
120 _this._context = context;
122 _this._error = error;
123 _this._complete = complete;
126 SafeSubscriber.prototype.next = function (value) {
127 if (!this.isStopped && this._next) {
128 var _parentSubscriber = this._parentSubscriber;
129 if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
130 this.__tryOrUnsub(this._next, value);
132 else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) {
137 SafeSubscriber.prototype.error = function (err) {
138 if (!this.isStopped) {
139 var _parentSubscriber = this._parentSubscriber;
140 var useDeprecatedSynchronousErrorHandling = config.useDeprecatedSynchronousErrorHandling;
142 if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
143 this.__tryOrUnsub(this._error, err);
147 this.__tryOrSetError(_parentSubscriber, this._error, err);
151 else if (!_parentSubscriber.syncErrorThrowable) {
153 if (useDeprecatedSynchronousErrorHandling) {
156 hostReportError(err);
159 if (useDeprecatedSynchronousErrorHandling) {
160 _parentSubscriber.syncErrorValue = err;
161 _parentSubscriber.syncErrorThrown = true;
164 hostReportError(err);
170 SafeSubscriber.prototype.complete = function () {
172 if (!this.isStopped) {
173 var _parentSubscriber = this._parentSubscriber;
174 if (this._complete) {
175 var wrappedComplete = function () { return _this._complete.call(_this._context); };
176 if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
177 this.__tryOrUnsub(wrappedComplete);
181 this.__tryOrSetError(_parentSubscriber, wrappedComplete);
190 SafeSubscriber.prototype.__tryOrUnsub = function (fn, value) {
192 fn.call(this._context, value);
196 if (config.useDeprecatedSynchronousErrorHandling) {
200 hostReportError(err);
204 SafeSubscriber.prototype.__tryOrSetError = function (parent, fn, value) {
205 if (!config.useDeprecatedSynchronousErrorHandling) {
206 throw new Error('bad call');
209 fn.call(this._context, value);
212 if (config.useDeprecatedSynchronousErrorHandling) {
213 parent.syncErrorValue = err;
214 parent.syncErrorThrown = true;
218 hostReportError(err);
224 SafeSubscriber.prototype._unsubscribe = function () {
225 var _parentSubscriber = this._parentSubscriber;
226 this._context = null;
227 this._parentSubscriber = null;
228 _parentSubscriber.unsubscribe();
230 return SafeSubscriber;
232 export { SafeSubscriber };
233 //# sourceMappingURL=Subscriber.js.map