Skip to content

Commit

Permalink
feat(typings): updated typings for combineAll, mergeAll, concatAll, s…
Browse files Browse the repository at this point in the history
…witch, exhaust, zipAll (#3321)

this adds support for nested observables using some of the newest features of the TypeScript
    compiler.  Also updated tests in related areas
  • Loading branch information
david-driscoll authored and benlesh committed Feb 20, 2018
1 parent 6dfaee5 commit f7e4c02
Show file tree
Hide file tree
Showing 38 changed files with 1,184 additions and 741 deletions.
72 changes: 36 additions & 36 deletions spec/observables/combineLatest-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ describe('Observable.combineLatest', () => {
const expected = '----uv--wx-y--z----|';

const combined = Observable.combineLatest(firstSource, secondSource,
(a: any, b: any) => '' + a + b);
(a, b) => '' + a + b);

expectObservable(combined).toBe(expected, {u: 'ad', v: 'ae', w: 'af', x: 'bf', y: 'bg', z: 'cg'});
});

it('should combine an immediately-scheduled source with an immediately-scheduled second', (done: MochaDone) => {
it('should combine an immediately-scheduled source with an immediately-scheduled second', (done) => {
const a = Observable.of<number>(1, 2, 3, queueScheduler);
const b = Observable.of<number>(4, 5, 6, 7, 8, queueScheduler);
const r = [[1, 4], [2, 4], [2, 5], [3, 5], [3, 6], [3, 7], [3, 8]];

//type definition need to be updated
Observable.combineLatest(a, b, queueScheduler).subscribe((vals: any) => {
Observable.combineLatest(a, b, queueScheduler).subscribe((vals) => {
expect(vals).to.deep.equal(r.shift());
}, (x) => {
done(new Error('should not be called'));
Expand All @@ -42,7 +42,7 @@ describe('Observable.combineLatest', () => {
const expected = '----uv--wx-y--z----|';

const combined = Observable.combineLatest([firstSource, secondSource],
(a: any, b: any) => '' + a + b);
(a: string, b: string) => '' + a + b);

expectObservable(combined).toBe(expected, {u: 'ad', v: 'ae', w: 'af', x: 'bf', y: 'bg', z: 'cg'});
});
Expand All @@ -54,7 +54,7 @@ describe('Observable.combineLatest', () => {
const e2subs = '^';
const expected = '-';

const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y);
const result = Observable.combineLatest(e1, e2, (x, y) => x + y);

expectObservable(result).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -68,7 +68,7 @@ describe('Observable.combineLatest', () => {
const e2subs = '(^!)';
const expected = '-';

const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y);
const result = Observable.combineLatest(e1, e2, (x, y) => x + y);

expectObservable(result).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -82,7 +82,7 @@ describe('Observable.combineLatest', () => {
const e2subs = '^';
const expected = '-';

const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y);
const result = Observable.combineLatest(e1, e2, (x, y) => x + y);

expectObservable(result).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -96,7 +96,7 @@ describe('Observable.combineLatest', () => {
const e2subs = '(^!)';
const expected = '|';

const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y);
const result = Observable.combineLatest(e1, e2, (x, y) => x + y);

expectObservable(result).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -116,7 +116,7 @@ describe('Observable.combineLatest', () => {
const e2subs = '^ !';
const expected = '----|';

const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y);
const result = Observable.combineLatest(e1, e2, (x, y) => x + y);

expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -133,7 +133,7 @@ describe('Observable.combineLatest', () => {
const e2subs = '^ !';
const expected = '----|';

const result = Observable.combineLatest(e2, e1, (x: any, y: any) => x + y);
const result = Observable.combineLatest(e2, e1, (x, y) => x + y);

expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -150,7 +150,7 @@ describe('Observable.combineLatest', () => {
const e2subs = '^ ';
const expected = '-'; //never

const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y);
const result = Observable.combineLatest(e1, e2, (x, y) => x + y);

expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -167,7 +167,7 @@ describe('Observable.combineLatest', () => {
const e2subs = '^ !';
const expected = '-----'; //never

const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y);
const result = Observable.combineLatest(e1, e2, (x, y) => x + y);

expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -181,7 +181,7 @@ describe('Observable.combineLatest', () => {
const e2subs = '^ !';
const expected = '----x-yz--|';

const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y);
const result = Observable.combineLatest(e1, e2, (x, y) => x + y);

expectObservable(result).toBe(expected, { x: 'bf', y: 'cf', z: 'cg' });
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -195,7 +195,7 @@ describe('Observable.combineLatest', () => {
const e2subs = '^ !';
const expected = '------#';

const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y);
const result = Observable.combineLatest(e1, e2, (x, y) => x + y);

expectObservable(result).toBe(expected, null, 'shazbot!');
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -209,7 +209,7 @@ describe('Observable.combineLatest', () => {
const e2subs = '^ !';
const expected = '----#';

const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y);
const result = Observable.combineLatest(e1, e2, (x, y) => x + y);

expectObservable(result).toBe(expected, null, 'too bad, honk');
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -223,7 +223,7 @@ describe('Observable.combineLatest', () => {
const e2subs = '^ !';
const expected = '--#';

const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y);
const result = Observable.combineLatest(e1, e2, (x, y) => x + y);

expectObservable(result).toBe(expected, null, 'bazinga');
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -237,7 +237,7 @@ describe('Observable.combineLatest', () => {
const e2subs = '^ !';
const expected = '--#';

const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y);
const result = Observable.combineLatest(e1, e2, (x, y) => x + y);

expectObservable(result).toBe(expected, null, 'bazinga');
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -251,7 +251,7 @@ describe('Observable.combineLatest', () => {
const e2subs = '^ !';
const expected = '--#';

const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y);
const result = Observable.combineLatest(e1, e2, (x, y) => x + y);

expectObservable(result).toBe(expected, null, 'bazinga');
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -265,7 +265,7 @@ describe('Observable.combineLatest', () => {
const e2subs = '^ !';
const expected = '--#';

const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y);
const result = Observable.combineLatest(e1, e2, (x, y) => x + y);

expectObservable(result).toBe(expected, null, 'flurp');
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -279,7 +279,7 @@ describe('Observable.combineLatest', () => {
const e2subs = '^ !';
const expected = '--#';

const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y);
const result = Observable.combineLatest(e1, e2, (x, y) => x + y);

expectObservable(result).toBe(expected, null, 'flurp');
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -293,7 +293,7 @@ describe('Observable.combineLatest', () => {
const e2subs = '^ !';
const expected = '------#';

const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y);
const result = Observable.combineLatest(e1, e2, (x, y) => x + y);

expectObservable(result).toBe(expected, null, 'wokka wokka');
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -307,7 +307,7 @@ describe('Observable.combineLatest', () => {
const e2subs = '^ !';
const expected = '-----#';

const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y);
const result = Observable.combineLatest(e1, e2, (x, y) => x + y);

expectObservable(result).toBe(expected, null, 'wokka wokka');
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -321,7 +321,7 @@ describe('Observable.combineLatest', () => {
const e2subs = '^ !';
const expected = '---#';

const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y);
const result = Observable.combineLatest(e1, e2, (x, y) => x + y);

expectObservable(result).toBe(expected, { a: 1, b: 2}, 'wokka wokka');
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -335,7 +335,7 @@ describe('Observable.combineLatest', () => {
const e2subs = '^ !';
const expected = '---#';

const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y);
const result = Observable.combineLatest(e1, e2, (x, y) => x + y);

expectObservable(result).toBe(expected, { a: 1, b: 2}, 'wokka wokka');
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -349,7 +349,7 @@ describe('Observable.combineLatest', () => {
const rightSubs = '^ !';
const expected = '---------#';

const result = Observable.combineLatest(left, right, (x: any, y: any) => x + y);
const result = Observable.combineLatest(left, right, (x, y) => x + y);

expectObservable(result).toBe(expected, null, 'bad things');
expectSubscriptions(left.subscriptions).toBe(leftSubs);
Expand All @@ -363,7 +363,7 @@ describe('Observable.combineLatest', () => {
const rightSubs = '^ !';
const expected = '---------#';

const result = Observable.combineLatest(left, right, (x: any, y: any) => x + y);
const result = Observable.combineLatest(left, right, (x, y) => x + y);

expectObservable(result).toBe(expected, null, 'bad things');
expectSubscriptions(left.subscriptions).toBe(leftSubs);
Expand All @@ -377,7 +377,7 @@ describe('Observable.combineLatest', () => {
const e2subs = '^ !';
const expected = '-----x-y-z--|';

const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y);
const result = Observable.combineLatest(e1, e2, (x, y) => x + y);

expectObservable(result).toBe(expected, { x: 'be', y: 'ce', z: 'cf' });
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -391,7 +391,7 @@ describe('Observable.combineLatest', () => {
const e2subs = '^ !';
const expected = '-----------x--y--z--|';

const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y);
const result = Observable.combineLatest(e1, e2, (x, y) => x + y);

expectObservable(result).toBe(expected, { x: 'cd', y: 'ce', z: 'cf' });
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -405,7 +405,7 @@ describe('Observable.combineLatest', () => {
const rightSubs = '^ !';
const expected = '---------#';

const result = Observable.combineLatest(left, right, (x: any, y: any) => x + y);
const result = Observable.combineLatest(left, right, (x, y) => x + y);

expectObservable(result).toBe(expected, null, 'jenga');
expectSubscriptions(left.subscriptions).toBe(leftSubs);
Expand All @@ -419,7 +419,7 @@ describe('Observable.combineLatest', () => {
const rightSubs = '^ !';
const expected = '-----------x--y--z--#';

const result = Observable.combineLatest(left, right, (x: any, y: any) => x + y);
const result = Observable.combineLatest(left, right, (x, y) => x + y);

expectObservable(result).toBe(expected, { x: 'cd', y: 'ce', z: 'cf' }, 'dun dun dun');
expectSubscriptions(left.subscriptions).toBe(leftSubs);
Expand All @@ -433,7 +433,7 @@ describe('Observable.combineLatest', () => {
const e2subs = '^ !';
const expected = '---#';

const result = Observable.combineLatest(e1, e2, (x: any, y: any) => { throw 'ha ha ' + x + ', ' + y; });
const result = Observable.combineLatest(e1, e2, (x, y) => { throw 'ha ha ' + x + ', ' + y; });

expectObservable(result).toBe(expected, null, 'ha ha 2, 4');
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -449,7 +449,7 @@ describe('Observable.combineLatest', () => {
const unsub = ' ! ';
const values = { x: 'bf', y: 'cf', z: 'cg' };

const result = Observable.combineLatest(e1, e2, (x: any, y: any) => x + y);
const result = Observable.combineLatest(e1, e2, (x, y) => x + y);

expectObservable(result, unsub).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -466,10 +466,10 @@ describe('Observable.combineLatest', () => {
const values = { x: 'bf', y: 'cf', z: 'cg' };

const result = Observable.combineLatest(
e1.mergeMap((x: string) => Observable.of(x)),
e2.mergeMap((x: string) => Observable.of(x)),
(x: any, y: any) => x + y
).mergeMap((x: any) => Observable.of(x));
e1.mergeMap((x) => Observable.of(x)),
e2.mergeMap((x) => Observable.of(x)),
(x, y) => x + y
).mergeMap((x) => Observable.of(x));

expectObservable(result, unsub).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand Down
10 changes: 5 additions & 5 deletions spec/observables/concat-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ describe('Observable.concat', () => {
const expected = '--i-j-k-l---i-j-';
const unsub = ' !';

const innerWrapped = inner.mergeMap((x: string) => Observable.of(x));
const innerWrapped = inner.mergeMap((x) => Observable.of(x));
const result = Observable
.concat(innerWrapped, innerWrapped, innerWrapped, innerWrapped)
.mergeMap((x: any) => Observable.of(x));
.mergeMap((x) => Observable.of(x));

expectObservable(result, unsub).toBe(expected);
expectSubscriptions(inner.subscriptions).toBe(innersubs);
Expand Down Expand Up @@ -334,17 +334,17 @@ describe('Observable.concat', () => {
expectSubscriptions(e2.subscriptions).toBe(e2subs);
});

it('should concat an immediately-scheduled source with an immediately-scheduled second', (done: MochaDone) => {
it('should concat an immediately-scheduled source with an immediately-scheduled second', (done) => {
const a = Observable.of<number>(1, 2, 3, queueScheduler);
const b = Observable.of<number>(4, 5, 6, 7, 8, queueScheduler);
const r = [1, 2, 3, 4, 5, 6, 7, 8];

Observable.concat(a, b, queueScheduler).subscribe((vals: number) => {
Observable.concat(a, b, queueScheduler).subscribe((vals) => {
expect(vals).to.equal(r.shift());
}, null, done);
});

it('should use the scheduler even when one Observable is concat\'d', (done: MochaDone) => {
it('should use the scheduler even when one Observable is concat\'d', (done) => {
let e1Subscribed = false;
const e1 = Observable.defer(() => {
e1Subscribed = true;
Expand Down
2 changes: 1 addition & 1 deletion spec/observables/merge-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ describe('Observable.merge(...observables, Scheduler, number)', () => {
expectObservable(Observable.merge(e1, e2, e3, 2, rxTestScheduler)).toBe(expected);
});

it('should use the scheduler even when one Observable is merged', (done: MochaDone) => {
it('should use the scheduler even when one Observable is merged', (done) => {
let e1Subscribed = false;
const e1 = Observable.defer(() => {
e1Subscribed = true;
Expand Down
Loading

0 comments on commit f7e4c02

Please sign in to comment.