Skip to content

Commit

Permalink
style(typings): Adding combineLatest typings
Browse files Browse the repository at this point in the history
  • Loading branch information
david-driscoll committed Dec 3, 2015
1 parent c765ebe commit b184e18
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/CoreOperators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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?: operator.operator_proto_combineLatest<T>;
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
4 changes: 1 addition & 3 deletions src/Observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,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: operator.operator_proto_combineLatest<T>;
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
32 changes: 32 additions & 0 deletions src/operator-typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,35 @@ import {GroupByObservable} from './operator/groupBy';
import {TimeInterval} from './operator/extended/timeInterval';
import {ObservableOrPromise, ArrayOrIterator, _Selector, _IndexSelector, _SwitchMapResultSelector, _ObservableMergeMapProjector, _IteratorMergeMapProjector, _Predicate, _PredicateObservable, _Comparer, _Accumulator, _MergeAccumulator} from './types';

export interface operator_proto_combineLatest<T> {
<TResult>(project: (v1: T) => TResult): Observable<TResult>;
<TResult>(project: (v1: T) => TResult): Observable<TResult>;
<T2>(second: ObservableOrPromise<T2>): Observable<[T, T2]>;
<T2>(array: [ObservableOrPromise<T2>]): Observable<[T, T2]>;
<T2, TResult>(second: ObservableOrPromise<T2>, project: (v1: T, v2: T2) => TResult): Observable<TResult>;
<T2, TResult>(second: ObservableOrPromise<T2>, project: (v1: T, v2: T2) => TResult): Observable<TResult>;
<T2, TResult>(array: [ObservableOrPromise<T2>], project: (v1: T, v2: T2) => TResult): Observable<TResult>;
<T2, T3>(second: ObservableOrPromise<T2>, third: ObservableOrPromise<T3>): Observable<[T, T2, T3]>;
<T2, T3>(second: ObservableOrPromise<T2>, third: ObservableOrPromise<T3>): Observable<[T, T2, T3]>;
<T2, T3>(second: ArrayOrIterator<T2>, third: ObservableOrPromise<T3>): Observable<[T, T2, T3]>;
<T2, T3>(second: ArrayOrIterator<T2>, third: ArrayOrIterator<T3>): Observable<[T, T2, T3]>;
<T2, T3>(second: ArrayOrIterator<T2>, third: ArrayOrIterator<T3>): Observable<[T, T2, T3]>;
<T2, T3>(second: ObservableOrPromise<T2>, third: ArrayOrIterator<T3>): Observable<[T, T2, T3]>;
<T2, T3>(second: ObservableOrPromise<T2>, third: ArrayOrIterator<T3>): Observable<[T, T2, T3]>;
<T2, T3>(second: ArrayOrIterator<T2>, third: ObservableOrPromise<T3>): Observable<[T, T2, T3]>;
<T2, T3>(array: [ObservableOrPromise<T2>, ObservableOrPromise<T3>]): Observable<[T, T2, T3]>;
<T2, T3, TResult>(second: ObservableOrPromise<T2>, third: ObservableOrPromise<T3>, project: (v1: T, v2: T2, v3: T3) => TResult): Observable<TResult>;
<T2, T3, TResult>(second: ObservableOrPromise<T2>, third: ObservableOrPromise<T3>, project: (v1: T, v2: T2, v3: T3) => TResult): Observable<TResult>;
<T2, T3, TResult>(second: ArrayOrIterator<T2>, third: ObservableOrPromise<T3>, project: (v1: T, v2: T2, v3: T3) => TResult): Observable<TResult>;
<T2, T3, TResult>(second: ArrayOrIterator<T2>, third: ArrayOrIterator<T3>, project: (v1: T, v2: T2, v3: T3) => TResult): Observable<TResult>;
<T2, T3, TResult>(second: ArrayOrIterator<T2>, third: ArrayOrIterator<T3>, project: (v1: T, v2: T2, v3: T3) => TResult): Observable<TResult>;
<T2, T3, TResult>(second: ObservableOrPromise<T2>, third: ArrayOrIterator<T3>, project: (v1: T, v2: T2, v3: T3) => TResult): Observable<TResult>;
<T2, T3, TResult>(second: ObservableOrPromise<T2>, third: ArrayOrIterator<T3>, project: (v1: T, v2: T2, v3: T3) => TResult): Observable<TResult>;
<T2, T3, TResult>(second: ArrayOrIterator<T2>, third: ObservableOrPromise<T3>, project: (v1: T, v2: T2, v3: T3) => TResult): Observable<TResult>;
<T2, T3, TResult>(array: [ObservableOrPromise<T2>, ObservableOrPromise<T3>], project: (v1: T, v2: T2, v3: T3) => TResult): Observable<TResult>;
<TResult>(array: ObservableOrPromise<any>[], project?: Function): Observable<TResult[]>;
(...observables: Array<ObservableOrPromise<T>>): Observable<T[]>;
(...observables: Array<ArrayOrIterator<T>>): Observable<T[]>;
<R>(...observables: Array<ObservableOrPromise<T> | ((...values: Array<T>) => R)>): Observable<R>;
<R>(...observables: Array<ArrayOrIterator<T> | ((...values: Array<T>) => R)>): Observable<R>;
}
50 changes: 45 additions & 5 deletions src/operator/combineLatest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Observable} from '../Observable';
import {ArrayObservable} from '../observable/fromArray';
import {CombineLatestOperator} from './combineLatest-support';
import {isArray} from '../util/isArray';
import {ObservableOrPromise, ArrayOrIterator} from '../types';

/**
* Combines the values from this observable with values from observables passed as arguments. This is done by subscribing
Expand All @@ -13,18 +14,57 @@ import {isArray} from '../util/isArray';
* @returns {Observable} an observable of other projected values from the most recent values from each observable, or an array of each of
* the most recent values from each observable.
*/
export function combineLatest<R>(...observables: Array<Observable<any> |
Array<Observable<any>> |
((...values: Array<any>) => R)>): Observable<R> {
let project: (...values: Array<any>) => R = null;
export function combineLatest<T, TResult>(project: (v1: T) => TResult): Observable<TResult>;
export function combineLatest<T, TResult>(project: (v1: T) => TResult): Observable<TResult>;
export function combineLatest<T, T2>(second: ObservableOrPromise<T2>): Observable<[T, T2]>;
export function combineLatest<T, T2>(array: [ObservableOrPromise<T2>]): Observable<[T, T2]>;
export function combineLatest<T, T2, TResult>(second: ObservableOrPromise<T2>, project: (v1: T, v2: T2) => TResult): Observable<TResult>;
export function combineLatest<T, T2, TResult>(second: ObservableOrPromise<T2>, project: (v1: T, v2: T2) => TResult): Observable<TResult>;
export function combineLatest<T, T2, TResult>(array: [ObservableOrPromise<T2>], project: (v1: T, v2: T2) => TResult): Observable<TResult>;
export function combineLatest<T, T2, T3>(second: ObservableOrPromise<T2>, third: ObservableOrPromise<T3>): Observable<[T, T2, T3]>;
export function combineLatest<T, T2, T3>(second: ObservableOrPromise<T2>, third: ObservableOrPromise<T3>): Observable<[T, T2, T3]>;
export function combineLatest<T, T2, T3>(second: ArrayOrIterator<T2>, third: ObservableOrPromise<T3>): Observable<[T, T2, T3]>;
export function combineLatest<T, T2, T3>(second: ArrayOrIterator<T2>, third: ArrayOrIterator<T3>): Observable<[T, T2, T3]>;
export function combineLatest<T, T2, T3>(second: ArrayOrIterator<T2>, third: ArrayOrIterator<T3>): Observable<[T, T2, T3]>;
export function combineLatest<T, T2, T3>(second: ObservableOrPromise<T2>, third: ArrayOrIterator<T3>): Observable<[T, T2, T3]>;
export function combineLatest<T, T2, T3>(second: ObservableOrPromise<T2>, third: ArrayOrIterator<T3>): Observable<[T, T2, T3]>;
export function combineLatest<T, T2, T3>(second: ArrayOrIterator<T2>, third: ObservableOrPromise<T3>): Observable<[T, T2, T3]>;
export function combineLatest<T, T2, T3>(array: [ObservableOrPromise<T2>, ObservableOrPromise<T3>]): Observable<[T, T2, T3]>;
export function combineLatest<T, T2, T3, TResult>(second: ObservableOrPromise<T2>, third: ObservableOrPromise<T3>,
project: (v1: T, v2: T2, v3: T3) => TResult): Observable<TResult>;
export function combineLatest<T, T2, T3, TResult>(second: ObservableOrPromise<T2>, third: ObservableOrPromise<T3>,
project: (v1: T, v2: T2, v3: T3) => TResult): Observable<TResult>;
export function combineLatest<T, T2, T3, TResult>(second: ArrayOrIterator<T2>, third: ObservableOrPromise<T3>,
project: (v1: T, v2: T2, v3: T3) => TResult): Observable<TResult>;
export function combineLatest<T, T2, T3, TResult>(second: ArrayOrIterator<T2>, third: ArrayOrIterator<T3>,
project: (v1: T, v2: T2, v3: T3) => TResult): Observable<TResult>;
export function combineLatest<T, T2, T3, TResult>(second: ArrayOrIterator<T2>, third: ArrayOrIterator<T3>,
project: (v1: T, v2: T2, v3: T3) => TResult): Observable<TResult>;
export function combineLatest<T, T2, T3, TResult>(second: ObservableOrPromise<T2>, third: ArrayOrIterator<T3>,
project: (v1: T, v2: T2, v3: T3) => TResult): Observable<TResult>;
export function combineLatest<T, T2, T3, TResult>(second: ObservableOrPromise<T2>, third: ArrayOrIterator<T3>,
project: (v1: T, v2: T2, v3: T3) => TResult): Observable<TResult>;
export function combineLatest<T, T2, T3, TResult>(second: ArrayOrIterator<T2>, third: ObservableOrPromise<T3>,
project: (v1: T, v2: T2, v3: T3) => TResult): Observable<TResult>;
export function combineLatest<T, T2, T3, TResult>(array: [ObservableOrPromise<T2>, ObservableOrPromise<T3>],
project: (v1: T, v2: T2, v3: T3) => TResult): Observable<TResult>;
export function combineLatest<T, TResult>(array: ObservableOrPromise<any>[], project?: Function): Observable<TResult[]>;
export function combineLatest<T>(...observables: Array<ObservableOrPromise<T>>): Observable<T[]>;
export function combineLatest<T>(...observables: Array<ArrayOrIterator<T>>): Observable<T[]>;
export function combineLatest<T, R>(...observables: Array<ObservableOrPromise<T> | ((...values: Array<T>) => R)>): Observable<R>;
export function combineLatest<T, R>(...observables: Array<ArrayOrIterator<T> | ((...values: Array<T>) => R)>): Observable<R>;
export function combineLatest<R>(...observables: Array<any | Observable<any> |
Array<Promise<any>> |
((...values: Array<any>) => R)>): Observable<R> {
let project: (...values: Array<any>) => R = null;
if (typeof observables[observables.length - 1] === 'function') {
project = <(...values: Array<any>) => R>observables.pop();
}

// if the first and only other argument besides the resultSelector is an array
// assume it's been called with `combineLatest([obs1, obs2, obs3], project)`
if (observables.length === 1 && isArray(observables[0])) {
observables = <Array<Observable<any>>>observables[0];
observables = <any>observables[0];
}

observables.unshift(this);
Expand Down

0 comments on commit b184e18

Please sign in to comment.