Skip to content

Commit

Permalink
style(typings): added enhanced typings for bindCallback and combineLa…
Browse files Browse the repository at this point in the history
…test
  • Loading branch information
david-driscoll committed Jan 13, 2016
1 parent 7a679b6 commit 846bcca
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/CoreOperators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {Subject} from './Subject';
import {GroupedObservable} from './operator/groupBy-support';
import {Notification} from './Notification';

import {CombineLatestDeclaration} from './operator/combineLatest';

export interface CoreOperators<T> {
buffer?: (closingNotifier: Observable<any>) => Observable<T[]>;
bufferCount?: (bufferSize: number, startBufferEvery: number) => Observable<T[]>;
Expand All @@ -13,7 +15,7 @@ export interface CoreOperators<T> {
bufferWhen?: (closingSelector: () => Observable<any>) => Observable<T[]>;
catch?: (selector: (err: any, source: Observable<T>, caught: Observable<any>) => Observable<any>) => Observable<T>;
combineAll?: <R>(project?: (...values: Array<any>) => R) => Observable<R>;
combineLatest?: <R>(...observables: Array<Observable<any> | ((...values: Array<any>) => R)>) => Observable<R>;
combineLatest: CombineLatestDeclaration<this>;
concat?: <R>(...observables: (Observable<any> | Scheduler)[]) => Observable<R>;
concatAll?: () => Observable<T>;
concatMap?: <R>(project: ((x: T, ix: number) => Observable<any>), projectResult?: (x: T, y: any, ix: number, iy: number) => R) => Observable<R>;
Expand Down
6 changes: 3 additions & 3 deletions src/Observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {ErrorObservable} from './observable/throw';
import {AjaxCreationMethod} from './observable/dom/ajax';
import {WebSocketSubject} from './observable/dom/webSocket';

import {CombineLatestDeclaration} from './operator/combineLatest';

/**
* A representation of any set of values over any amount of time. This the most basic building block
* of RxJS.
Expand Down Expand Up @@ -196,9 +198,7 @@ export class Observable<T> implements CoreOperators<T> {
bufferWhen: (closingSelector: () => Observable<any>) => Observable<T[]>;
catch: (selector: (err: any, source: Observable<T>, caught: Observable<any>) => Observable<any>) => Observable<T>;
combineAll: <R>(project?: (...values: Array<any>) => R) => Observable<R>;
combineLatest: <R>(...observables: Array<Observable<any> |
Array<Observable<any>> |
((...values: Array<any>) => R)>) => Observable<R>;
combineLatest: CombineLatestDeclaration<this>;
concat: <R>(...observables: (Observable<any> | Scheduler)[]) => Observable<R>;
concatAll: () => Observable<any>;
concatMap: <R>(project: ((x: T, ix: number) => Observable<any>), projectResult?: (x: T, y: any, ix: number, iy: number) => R) => Observable<R>;
Expand Down
2 changes: 1 addition & 1 deletion src/add/operator/combineLatest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
import {Observable} from '../../Observable';
import {combineLatest} from '../../operator/combineLatest';

Observable.prototype.combineLatest = combineLatest;
Observable.prototype.combineLatest = <any>combineLatest;

export var _void: void;
18 changes: 18 additions & 0 deletions src/observable/bindCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ import {AsyncSubject} from '../subject/AsyncSubject';
export class BoundCallbackObservable<T> extends Observable<T> {
subject: AsyncSubject<T>;

/* tslint:disable:max-line-length */
static create<TResult>(callbackFunc: (callback: (result: TResult) => any) => any, selector?: void, scheduler?: Scheduler): () => Observable<TResult>;
static create<T, TResult>(callbackFunc: (v1: T, callback: (result: TResult) => any) => any, selector?: void, scheduler?: Scheduler): (v1: T) => Observable<TResult>;
static create<T, T2, TResult>(callbackFunc: (v1: T, v2: T2, callback: (result: TResult) => any) => any, selector?: void, scheduler?: Scheduler): (v1: T, v2: T2) => Observable<TResult>;
static create<T, T2, T3, TResult>(callbackFunc: (v1: T, v2: T2, v3: T3, callback: (result: TResult) => any) => any, selector?: void, scheduler?: Scheduler): (v1: T, v2: T2, v3: T3) => Observable<TResult>;
static create<T, T2, T3, T4, TResult>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, callback: (result: TResult) => any) => any, selector?: void, scheduler?: Scheduler): (v1: T, v2: T2, v3: T3, v4: T4) => Observable<TResult>;
static create<T, T2, T3, T4, T5, TResult>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, callback: (result: TResult) => any) => any, selector?: void, scheduler?: Scheduler): (v1: T, v2: T2, v3: T3, v4: T4, v5: T5) => Observable<TResult>;
static create<T, T2, T3, T4, T5, T6, TResult>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6, callback: (result: TResult) => any) => any, selector?: void, scheduler?: Scheduler): (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6) => Observable<TResult>;
static create<TResult>(callbackFunc: (callback: (...args: any[]) => any) => any, selector: (...args: any[]) => TResult, scheduler?: Scheduler): () => Observable<TResult>;
static create<T, TResult>(callbackFunc: (v1: T, callback: (...args: any[]) => any) => any, selector: (...args: any[]) => TResult, scheduler?: Scheduler): (v1: T) => Observable<TResult>;
static create<T, T2, TResult>(callbackFunc: (v1: T, v2: T2, callback: (...args: any[]) => any) => any, selector: (...args: any[]) => TResult, scheduler?: Scheduler): (v1: T, v2: T2) => Observable<TResult>;
static create<T, T2, T3, TResult>(callbackFunc: (v1: T, v2: T2, v3: T3, callback: (...args: any[]) => any) => any, selector: (...args: any[]) => TResult, scheduler?: Scheduler): (v1: T, v2: T2, v3: T3) => Observable<TResult>;
static create<T, T2, T3, T4, TResult>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, callback: (...args: any[]) => any) => any, selector: (...args: any[]) => TResult, scheduler?: Scheduler): (v1: T, v2: T2, v3: T3, v4: T4) => Observable<TResult>;
static create<T, T2, T3, T4, T5, TResult>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, callback: (...args: any[]) => any) => any, selector: (...args: any[]) => TResult, scheduler?: Scheduler): (v1: T, v2: T2, v3: T3, v4: T4, v5: T5) => Observable<TResult>;
static create<T, T2, T3, T4, T5, T6, TResult>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6, callback: (...args: any[]) => any) => any, selector: (...args: any[]) => TResult, scheduler?: Scheduler): (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6) => Observable<TResult>;
static create<T>(callbackFunc: Function, selector?: void, scheduler?: Scheduler): (...args: any[]) => Observable<T>;
static create<T>(callbackFunc: Function, selector?: (...args: any[]) => T, scheduler?: Scheduler): (...args: any[]) => Observable<T>;
/* tslint:enable:max-line-length */
static create<T>(callbackFunc: Function,
selector: Function | void = undefined,
scheduler?: Scheduler): (...args: any[]) => Observable<T> {
Expand Down
25 changes: 25 additions & 0 deletions src/operator/combineLatest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,28 @@ export function combineLatest<T, R>(...observables: Array<Observable<any> |

return new ArrayObservable(observables).lift<T, R>(new CombineLatestOperator<T, R>(project));
}

/* These types would be come standard types used through-out the library */
export type ObservableOrPromise<T> = Observable<T> | Promise<T>;
export type ArrayOrIterator<T> = Iterator<T> | ArrayLike<T> | Array<T>;
export type ObservableInput<T> = Observable<T> | Promise<T> | Iterator<T> | ArrayLike<T>;

/* tslint:disable:max-line-length */
export interface CombineLatestDeclaration<T> {
<T2>(v2: ObservableInput<T2>): Observable<[T, T2]>;
<T2, T3>(v2: ObservableInput<T2>, v3: ObservableInput<T3>): Observable<[T, T2, T3]>;
<T2, T3, T4>(v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>): Observable<[T, T2, T3, T4]>;
<T2, T3, T4, T5>(v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>): Observable<[T, T2, T3, T4, T5]>;
<T2, T3, T4, T5, T6>(v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, v6: ObservableInput<T6>): Observable<[T, T2, T3, T4, T5, T6]>;

<R>(project: (v1: T) => R): Observable<R>;
<T2, R>(v2: ObservableInput<T2>, project: (v1: T, v2: T2) => R): Observable<R>;
<T2, T3, R>(v2: ObservableInput<T2>, v3: ObservableInput<T3>, project: (v1: T, v2: T2, v3: T3) => R): Observable<R>;
<T2, T3, T4, R>(v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, project: (v1: T, v2: T2, v3: T3, v4: T4) => R): Observable<R>;
<T2, T3, T4, T5, R>(v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, project: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5) => R): Observable<R>;
<T2, T3, T4, T5, T6, R>(v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, v6: ObservableInput<T6>, project: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6) => R): Observable<R>;

<R>(...observables: Array<ObservableInput<any> | ((...values: Array<any>) => R)>): Observable<R>;
<R>(array: ObservableInput<any>[]): Observable<R>;
<R>(array: ObservableInput<any>[], project: (...values: Array<any>) => R): Observable<R>;
}

0 comments on commit 846bcca

Please sign in to comment.