2 var __extends = (this && this.__extends) || (function () {
3 var extendStatics = function (d, b) {
4 extendStatics = Object.setPrototypeOf ||
5 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7 return extendStatics(d, b);
9 return function (d, b) {
11 function __() { this.constructor = d; }
12 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15 Object.defineProperty(exports, "__esModule", { value: true });
16 var Observable_1 = require("./Observable");
17 var Subscriber_1 = require("./Subscriber");
18 var Subscription_1 = require("./Subscription");
19 var ObjectUnsubscribedError_1 = require("./util/ObjectUnsubscribedError");
20 var SubjectSubscription_1 = require("./SubjectSubscription");
21 var rxSubscriber_1 = require("../internal/symbol/rxSubscriber");
22 var SubjectSubscriber = (function (_super) {
23 __extends(SubjectSubscriber, _super);
24 function SubjectSubscriber(destination) {
25 var _this = _super.call(this, destination) || this;
26 _this.destination = destination;
29 return SubjectSubscriber;
30 }(Subscriber_1.Subscriber));
31 exports.SubjectSubscriber = SubjectSubscriber;
32 var Subject = (function (_super) {
33 __extends(Subject, _super);
35 var _this = _super.call(this) || this;
38 _this.isStopped = false;
39 _this.hasError = false;
40 _this.thrownError = null;
43 Subject.prototype[rxSubscriber_1.rxSubscriber] = function () {
44 return new SubjectSubscriber(this);
46 Subject.prototype.lift = function (operator) {
47 var subject = new AnonymousSubject(this, this);
48 subject.operator = operator;
51 Subject.prototype.next = function (value) {
53 throw new ObjectUnsubscribedError_1.ObjectUnsubscribedError();
55 if (!this.isStopped) {
56 var observers = this.observers;
57 var len = observers.length;
58 var copy = observers.slice();
59 for (var i = 0; i < len; i++) {
64 Subject.prototype.error = function (err) {
66 throw new ObjectUnsubscribedError_1.ObjectUnsubscribedError();
69 this.thrownError = err;
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.complete = function () {
81 throw new ObjectUnsubscribedError_1.ObjectUnsubscribedError();
83 this.isStopped = true;
84 var observers = this.observers;
85 var len = observers.length;
86 var copy = observers.slice();
87 for (var i = 0; i < len; i++) {
90 this.observers.length = 0;
92 Subject.prototype.unsubscribe = function () {
93 this.isStopped = true;
95 this.observers = null;
97 Subject.prototype._trySubscribe = function (subscriber) {
99 throw new ObjectUnsubscribedError_1.ObjectUnsubscribedError();
102 return _super.prototype._trySubscribe.call(this, subscriber);
105 Subject.prototype._subscribe = function (subscriber) {
107 throw new ObjectUnsubscribedError_1.ObjectUnsubscribedError();
109 else if (this.hasError) {
110 subscriber.error(this.thrownError);
111 return Subscription_1.Subscription.EMPTY;
113 else if (this.isStopped) {
114 subscriber.complete();
115 return Subscription_1.Subscription.EMPTY;
118 this.observers.push(subscriber);
119 return new SubjectSubscription_1.SubjectSubscription(this, subscriber);
122 Subject.prototype.asObservable = function () {
123 var observable = new Observable_1.Observable();
124 observable.source = this;
127 Subject.create = function (destination, source) {
128 return new AnonymousSubject(destination, source);
131 }(Observable_1.Observable));
132 exports.Subject = Subject;
133 var AnonymousSubject = (function (_super) {
134 __extends(AnonymousSubject, _super);
135 function AnonymousSubject(destination, source) {
136 var _this = _super.call(this) || this;
137 _this.destination = destination;
138 _this.source = source;
141 AnonymousSubject.prototype.next = function (value) {
142 var destination = this.destination;
143 if (destination && destination.next) {
144 destination.next(value);
147 AnonymousSubject.prototype.error = function (err) {
148 var destination = this.destination;
149 if (destination && destination.error) {
150 this.destination.error(err);
153 AnonymousSubject.prototype.complete = function () {
154 var destination = this.destination;
155 if (destination && destination.complete) {
156 this.destination.complete();
159 AnonymousSubject.prototype._subscribe = function (subscriber) {
160 var source = this.source;
162 return this.source.subscribe(subscriber);
165 return Subscription_1.Subscription.EMPTY;
168 return AnonymousSubject;
170 exports.AnonymousSubject = AnonymousSubject;
171 //# sourceMappingURL=Subject.js.map