diff --git a/src/Subject.ts b/src/Subject.ts index 8c628e7bb4..a8c5626ab5 100644 --- a/src/Subject.ts +++ b/src/Subject.ts @@ -25,7 +25,7 @@ export default class Subject extends Observable implements Observer, Su return new BidirectionalSubject(source, destination); } - destination: Observer; + protected destination: Observer; observers: Observer[] = []; isUnsubscribed: boolean = false; @@ -41,8 +41,7 @@ export default class Subject extends Observable implements Observer, Su return subject; } - _subscribe(subscriber: Subscriber) : Subscription { - + _subscribe(subscriber: Subscriber): Subscription { if (subscriber.isUnsubscribed) { return; } else if (this.errorSignal) { @@ -73,8 +72,7 @@ export default class Subject extends Observable implements Observer, Su subscriptionUnsubscribe.call(this); } - next(value) { - + next(value: T): void { if (this.isUnsubscribed) { return; } @@ -90,25 +88,23 @@ export default class Subject extends Observable implements Observer, Su } } - error(error) { - + error(err?: any): void { if (this.isUnsubscribed || this.completeSignal) { return; } this.errorSignal = true; - this.errorInstance = error; + this.errorInstance = err; if (this.dispatching) { return; } - this._error(error); + this._error(err); this.unsubscribe(); } - complete() { - + complete(): void { if (this.isUnsubscribed || this.errorSignal) { return; } @@ -124,7 +120,7 @@ export default class Subject extends Observable implements Observer, Su } - _next(value?) { + _next(value: T): void { let index = -1; const observers = this.observers.slice(0); const len = observers.length; @@ -134,7 +130,7 @@ export default class Subject extends Observable implements Observer, Su } } - _error(error?) { + _error(err: any): void{ let index = -1; const observers = this.observers; const len = observers.length; @@ -144,13 +140,13 @@ export default class Subject extends Observable implements Observer, Su this.isUnsubscribed = true; while(++index < len) { - observers[index].error(error); + observers[index].error(err); } this.isUnsubscribed = false; } - _complete() { + _complete(): void{ let index = -1; const observers = this.observers; const len = observers.length; @@ -168,39 +164,36 @@ export default class Subject extends Observable implements Observer, Su } class BidirectionalSubject extends Subject { - - constructor(source: Observable, destination: Observer) { + constructor(public source: Observable, protected destination: Observer) { super(); - this.source = source; - this.destination = destination; } - _subscribe(subscriber: Subscriber) { + _subscribe(subscriber: Subscriber): Subscription { const operator = this.operator; return this.source._subscribe.call(this.source, operator ? operator.call(subscriber) : subscriber); } - next(x) { - subscriberNext.call(this, x); + next(value?: T): void { + subscriberNext.call(this, value); } - error(e) { - subscriberError.call(this, e); + error(err?: any): void { + subscriberError.call(this, err); } - complete() { + complete(): void { subscriberComplete.call(this); } - _next(x) { - _subscriberNext.call(this, x); + _next(value: T): void { + _subscriberNext.call(this, value); } - _error(e) { - _subscriberError.call(this, e); + _error(err: any): void { + _subscriberError.call(this, err); } - _complete() { + _complete(): void { _subscriberComplete.call(this); } } \ No newline at end of file diff --git a/src/Subscriber.ts b/src/Subscriber.ts index 68a50d8add..086afd2e7b 100644 --- a/src/Subscriber.ts +++ b/src/Subscriber.ts @@ -100,9 +100,9 @@ export default class Subscriber extends Subscription implements Observer extends Observable> { super(); } - _subscribe(subscriber) { + _subscribe(subscriber: Subscriber): Subscription | Function | void { const refCountSubscription = new RefCountSubscription(); const groupBySubscriber = new GroupBySubscriber( subscriber, refCountSubscription, this.keySelector, this.elementSelector, this.durationSelector @@ -45,7 +46,7 @@ class GroupBySubscriber extends Subscriber { this.add(destination); } - _next(x: T) { + _next(x: T): void { let key = tryCatch(this.keySelector)(x); if (key === errorObject) { this.error(key.e); @@ -58,7 +59,7 @@ class GroupBySubscriber extends Subscriber { groups = this.groups = typeof key === 'string' ? new FastMap() : new Map(); } - let group: Subject = groups.get(key); + let group: Subject = groups.get(key); if (!group) { groups.set(key, group = new Subject()); @@ -89,7 +90,7 @@ class GroupBySubscriber extends Subscriber { } } - _error(err: any) { + _error(err: any): void { const groups = this.groups; if (groups) { groups.forEach((group, key) => { @@ -100,7 +101,7 @@ class GroupBySubscriber extends Subscriber { this.destination.error(err); } - _complete() { + _complete(): void { const groups = this.groups; if (groups) { groups.forEach((group, key) => { @@ -111,7 +112,7 @@ class GroupBySubscriber extends Subscriber { this.destination.complete(); } - removeGroup(key: string) { + removeGroup(key: string): void { this.groups.delete(key); } } @@ -123,17 +124,17 @@ class GroupDurationSubscriber extends Subscriber { super(null); } - _next(value: T) { + _next(value: T): void { this.group.complete(); this.parent.removeGroup(this.key); } - _error(err: any) { + _error(err: any): void { this.group.error(err); this.parent.removeGroup(this.key); } - _complete() { + _complete(): void { this.group.complete(); this.parent.removeGroup(this.key); } diff --git a/src/subjects/BehaviorSubject.ts b/src/subjects/BehaviorSubject.ts index b69fe7a141..60a4202f40 100644 --- a/src/subjects/BehaviorSubject.ts +++ b/src/subjects/BehaviorSubject.ts @@ -3,7 +3,7 @@ import Subscriber from '../Subscriber'; import Subscription from '../Subscription'; export default class BehaviorSubject extends Subject { - constructor(public value: any) { + constructor(private value: any) { super(); } @@ -17,7 +17,7 @@ export default class BehaviorSubject extends Subject { return subscription; } - _next(value?) { + _next(value: T): void { super._next(this.value = value); } } \ No newline at end of file diff --git a/src/subjects/ReplaySubject.ts b/src/subjects/ReplaySubject.ts index 9ce6cac7f1..875998b662 100644 --- a/src/subjects/ReplaySubject.ts +++ b/src/subjects/ReplaySubject.ts @@ -8,7 +8,7 @@ export default class ReplaySubject extends Subject { private bufferSize: number; private _windowTime: number; private scheduler: Scheduler; - private events: ReplayEvent [] = []; + private events: ReplayEvent[] = []; constructor(bufferSize: number = Number.POSITIVE_INFINITY, _windowTime: number = Number.POSITIVE_INFINITY, @@ -19,7 +19,7 @@ export default class ReplaySubject extends Subject { this.scheduler = scheduler; } - _next(value?) { + _next(value: T): void { const now = this._getNow(); this.events.push(new ReplayEvent(now, value)); super._next(value); @@ -35,12 +35,11 @@ export default class ReplaySubject extends Subject { return super._subscribe(subscriber); } - private _getNow() { + private _getNow(): number { return (this.scheduler || immediate).now(); } - private _getEvents(now) { - + private _getEvents(now): ReplayEvent[] { const bufferSize = this.bufferSize; const _windowTime = this._windowTime; const events = this.events; @@ -71,13 +70,7 @@ export default class ReplaySubject extends Subject { } class ReplayEvent { - - time: number; - value: T; - - constructor(time: number, value: T) { - this.time = time; - this.value = value; + constructor(public time: number, public value: T) { } }