-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(combineLatest): supports promises, iterables, lowercase-o observ…
…ables and Observables - refactor combineLatest to standalone from zip - moves tests for combineAll to own file - moves test regarding immediate scheduling to static combineLatest tests - adds support for iterables, promises, Observables and lowercase-o observables - adds scheduling capability to static combineLatest method
- Loading branch information
Showing
7 changed files
with
159 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* globals describe, it, expect, hot, cold, expectObservable */ | ||
var Rx = require('../../dist/cjs/Rx'); | ||
var Observable = Rx.Observable; | ||
var immediateScheduler = Rx.Scheduler.immediate; | ||
|
||
describe('Observable.prototype.combineAll()', function(){ | ||
it("should combine two observables", function (done) { | ||
var a = Observable.of(1, 2, 3); | ||
var b = Observable.of(4, 5, 6, 7, 8); | ||
var expected = [[3, 4], [3, 5], [3, 6], [3, 7], [3, 8]]; | ||
Observable.of(a, b).combineAll().subscribe(function (vals) { | ||
expect(vals).toEqual(expected.shift()); | ||
}, null, function() { | ||
expect(expected.length).toBe(0); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("should combine two immediately-scheduled observables", function (done) { | ||
var a = Observable.of(1, 2, 3, immediateScheduler); | ||
var b = Observable.of(4, 5, 6, 7, 8, immediateScheduler); | ||
var r = [[1, 4], [2, 4], [2, 5], [3, 5], [3, 6], [3, 7], [3, 8]]; | ||
var i = 0; | ||
Observable.of(a, b, immediateScheduler).combineAll().subscribe(function (vals) { | ||
expect(vals).toDeepEqual(r[i++]); | ||
}, null, function() { | ||
expect(i).toEqual(r.length); | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
import Observable from '../Observable'; | ||
import ArrayObservable from '../observables/ArrayObservable'; | ||
import { CombineLatestOperator } from './combineLatest-support'; | ||
import Scheduler from '../Scheduler'; | ||
|
||
export default function combineLatest<T, R>(...observables: (Observable<any> | ((...values: Array<any>) => R))[]): Observable<R> { | ||
const project = <((...ys: Array<any>) => R)> observables[observables.length - 1]; | ||
if (typeof project === "function") { | ||
observables.pop(); | ||
export default function combineLatest<T, R>(...observables: (Observable<any> | ((...values: Array<any>) => R) | Scheduler)[]): Observable<R> { | ||
let project, scheduler; | ||
|
||
if(typeof (<any>observables[observables.length - 1]).schedule === 'function') { | ||
scheduler = observables.pop(); | ||
} | ||
return new ArrayObservable(observables).lift(new CombineLatestOperator(project)); | ||
|
||
if (typeof observables[observables.length - 1] === 'function') { | ||
project = observables.pop(); | ||
} | ||
|
||
return new ArrayObservable(observables, scheduler).lift(new CombineLatestOperator(project)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.