source: trip-planner-front/node_modules/rxjs/_esm2015/internal/Subject.js@ fa375fe

Last change on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 4.0 KB
Line 
1import { Observable } from './Observable';
2import { Subscriber } from './Subscriber';
3import { Subscription } from './Subscription';
4import { ObjectUnsubscribedError } from './util/ObjectUnsubscribedError';
5import { SubjectSubscription } from './SubjectSubscription';
6import { rxSubscriber as rxSubscriberSymbol } from '../internal/symbol/rxSubscriber';
7export class SubjectSubscriber extends Subscriber {
8 constructor(destination) {
9 super(destination);
10 this.destination = destination;
11 }
12}
13export class Subject extends Observable {
14 constructor() {
15 super();
16 this.observers = [];
17 this.closed = false;
18 this.isStopped = false;
19 this.hasError = false;
20 this.thrownError = null;
21 }
22 [rxSubscriberSymbol]() {
23 return new SubjectSubscriber(this);
24 }
25 lift(operator) {
26 const subject = new AnonymousSubject(this, this);
27 subject.operator = operator;
28 return subject;
29 }
30 next(value) {
31 if (this.closed) {
32 throw new ObjectUnsubscribedError();
33 }
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++) {
39 copy[i].next(value);
40 }
41 }
42 }
43 error(err) {
44 if (this.closed) {
45 throw new ObjectUnsubscribedError();
46 }
47 this.hasError = true;
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++) {
54 copy[i].error(err);
55 }
56 this.observers.length = 0;
57 }
58 complete() {
59 if (this.closed) {
60 throw new ObjectUnsubscribedError();
61 }
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++) {
67 copy[i].complete();
68 }
69 this.observers.length = 0;
70 }
71 unsubscribe() {
72 this.isStopped = true;
73 this.closed = true;
74 this.observers = null;
75 }
76 _trySubscribe(subscriber) {
77 if (this.closed) {
78 throw new ObjectUnsubscribedError();
79 }
80 else {
81 return super._trySubscribe(subscriber);
82 }
83 }
84 _subscribe(subscriber) {
85 if (this.closed) {
86 throw new ObjectUnsubscribedError();
87 }
88 else if (this.hasError) {
89 subscriber.error(this.thrownError);
90 return Subscription.EMPTY;
91 }
92 else if (this.isStopped) {
93 subscriber.complete();
94 return Subscription.EMPTY;
95 }
96 else {
97 this.observers.push(subscriber);
98 return new SubjectSubscription(this, subscriber);
99 }
100 }
101 asObservable() {
102 const observable = new Observable();
103 observable.source = this;
104 return observable;
105 }
106}
107Subject.create = (destination, source) => {
108 return new AnonymousSubject(destination, source);
109};
110export class AnonymousSubject extends Subject {
111 constructor(destination, source) {
112 super();
113 this.destination = destination;
114 this.source = source;
115 }
116 next(value) {
117 const { destination } = this;
118 if (destination && destination.next) {
119 destination.next(value);
120 }
121 }
122 error(err) {
123 const { destination } = this;
124 if (destination && destination.error) {
125 this.destination.error(err);
126 }
127 }
128 complete() {
129 const { destination } = this;
130 if (destination && destination.complete) {
131 this.destination.complete();
132 }
133 }
134 _subscribe(subscriber) {
135 const { source } = this;
136 if (source) {
137 return this.source.subscribe(subscriber);
138 }
139 else {
140 return Subscription.EMPTY;
141 }
142 }
143}
144//# sourceMappingURL=Subject.js.map
Note: See TracBrowser for help on using the repository browser.