1 /** PURE_IMPORTS_START tslib,_Observable,_Subscriber,_Subscription,_util_ObjectUnsubscribedError,_SubjectSubscription,_internal_symbol_rxSubscriber PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { Observable } from './Observable';
4 import { Subscriber } from './Subscriber';
5 import { Subscription } from './Subscription';
6 import { ObjectUnsubscribedError } from './util/ObjectUnsubscribedError';
7 import { SubjectSubscription } from './SubjectSubscription';
8 import { rxSubscriber as rxSubscriberSymbol } from '../internal/symbol/rxSubscriber';
9 var SubjectSubscriber = /*@__PURE__*/ (function (_super) {
10 tslib_1.__extends(SubjectSubscriber, _super);
11 function SubjectSubscriber(destination) {
12 var _this = _super.call(this, destination) || this;
13 _this.destination = destination;
16 return SubjectSubscriber;
18 export { SubjectSubscriber };
19 var Subject = /*@__PURE__*/ (function (_super) {
20 tslib_1.__extends(Subject, _super);
22 var _this = _super.call(this) || this;
25 _this.isStopped = false;
26 _this.hasError = false;
27 _this.thrownError = null;
30 Subject.prototype[rxSubscriberSymbol] = function () {
31 return new SubjectSubscriber(this);
33 Subject.prototype.lift = function (operator) {
34 var subject = new AnonymousSubject(this, this);
35 subject.operator = operator;
38 Subject.prototype.next = function (value) {
40 throw new ObjectUnsubscribedError();
42 if (!this.isStopped) {
43 var observers = this.observers;
44 var len = observers.length;
45 var copy = observers.slice();
46 for (var i = 0; i < len; i++) {
51 Subject.prototype.error = function (err) {
53 throw new ObjectUnsubscribedError();
56 this.thrownError = err;
57 this.isStopped = true;
58 var observers = this.observers;
59 var len = observers.length;
60 var copy = observers.slice();
61 for (var i = 0; i < len; i++) {
64 this.observers.length = 0;
66 Subject.prototype.complete = function () {
68 throw new ObjectUnsubscribedError();
70 this.isStopped = true;
71 var observers = this.observers;
72 var len = observers.length;
73 var copy = observers.slice();
74 for (var i = 0; i < len; i++) {
77 this.observers.length = 0;
79 Subject.prototype.unsubscribe = function () {
80 this.isStopped = true;
82 this.observers = null;
84 Subject.prototype._trySubscribe = function (subscriber) {
86 throw new ObjectUnsubscribedError();
89 return _super.prototype._trySubscribe.call(this, subscriber);
92 Subject.prototype._subscribe = function (subscriber) {
94 throw new ObjectUnsubscribedError();
96 else if (this.hasError) {
97 subscriber.error(this.thrownError);
98 return Subscription.EMPTY;
100 else if (this.isStopped) {
101 subscriber.complete();
102 return Subscription.EMPTY;
105 this.observers.push(subscriber);
106 return new SubjectSubscription(this, subscriber);
109 Subject.prototype.asObservable = function () {
110 var observable = new Observable();
111 observable.source = this;
114 Subject.create = function (destination, source) {
115 return new AnonymousSubject(destination, source);
120 var AnonymousSubject = /*@__PURE__*/ (function (_super) {
121 tslib_1.__extends(AnonymousSubject, _super);
122 function AnonymousSubject(destination, source) {
123 var _this = _super.call(this) || this;
124 _this.destination = destination;
125 _this.source = source;
128 AnonymousSubject.prototype.next = function (value) {
129 var destination = this.destination;
130 if (destination && destination.next) {
131 destination.next(value);
134 AnonymousSubject.prototype.error = function (err) {
135 var destination = this.destination;
136 if (destination && destination.error) {
137 this.destination.error(err);
140 AnonymousSubject.prototype.complete = function () {
141 var destination = this.destination;
142 if (destination && destination.complete) {
143 this.destination.complete();
146 AnonymousSubject.prototype._subscribe = function (subscriber) {
147 var source = this.source;
149 return this.source.subscribe(subscriber);
152 return Subscription.EMPTY;
155 return AnonymousSubject;
157 export { AnonymousSubject };
158 //# sourceMappingURL=Subject.js.map