Skip to content

Commit

Permalink
fix(race): allow TypeScript support for array of observables other th…
Browse files Browse the repository at this point in the history
…an rest param
  • Loading branch information
kwonoj committed Apr 12, 2017
1 parent 0ecf55d commit 95f5441
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
14 changes: 14 additions & 0 deletions spec/observables/race-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ describe('Observable.race', () => {
expectSubscriptions(e2.subscriptions).toBe(e2subs);
});

it('should race with array of observable', () => {
const e1 = cold('---a-----b-----c----|');
const e1subs = '^ !';
const e2 = cold('------x-----y-----z----|');
const e2subs = '^ !';
const expected = '---a-----b-----c----|';

const result = Observable.race([e1, e2]);

expectObservable(result).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
expectSubscriptions(e2.subscriptions).toBe(e2subs);
});

it('should race hot and hot', () => {
const e1 = hot('---a-----b-----c----|');
const e1subs = '^ !';
Expand Down
8 changes: 6 additions & 2 deletions src/operator/race.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import { InnerSubscriber } from '../InnerSubscriber';
import { subscribeToResult } from '../util/subscribeToResult';

/* tslint:disable:max-line-length */
export function race<T>(this: Observable<T>, observables: Array<Observable<T>>): Observable<T>;
export function race<T, R>(this: Observable<T>, observables: Array<Observable<T>>): Observable<R>;
export function race<T>(this: Observable<T>, ...observables: Array<Observable<T> | Array<Observable<T>>>): Observable<T>;
export function race<T, R>(this: Observable<T>, ...observables: Array<Observable<any> | Array<Observable<T>>>): Observable<R>;
export function race<T, R>(this: Observable<T>, ...observables: Array<Observable<any> | Array<Observable<any>>>): Observable<R>;
/* tslint:enable:max-line-length */

/**
Expand Down Expand Up @@ -39,10 +41,12 @@ export function race<T>(this: Observable<T>, ...observables: Array<Observable<T>
* @name race
* @owner Observable
*/
export function raceStatic<T>(observables: Array<Observable<T>>): Observable<T>;
export function raceStatic<T>(observables: Array<Observable<any>>): Observable<T>;
export function raceStatic<T>(...observables: Array<Observable<T> | Array<Observable<T>>>): Observable<T>;
export function raceStatic<T>(...observables: Array<Observable<any> | Array<Observable<any>>>): Observable<T> {
// if the only argument is an array, it was most likely called with
// `pair([obs1, obs2, ...])`
// `race([obs1, obs2, ...])`
if (observables.length === 1) {
if (isArray(observables[0])) {
observables = <Array<Observable<any>>>observables[0];
Expand Down

0 comments on commit 95f5441

Please sign in to comment.