Skip to content

Commit

Permalink
fix(concat): accept scheduler parameter
Browse files Browse the repository at this point in the history
- accept scheduler as last parameter
- expand test coverage
  • Loading branch information
kwonoj authored and benlesh committed Nov 18, 2015
1 parent 7f892ad commit 8859702
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
35 changes: 34 additions & 1 deletion spec/operators/concat-spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* globals describe, it, expect, expectObservable, hot, cold */
/* globals describe, it, expect, expectObservable, expectSubscriptions, hot, cold, rxTestScheduler */
var Rx = require('../../dist/cjs/Rx');

describe('Observable.prototype.concat()', function () {
Expand Down Expand Up @@ -221,4 +221,37 @@ describe('Observable.prototype.concat()', function () {
expectSubscriptions(e1.subscriptions).toBe(e1subs);
expectSubscriptions(e2.subscriptions).toBe(e2subs);
});

it('should accept scheduler with multiple observables', function () {
var e1 = cold('---a|');
var e1subs = '^ !';
var e2 = cold( '---b--|');
var e2subs = ' ^ !';
var e3 = cold( '---c--|');
var e3subs = ' ^ !';
var expected = '---a---b-----c--|';

expectObservable(e1.concat(e2, e3, rxTestScheduler)).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
expectSubscriptions(e2.subscriptions).toBe(e2subs);
expectSubscriptions(e3.subscriptions).toBe(e3subs);
});

it('should accept scheduler without observable parameters', function () {
var e1 = cold('---a-|');
var e1subs = '^ !';
var expected = '---a-|';

expectObservable(e1.concat(rxTestScheduler)).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

it('should emit self without parameters', function () {
var e1 = cold('---a-|');
var e1subs = '^ !';
var expected = '---a-|';

expectObservable(e1.concat()).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
});
12 changes: 8 additions & 4 deletions src/operators/concat.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {Observable} from '../Observable';
import {Scheduler} from '../Scheduler';
import {CoreOperators} from '../CoreOperators';
import {isScheduler} from '../util/isScheduler';
import {ArrayObservable} from '../observables/ArrayObservable';
import {MergeAllOperator} from './mergeAll-support';

/**
* Joins this observable with multiple other observables by subscribing to them one at a time, starting with the source,
Expand All @@ -14,8 +15,11 @@ import {isScheduler} from '../util/isScheduler';
export function concat<R>(...observables: (Observable<any> | Scheduler)[]): Observable<R> {
let args = <any[]>observables;
args.unshift(this);
if (args.length > 1 && isScheduler(args[args.length - 1])) {
args.splice(args.length - 2, 0, 1);

let scheduler: Scheduler = null;
if (isScheduler(args[args.length - 1])) {
scheduler = args.pop();
}
return (<CoreOperators<any>>Observable.fromArray(args)).mergeAll(1);

return new ArrayObservable(args, scheduler).lift(new MergeAllOperator(1));
}

0 comments on commit 8859702

Please sign in to comment.