1 import { Observable } from './Observable';
2 import { Subscriber } from './Subscriber';
3 import { Subscription } from './Subscription';
4 import { ObjectUnsubscribedError } from './util/ObjectUnsubscribedError';
5 import { SubjectSubscription } from './SubjectSubscription';
6 import { rxSubscriber as rxSubscriberSymbol } from '../internal/symbol/rxSubscriber';
7 export class SubjectSubscriber extends Subscriber {
8 constructor(destination) {
10 this.destination = destination;
13 export class Subject extends Observable {
18 this.isStopped = false;
19 this.hasError = false;
20 this.thrownError = null;
22 [rxSubscriberSymbol]() {
23 return new SubjectSubscriber(this);
26 const subject = new AnonymousSubject(this, this);
27 subject.operator = operator;
32 throw new ObjectUnsubscribedError();
34 if (!this.isStopped) {
35 const { observers } = this;
36 const len = observers.length;
37 const copy = observers.slice();
38 for (let i = 0; i < len; i++) {
45 throw new ObjectUnsubscribedError();
48 this.thrownError = err;
49 this.isStopped = true;
50 const { observers } = this;
51 const len = observers.length;
52 const copy = observers.slice();
53 for (let i = 0; i < len; i++) {
56 this.observers.length = 0;
60 throw new ObjectUnsubscribedError();
62 this.isStopped = true;
63 const { observers } = this;
64 const len = observers.length;
65 const copy = observers.slice();
66 for (let i = 0; i < len; i++) {
69 this.observers.length = 0;
72 this.isStopped = true;
74 this.observers = null;
76 _trySubscribe(subscriber) {
78 throw new ObjectUnsubscribedError();
81 return super._trySubscribe(subscriber);
84 _subscribe(subscriber) {
86 throw new ObjectUnsubscribedError();
88 else if (this.hasError) {
89 subscriber.error(this.thrownError);
90 return Subscription.EMPTY;
92 else if (this.isStopped) {
93 subscriber.complete();
94 return Subscription.EMPTY;
97 this.observers.push(subscriber);
98 return new SubjectSubscription(this, subscriber);
102 const observable = new Observable();
103 observable.source = this;
107 Subject.create = (destination, source) => {
108 return new AnonymousSubject(destination, source);
110 export class AnonymousSubject extends Subject {
111 constructor(destination, source) {
113 this.destination = destination;
114 this.source = source;
117 const { destination } = this;
118 if (destination && destination.next) {
119 destination.next(value);
123 const { destination } = this;
124 if (destination && destination.error) {
125 this.destination.error(err);
129 const { destination } = this;
130 if (destination && destination.complete) {
131 this.destination.complete();
134 _subscribe(subscriber) {
135 const { source } = this;
137 return this.source.subscribe(subscriber);
140 return Subscription.EMPTY;
144 //# sourceMappingURL=Subject.js.map