import { Observable } from './Observable'; import { Subscriber } from './Subscriber'; import { Subscription } from './Subscription'; import { ObjectUnsubscribedError } from './util/ObjectUnsubscribedError'; import { SubjectSubscription } from './SubjectSubscription'; import { rxSubscriber as rxSubscriberSymbol } from '../internal/symbol/rxSubscriber'; export class SubjectSubscriber extends Subscriber { constructor(destination) { super(destination); this.destination = destination; } } export class Subject extends Observable { constructor() { super(); this.observers = []; this.closed = false; this.isStopped = false; this.hasError = false; this.thrownError = null; } [rxSubscriberSymbol]() { return new SubjectSubscriber(this); } lift(operator) { const subject = new AnonymousSubject(this, this); subject.operator = operator; return subject; } next(value) { if (this.closed) { throw new ObjectUnsubscribedError(); } if (!this.isStopped) { const { observers } = this; const len = observers.length; const copy = observers.slice(); for (let i = 0; i < len; i++) { copy[i].next(value); } } } error(err) { if (this.closed) { throw new ObjectUnsubscribedError(); } this.hasError = true; this.thrownError = err; this.isStopped = true; const { observers } = this; const len = observers.length; const copy = observers.slice(); for (let i = 0; i < len; i++) { copy[i].error(err); } this.observers.length = 0; } complete() { if (this.closed) { throw new ObjectUnsubscribedError(); } this.isStopped = true; const { observers } = this; const len = observers.length; const copy = observers.slice(); for (let i = 0; i < len; i++) { copy[i].complete(); } this.observers.length = 0; } unsubscribe() { this.isStopped = true; this.closed = true; this.observers = null; } _trySubscribe(subscriber) { if (this.closed) { throw new ObjectUnsubscribedError(); } else { return super._trySubscribe(subscriber); } } _subscribe(subscriber) { if (this.closed) { throw new ObjectUnsubscribedError(); } else if (this.hasError) { subscriber.error(this.thrownError); return Subscription.EMPTY; } else if (this.isStopped) { subscriber.complete(); return Subscription.EMPTY; } else { this.observers.push(subscriber); return new SubjectSubscription(this, subscriber); } } asObservable() { const observable = new Observable(); observable.source = this; return observable; } } Subject.create = (destination, source) => { return new AnonymousSubject(destination, source); }; export class AnonymousSubject extends Subject { constructor(destination, source) { super(); this.destination = destination; this.source = source; } next(value) { const { destination } = this; if (destination && destination.next) { destination.next(value); } } error(err) { const { destination } = this; if (destination && destination.error) { this.destination.error(err); } } complete() { const { destination } = this; if (destination && destination.complete) { this.destination.complete(); } } _subscribe(subscriber) { const { source } = this; if (source) { return this.source.subscribe(subscriber); } else { return Subscription.EMPTY; } } } //# sourceMappingURL=Subject.js.map
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
observable | Folder | 0755 |
|
|
operators | Folder | 0755 |
|
|
scheduled | Folder | 0755 |
|
|
scheduler | Folder | 0755 |
|
|
symbol | Folder | 0755 |
|
|
testing | Folder | 0755 |
|
|
util | Folder | 0755 |
|
|
AsyncSubject.js | File | 1.07 KB | 0644 |
|
AsyncSubject.js.map | File | 1.1 KB | 0644 |
|
BehaviorSubject.js | File | 876 B | 0644 |
|
BehaviorSubject.js.map | File | 875 B | 0644 |
|
InnerSubscriber.js | File | 653 B | 0644 |
|
InnerSubscriber.js.map | File | 751 B | 0644 |
|
Notification.js | File | 2.31 KB | 0644 |
|
Notification.js.map | File | 2.13 KB | 0644 |
|
Observable.js | File | 3.23 KB | 0644 |
|
Observable.js.map | File | 3.05 KB | 0644 |
|
Observer.js | File | 389 B | 0644 |
|
Observer.js.map | File | 433 B | 0644 |
|
Operator.js | File | 36 B | 0644 |
|
Operator.js.map | File | 105 B | 0644 |
|
OuterSubscriber.js | File | 416 B | 0644 |
|
OuterSubscriber.js.map | File | 489 B | 0644 |
|
ReplaySubject.js | File | 3.57 KB | 0644 |
|
ReplaySubject.js.map | File | 3.44 KB | 0644 |
|
Rx.js | File | 7.4 KB | 0644 |
|
Rx.js.map | File | 4.45 KB | 0644 |
|
Scheduler.js | File | 353 B | 0644 |
|
Scheduler.js.map | File | 459 B | 0644 |
|
Subject.js | File | 4.03 KB | 0644 |
|
Subject.js.map | File | 3.94 KB | 0644 |
|
SubjectSubscription.js | File | 823 B | 0644 |
|
SubjectSubscription.js.map | File | 831 B | 0644 |
|
Subscriber.js | File | 7.2 KB | 0644 |
|
Subscriber.js.map | File | 5.95 KB | 0644 |
|
Subscription.js | File | 4.68 KB | 0644 |
|
Subscription.js.map | File | 3.84 KB | 0644 |
|
config.js | File | 776 B | 0644 |
|
config.js.map | File | 513 B | 0644 |
|
innerSubscribe.js | File | 1.91 KB | 0644 |
|
innerSubscribe.js.map | File | 1.94 KB | 0644 |
|
types.js | File | 33 B | 0644 |
|
types.js.map | File | 99 B | 0644 |
|