Skip to content

Commit

Permalink
fix(typings): remove R from Operator.call, update operators accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
masaeedu authored and kwonoj committed Feb 10, 2016
1 parent 603c9eb commit f27902d
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/Operator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Subscriber} from './Subscriber';

export class Operator<T, R> {
call<R>(subscriber: Subscriber<R>): Subscriber<T> {
call(subscriber: Subscriber<R>): Subscriber<T> {
return new Subscriber<T>(subscriber);
}
}
2 changes: 1 addition & 1 deletion src/observable/dom/WebSocketSubject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class WebSocketSubject<T> extends Subject<T> {

lift<R>(operator: Operator<T, R>) {
const sock: WebSocketSubject<T> = new WebSocketSubject(this, this.destination);
sock.operator = operator;
sock.operator = <any>operator;
return sock;
}

Expand Down
6 changes: 3 additions & 3 deletions src/operator/defaultIfEmpty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ export function defaultIfEmpty<T, R>(defaultValue: R = null): Observable<T | R>
return this.lift(new DefaultIfEmptyOperator(defaultValue));
}

class DefaultIfEmptyOperator<T, R> implements Operator<T, R> {
class DefaultIfEmptyOperator<T, R> implements Operator<T, T | R> {

constructor(private defaultValue: R) {
}

call(subscriber: Subscriber<T>): Subscriber<T> {
call(subscriber: Subscriber<T | R>): Subscriber<T> {
return new DefaultIfEmptySubscriber(subscriber, this.defaultValue);
}
}

class DefaultIfEmptySubscriber<T, R> extends Subscriber<T> {
private isEmpty: boolean = true;

constructor(destination: Subscriber<T>, private defaultValue: R) {
constructor(destination: Subscriber<T | R>, private defaultValue: R) {
super(destination);
}

Expand Down
4 changes: 2 additions & 2 deletions src/operator/distinct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import {subscribeToResult} from '../util/subscribeToResult';
* @param {Observable} [flushes] optional Observable for flushing the internal HashSet of the operator.
* @returns {Observable} an Observable that emits items from the source Observable with distinct values.
*/
export function distinct<T>(compare?: (x: T, y: T) => boolean, flushes?: Observable<any>) {
export function distinct<T>(compare?: (x: T, y: T) => boolean, flushes?: Observable<any>): Observable<T> {
return this.lift(new DistinctOperator(compare, flushes));
}

class DistinctOperator<T, R> implements Operator<T, R> {
class DistinctOperator<T> implements Operator<T, T> {
constructor(private compare: (x: T, y: T) => boolean, private flushes: Observable<any>) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/operator/every.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function every<T>(predicate: (value: T, index: number, source: Observable
return source.lift(new EveryOperator(predicate, thisArg, source));
}

class EveryOperator<T, R> implements Operator<T, R> {
class EveryOperator<T, R> implements Operator<T, boolean> {
constructor(private predicate: (value: T, index: number, source: Observable<T>) => boolean,
private thisArg?: any,
private source?: Observable<T>) {
Expand Down
2 changes: 1 addition & 1 deletion src/operator/groupBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface RefCountSubscription {
attemptedToUnsubscribe: boolean;
}

class GroupByOperator<T, K, R> extends Operator<T, R> {
class GroupByOperator<T, K, R> extends Operator<T, GroupedObservable<K, R>> {
constructor(public source: Observable<T>,
private keySelector: (value: T) => K,
private elementSelector?: (value: T) => R,
Expand Down
2 changes: 1 addition & 1 deletion src/operator/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function inspect<T>(durationSelector: (value: T) => Observable<any> | Pro
return this.lift(new InspectOperator(durationSelector));
}

class InspectOperator<T, R> implements Operator<T, R> {
class InspectOperator<T> implements Operator<T, T> {
constructor(private durationSelector: (value: T) => Observable<any> | Promise<any>) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/operator/inspectTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function inspectTime<T>(delay: number, scheduler: Scheduler = asap): Obse
return this.lift(new InspectTimeOperator(delay, scheduler));
}

class InspectTimeOperator<T, R> implements Operator<T, R> {
class InspectTimeOperator<T> implements Operator<T, T> {
constructor(private delay: number, private scheduler: Scheduler) {
}

Expand Down
9 changes: 4 additions & 5 deletions src/operator/isEmpty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ export function isEmpty(): Observable<boolean> {
return this.lift(new IsEmptyOperator());
}

class IsEmptyOperator<T> implements Operator<boolean, boolean> {
call (observer: Subscriber<T>): Subscriber<boolean> {
class IsEmptyOperator implements Operator<any, boolean> {
call (observer: Subscriber<boolean>): Subscriber<any> {
return new IsEmptySubscriber(observer);
}
}

class IsEmptySubscriber extends Subscriber<boolean> {

constructor(destination: Subscriber<any>) {
class IsEmptySubscriber extends Subscriber<any> {
constructor(destination: Subscriber<boolean>) {
super(destination);
}

Expand Down
8 changes: 4 additions & 4 deletions src/operator/pairwise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import {Subscriber} from '../Subscriber';
*
* @returns {Observable<R>} an observable of pairs of values.
*/
export function pairwise<T>(): Observable<T> {
export function pairwise<T>(): Observable<[T, T]> {
return this.lift(new PairwiseOperator());
}

class PairwiseOperator<T, R> implements Operator<T, R> {
call(subscriber: Subscriber<T>): Subscriber<T> {
class PairwiseOperator<T> implements Operator<T, [T, T]> {
call(subscriber: Subscriber<[T, T]>): Subscriber<T> {
return new PairwiseSubscriber(subscriber);
}
}
Expand All @@ -25,7 +25,7 @@ class PairwiseSubscriber<T> extends Subscriber<T> {
private prev: T;
private hasPrev: boolean = false;

constructor(destination: Subscriber<T>) {
constructor(destination: Subscriber<[T, T]>) {
super(destination);
}

Expand Down
2 changes: 1 addition & 1 deletion src/operator/race.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function raceStatic<T>(...observables: Array<Observable<T> | Array<Observ
return new ArrayObservable(observables).lift(new RaceOperator());
}

export class RaceOperator<T, R> implements Operator<T, R> {
export class RaceOperator<T> implements Operator<T, T> {
call(subscriber: Subscriber<T>): Subscriber<T> {
return new RaceSubscriber(subscriber);
}
Expand Down
4 changes: 2 additions & 2 deletions src/operator/reduce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class ReduceOperator<T, R> implements Operator<T, R> {
constructor(private project: (acc: R, value: T) => R, private seed?: R) {
}

call(subscriber: Subscriber<T>): Subscriber<T> {
call(subscriber: Subscriber<R>): Subscriber<T> {
return new ReduceSubscriber(subscriber, this.project, this.seed);
}
}
Expand All @@ -39,7 +39,7 @@ export class ReduceSubscriber<T, R> extends Subscriber<T> {
hasValue: boolean = false;
project: (acc: R, value: T) => R;

constructor(destination: Subscriber<T>, project: (acc: R, value: T) => R, seed?: R) {
constructor(destination: Subscriber<R>, project: (acc: R, value: T) => R, seed?: R) {
super(destination);
this.acc = seed;
this.project = project;
Expand Down
4 changes: 2 additions & 2 deletions src/operator/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ScanOperator<T, R> implements Operator<T, R> {
constructor(private accumulator: (acc: R, x: T) => R, private seed?: T | R) {
}

call(subscriber: Subscriber<T>): Subscriber<T> {
call(subscriber: Subscriber<R>): Subscriber<T> {
return new ScanSubscriber(subscriber, this.accumulator, this.seed);
}
}
Expand All @@ -40,7 +40,7 @@ class ScanSubscriber<T, R> extends Subscriber<T> {

private accumulatorSet: boolean = false;

constructor(destination: Subscriber<T>, private accumulator: (acc: R, x: T) => R, seed?: T|R) {
constructor(destination: Subscriber<R>, private accumulator: (acc: R, x: T) => R, seed?: T|R) {
super(destination);
this.seed = seed;
this.accumulator = accumulator;
Expand Down
2 changes: 1 addition & 1 deletion src/operator/skipWhile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function skipWhile<T>(predicate: (value: T, index: number) => boolean): O
return this.lift(new SkipWhileOperator(predicate));
}

class SkipWhileOperator<T, R> implements Operator<T, R> {
class SkipWhileOperator<T> implements Operator<T, T> {
constructor(private predicate: (value: T, index: number) => boolean) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/operator/withLatestFrom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class WithLatestFromOperator<T, R> implements Operator<T, R> {
private project?: (...values: any[]) => Observable<R>) {
}

call(subscriber: Subscriber<T>): Subscriber<T> {
call(subscriber: Subscriber<R>): Subscriber<T> {
return new WithLatestFromSubscriber(subscriber, this.observables, this.project);
}
}
Expand All @@ -67,7 +67,7 @@ class WithLatestFromSubscriber<T, R> extends OuterSubscriber<T, R> {
private values: any[];
private toRespond: number[] = [];

constructor(destination: Subscriber<T>,
constructor(destination: Subscriber<R>,
private observables: Observable<any>[],
private project?: (...values: any[]) => Observable<R>) {
super(destination);
Expand Down

0 comments on commit f27902d

Please sign in to comment.