Skip to content

Commit

Permalink
fix(combineLatest): check for limits higher than total observable count
Browse files Browse the repository at this point in the history
  • Loading branch information
jinroh authored and benlesh committed Aug 28, 2015
1 parent 623edf7 commit 81e5dfb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
27 changes: 21 additions & 6 deletions spec/operators/combineLatest-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ describe('combineLatest', function () {
var i = 0;
Observable.of(a, b).combineAll().subscribe(function (vals) {
expect(vals).toDeepEqual(r[i++]);
}, null, done);
}, null, function() {
expect(i).toEqual(r.length);
done();
});
});
it("should combine a source with a second", function (done) {
var a = Observable.of(1, 2, 3);
Expand All @@ -21,7 +24,10 @@ describe('combineLatest', function () {
var i = 0;
a.combineLatest(b).subscribe(function (vals) {
expect(vals).toDeepEqual(r[i++]);
}, null, done);
}, null, function() {
expect(i).toEqual(r.length);
done();
});
});
it("should combine two immediately-scheduled observables", function (done) {
var a = Observable.of(1, 2, 3, immediateScheduler);
Expand All @@ -30,7 +36,10 @@ describe('combineLatest', function () {
var i = 0;
Observable.of(a, b, immediateScheduler).combineAll().subscribe(function (vals) {
expect(vals).toDeepEqual(r[i++]);
}, null, done);
}, null, function() {
expect(i).toEqual(r.length);
done();
});
});
it("should combine an immediately-scheduled source with an immediately-scheduled second", function (done) {
var a = Observable.of(1, 2, 3, immediateScheduler);
Expand All @@ -39,7 +48,10 @@ describe('combineLatest', function () {
var i = 0;
a.combineLatest(b).subscribe(function (vals) {
expect(vals).toDeepEqual(r[i++]);
}, null, done);
}, null, function() {
expect(i).toEqual(r.length);
done();
});
});
it('should combineLatest the source with the provided observables', function (done) {
var expected = ['00', '01', '11', '12', '22', '23'];
Expand All @@ -50,6 +62,9 @@ describe('combineLatest', function () {
})
.subscribe(function (x) {
expect(x).toBe(expected[i++]);
}, null, done);
}, null, function() {
expect(i).toEqual(expected.length);
done();
});
}, 300);
});
});
5 changes: 3 additions & 2 deletions src/operators/combineLatest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Subscriber from '../Subscriber';

import ArrayObservable from '../observables/ArrayObservable';
import EmptyObservable from '../observables/EmptyObservable';
import {ZipSubscriber, ZipInnerSubscriber, hasValue, mapValue} from './zip';
import {ZipSubscriber, ZipInnerSubscriber} from './zip';

import tryCatch from '../util/tryCatch';
import {errorObject} from '../util/errorObject';
Expand Down Expand Up @@ -43,6 +43,7 @@ export class CombineLatestOperator<T, R> implements Operator<T, R> {
export class CombineLatestSubscriber<T, R> extends ZipSubscriber<T, R> {

project: (...values: Array<any>) => R;
limit: number = 0;

constructor(destination: Observer<R>, project?: (...values: Array<any>) => R) {
super(destination, project, []);
Expand Down Expand Up @@ -82,7 +83,7 @@ export class CombineLatestInnerSubscriber<T, R> extends ZipInnerSubscriber<T, R>
values[index] = [x];
}

if(limit === total) {
if(limit >= total) {
this._projectNext(values, parent.project);
}
}
Expand Down

0 comments on commit 81e5dfb

Please sign in to comment.