Skip to content

Commit

Permalink
Merge pull request #1823 from kwonoj/type-call
Browse files Browse the repository at this point in the history
refactor(Operator): update explicit return type to call()
  • Loading branch information
jayphelps authored Jul 12, 2016
2 parents 98cb567 + c9af224 commit 4f65b03
Show file tree
Hide file tree
Showing 35 changed files with 70 additions and 51 deletions.
3 changes: 2 additions & 1 deletion spec/Observable-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {expect} from 'chai';
import * as Rx from '../dist/cjs/Rx';
import {TeardownLogic} from '../dist/cjs/Subscription';

declare const {asDiagram, expectObservable};
const Subscriber = Rx.Subscriber;
Expand Down Expand Up @@ -575,7 +576,7 @@ describe('Observable.lift', () => {
super();
}

call(subscriber: Rx.Subscriber<R>, source: any): Rx.Subscription | Function | void {
call(subscriber: Rx.Subscriber<R>, source: any): TeardownLogic {
return this.childOperator.call(new LogSubscriber<R>(subscriber), source);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Operator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {Subscriber} from './Subscriber';
import {TeardownLogic} from './Subscription';

export class Operator<T, R> {
call(subscriber: Subscriber<R>, source: any): any {
call(subscriber: Subscriber<R>, source: any): TeardownLogic {
return source._subscribe(new Subscriber<T>(subscriber));
}
}
4 changes: 2 additions & 2 deletions src/observable/ConnectableObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Subject, SubjectSubscriber} from '../Subject';
import {Operator} from '../Operator';
import {Observable} from '../Observable';
import {Subscriber} from '../Subscriber';
import {Subscription} from '../Subscription';
import {Subscription, TeardownLogic} from '../Subscription';

/**
* @class ConnectableObservable<T>
Expand Down Expand Up @@ -82,7 +82,7 @@ class ConnectableSubscriber<T> extends SubjectSubscriber<T> {
class RefCountOperator<T> implements Operator<T, T> {
constructor(private connectable: ConnectableObservable<T>) {
}
call(subscriber: Subscriber<T>, source: any): any {
call(subscriber: Subscriber<T>, source: any): TeardownLogic {

const { connectable } = this;
(<any> connectable)._refCount++;
Expand Down
4 changes: 2 additions & 2 deletions src/operator/audit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';
import {Observable, SubscribableOrPromise} from '../Observable';
import {Subscription} from '../Subscription';
import {Subscription, TeardownLogic} from '../Subscription';

import {tryCatch} from '../util/tryCatch';
import {errorObject} from '../util/errorObject';
Expand Down Expand Up @@ -60,7 +60,7 @@ class AuditOperator<T> implements Operator<T, T> {
constructor(private durationSelector: (value: T) => SubscribableOrPromise<any>) {
}

call(subscriber: Subscriber<T>, source: any): any {
call(subscriber: Subscriber<T>, source: any): TeardownLogic {
return source._subscribe(new AuditSubscriber<T, T>(subscriber, this.durationSelector));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/operator/auditTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Operator} from '../Operator';
import {Scheduler} from '../Scheduler';
import {Subscriber} from '../Subscriber';
import {Observable} from '../Observable';
import {Subscription} from '../Subscription';
import {Subscription, TeardownLogic} from '../Subscription';

/**
* Ignores source values for `duration` milliseconds, then emits the most recent
Expand Down Expand Up @@ -60,7 +60,7 @@ class AuditTimeOperator<T> implements Operator<T, T> {
private scheduler: Scheduler) {
}

call(subscriber: Subscriber<T>, source: any): any {
call(subscriber: Subscriber<T>, source: any): TeardownLogic {
return source._subscribe(new AuditTimeSubscriber(subscriber, this.duration, this.scheduler));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/operator/debounce.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Operator} from '../Operator';
import {Observable, SubscribableOrPromise} from '../Observable';
import {Subscriber} from '../Subscriber';
import {Subscription} from '../Subscription';
import {Subscription, TeardownLogic} from '../Subscription';

import {OuterSubscriber} from '../OuterSubscriber';
import {InnerSubscriber} from '../InnerSubscriber';
Expand Down Expand Up @@ -61,7 +61,7 @@ class DebounceOperator<T> implements Operator<T, T> {
constructor(private durationSelector: (value: T) => SubscribableOrPromise<number>) {
}

call(subscriber: Subscriber<T>, source: any): any {
call(subscriber: Subscriber<T>, source: any): TeardownLogic {
return source._subscribe(new DebounceSubscriber(subscriber, this.durationSelector));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/operator/debounceTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Operator} from '../Operator';
import {Observable} from '../Observable';
import {Subscriber} from '../Subscriber';
import {Scheduler} from '../Scheduler';
import {Subscription} from '../Subscription';
import {Subscription, TeardownLogic} from '../Subscription';
import {async} from '../scheduler/async';

/**
Expand Down Expand Up @@ -63,7 +63,7 @@ class DebounceTimeOperator<T> implements Operator<T, T> {
constructor(private dueTime: number, private scheduler: Scheduler) {
}

call(subscriber: Subscriber<T>, source: any): any {
call(subscriber: Subscriber<T>, source: any): TeardownLogic {
return source._subscribe(new DebounceTimeSubscriber(subscriber, this.dueTime, this.scheduler));
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/operator/delay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Scheduler} from '../Scheduler';
import {Subscriber} from '../Subscriber';
import {Notification} from '../Notification';
import {Observable} from '../Observable';
import {TeardownLogic} from '../Subscription';

/**
* Delays the emission of items from the source Observable by a given timeout or
Expand Down Expand Up @@ -61,7 +62,7 @@ class DelayOperator<T> implements Operator<T, T> {
private scheduler: Scheduler) {
}

call(subscriber: Subscriber<T>, source: any): any {
call(subscriber: Subscriber<T>, source: any): TeardownLogic {
return source._subscribe(new DelaySubscriber(subscriber, this.delay, this.scheduler));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/operator/delayWhen.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';
import {Observable} from '../Observable';
import {Subscription} from '../Subscription';
import {Subscription, TeardownLogic} from '../Subscription';

import {OuterSubscriber} from '../OuterSubscriber';
import {InnerSubscriber} from '../InnerSubscriber';
Expand Down Expand Up @@ -69,7 +69,7 @@ class DelayWhenOperator<T> implements Operator<T, T> {
constructor(private delayDurationSelector: (value: T) => Observable<any>) {
}

call(subscriber: Subscriber<T>, source: any): any {
call(subscriber: Subscriber<T>, source: any): TeardownLogic {
return source._subscribe(new DelayWhenSubscriber(subscriber, this.delayDurationSelector));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/operator/distinct.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Observable} from '../Observable';
import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';

import {TeardownLogic} from '../Subscription';
import {OuterSubscriber} from '../OuterSubscriber';
import {InnerSubscriber} from '../InnerSubscriber';
import {subscribeToResult} from '../util/subscribeToResult';
Expand Down Expand Up @@ -30,7 +30,7 @@ class DistinctOperator<T> implements Operator<T, T> {
constructor(private compare: (x: T, y: T) => boolean, private flushes: Observable<any>) {
}

call(subscriber: Subscriber<T>, source: any): any {
call(subscriber: Subscriber<T>, source: any): TeardownLogic {
return source._subscribe(new DistinctSubscriber(subscriber, this.compare, this.flushes));
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/operator/distinctUntilChanged.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Subscriber} from '../Subscriber';
import {tryCatch} from '../util/tryCatch';
import {errorObject} from '../util/errorObject';
import {Observable} from '../Observable';
import {TeardownLogic} from '../Subscription';

/**
* Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from the previous item.
Expand All @@ -27,7 +28,7 @@ class DistinctUntilChangedOperator<T, K> implements Operator<T, T> {
private keySelector: (x: T) => K) {
}

call(subscriber: Subscriber<T>, source: any): any {
call(subscriber: Subscriber<T>, source: any): TeardownLogic {
return source._subscribe(new DistinctUntilChangedSubscriber(subscriber, this.compare, this.keySelector));
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/operator/do.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';
import {Observable} from '../Observable';
import {PartialObserver} from '../Observer';
import {TeardownLogic} from '../Subscription';

/**
* Perform a side effect for every emission on the source Observable, but return
Expand Down Expand Up @@ -62,7 +63,7 @@ class DoOperator<T> implements Operator<T, T> {
private error?: (e: any) => void,
private complete?: () => void) {
}
call(subscriber: Subscriber<T>, source: any): any {
call(subscriber: Subscriber<T>, source: any): TeardownLogic {
return source._subscribe(new DoSubscriber(subscriber, this.nextOrObserver, this.error, this.complete));
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/operator/elementAt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';
import {ArgumentOutOfRangeError} from '../util/ArgumentOutOfRangeError';
import {Observable} from '../Observable';
import {TeardownLogic} from '../Subscription';

/**
* Emits the single value at the specified `index` in a sequence of emissions
Expand Down Expand Up @@ -56,7 +57,7 @@ class ElementAtOperator<T> implements Operator<T, T> {
}
}

call(subscriber: Subscriber<T>, source: any): any {
call(subscriber: Subscriber<T>, source: any): TeardownLogic {
return source._subscribe(new ElementAtSubscriber(subscriber, this.index, this.defaultValue));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/operator/exhaust.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Operator} from '../Operator';
import {Observable} from '../Observable';
import {Subscriber} from '../Subscriber';
import {Subscription} from '../Subscription';
import {Subscription, TeardownLogic} from '../Subscription';
import {OuterSubscriber} from '../OuterSubscriber';
import {subscribeToResult} from '../util/subscribeToResult';

Expand Down Expand Up @@ -50,7 +50,7 @@ export interface SwitchFirstSignature<T> {
}

class SwitchFirstOperator<T> implements Operator<T, T> {
call(subscriber: Subscriber<T>, source: any): any {
call(subscriber: Subscriber<T>, source: any): TeardownLogic {
return source._subscribe(new SwitchFirstSubscriber(subscriber));
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/operator/filter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';
import {Observable} from '../Observable';
import {TeardownLogic} from '../Subscription';

/**
* Filter items emitted by the source Observable by only emitting those that
Expand Down Expand Up @@ -56,7 +57,7 @@ class FilterOperator<T> implements Operator<T, T> {
private thisArg?: any) {
}

call(subscriber: Subscriber<T>, source: any): any {
call(subscriber: Subscriber<T>, source: any): TeardownLogic {
return source._subscribe(new FilterSubscriber(subscriber, this.predicate, this.thisArg));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/operator/finally.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';
import {Subscription} from '../Subscription';
import {Subscription, TeardownLogic} from '../Subscription';
import {Observable} from '../Observable';

/**
Expand All @@ -23,7 +23,7 @@ class FinallyOperator<T> implements Operator<T, T> {
constructor(private callback: () => void) {
}

call(subscriber: Subscriber<T>, source: any): any {
call(subscriber: Subscriber<T>, source: any): TeardownLogic {
return source._subscribe(new FinallySubscriber(subscriber, this.callback));
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/operator/observeOn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {Operator} from '../Operator';
import {PartialObserver} from '../Observer';
import {Subscriber} from '../Subscriber';
import {Notification} from '../Notification';
import {TeardownLogic} from '../Subscription';

/**
* @see {@link Notification}
Expand All @@ -26,7 +27,7 @@ export class ObserveOnOperator<T> implements Operator<T, T> {
constructor(private scheduler: Scheduler, private delay: number = 0) {
}

call(subscriber: Subscriber<T>, source: any): any {
call(subscriber: Subscriber<T>, source: any): TeardownLogic {
return source._subscribe(new ObserveOnSubscriber(subscriber, this.scheduler, this.delay));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/operator/race.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {isArray} from '../util/isArray';
import {ArrayObservable} from '../observable/ArrayObservable';
import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';
import {Subscription} from '../Subscription';
import {Subscription, TeardownLogic} from '../Subscription';
import {OuterSubscriber} from '../OuterSubscriber';
import {InnerSubscriber} from '../InnerSubscriber';
import {subscribeToResult} from '../util/subscribeToResult';
Expand Down Expand Up @@ -56,7 +56,7 @@ export function raceStatic<T>(...observables: Array<Observable<any> | Array<Obse
}

export class RaceOperator<T> implements Operator<T, T> {
call(subscriber: Subscriber<T>, source: any): any {
call(subscriber: Subscriber<T>, source: any): TeardownLogic {
return source._subscribe(new RaceSubscriber(subscriber));
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/operator/repeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';
import {Observable} from '../Observable';
import {EmptyObservable} from '../observable/EmptyObservable';
import {TeardownLogic} from '../Subscription';

/**
* Returns an Observable that repeats the stream of items emitted by the source Observable at most count times,
Expand Down Expand Up @@ -35,7 +36,7 @@ class RepeatOperator<T> implements Operator<T, T> {
constructor(private count: number,
private source: Observable<T>) {
}
call(subscriber: Subscriber<T>, source: any): any {
call(subscriber: Subscriber<T>, source: any): TeardownLogic {
return source._subscribe(new RepeatSubscriber(subscriber, this.count, this.source));
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/operator/retry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';
import {Observable} from '../Observable';
import {TeardownLogic} from '../Subscription';

/**
* Returns an Observable that mirrors the source Observable, resubscribing to it if it calls `error` and the
Expand Down Expand Up @@ -32,7 +33,7 @@ class RetryOperator<T> implements Operator<T, T> {
private source: Observable<T>) {
}

call(subscriber: Subscriber<T>, source: any): any {
call(subscriber: Subscriber<T>, source: any): TeardownLogic {
return source._subscribe(new RetrySubscriber(subscriber, this.count, this.source));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/operator/retryWhen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';
import {Observable} from '../Observable';
import {Subject} from '../Subject';
import {Subscription} from '../Subscription';
import {Subscription, TeardownLogic} from '../Subscription';
import {tryCatch} from '../util/tryCatch';
import {errorObject} from '../util/errorObject';

Expand Down Expand Up @@ -39,7 +39,7 @@ class RetryWhenOperator<T> implements Operator<T, T> {
protected source: Observable<T>) {
}

call(subscriber: Subscriber<T>, source: any): any {
call(subscriber: Subscriber<T>, source: any): TeardownLogic {
return source._subscribe(new RetryWhenSubscriber(subscriber, this.notifier, this.source));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/operator/sample.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Operator} from '../Operator';
import {Observable} from '../Observable';
import {Subscriber} from '../Subscriber';

import {TeardownLogic} from '../Subscription';
import {OuterSubscriber} from '../OuterSubscriber';
import {InnerSubscriber} from '../InnerSubscriber';
import {subscribeToResult} from '../util/subscribeToResult';
Expand Down Expand Up @@ -52,7 +52,7 @@ class SampleOperator<T> implements Operator<T, T> {
constructor(private notifier: Observable<any>) {
}

call(subscriber: Subscriber<T>, source: any): any {
call(subscriber: Subscriber<T>, source: any): TeardownLogic {
return source._subscribe(new SampleSubscriber(subscriber, this.notifier));
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/operator/sampleTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';
import {Scheduler} from '../Scheduler';
import {async} from '../scheduler/async';
import {TeardownLogic} from '../Subscription';

/**
* Emits the most recently emitted value from the source Observable within
Expand Down Expand Up @@ -53,7 +54,7 @@ class SampleTimeOperator<T> implements Operator<T, T> {
private scheduler: Scheduler) {
}

call(subscriber: Subscriber<T>, source: any): any {
call(subscriber: Subscriber<T>, source: any): TeardownLogic {
return source._subscribe(new SampleTimeSubscriber(subscriber, this.period, this.scheduler));
}
}
Expand Down
Loading

0 comments on commit 4f65b03

Please sign in to comment.