From 42cee8045594779e8802b370c7244e6bbeeccaa3 Mon Sep 17 00:00:00 2001 From: Nicholas Jamieson Date: Tue, 9 Mar 2021 00:51:23 +1000 Subject: [PATCH] feat: rename and alias `combineLatest` as `combineLatestAll` for consistency (#6079) * chore: rename and alias comblineLatestAll Closes #4590 * chore: update api_guardian * chore: update docs and test --- api_guard/dist/types/operators/index.d.ts | 10 +-- .../deprecations/scheduler-argument.md | 52 +++++--------- docs_app/content/guide/operators.md | 4 +- spec-dtslint/operators/combineAll-spec.ts | 23 ------ .../operators/combineLatestAll-spec.ts | 23 ++++++ ...neAll-spec.ts => combineLatestAll-spec.ts} | 72 +++++++++---------- spec/operators/index-spec.ts | 2 + src/internal/observable/combineLatest.ts | 16 ++--- src/internal/operators/combineAll.ts | 56 +-------------- src/internal/operators/combineLatestAll.ts | 56 +++++++++++++++ src/internal/operators/concatAll.ts | 5 +- src/internal/operators/exhaustAll.ts | 4 +- src/internal/operators/joinAllInternals.ts | 2 +- src/internal/operators/mergeAll.ts | 4 +- src/internal/operators/switchAll.ts | 6 +- src/operators/index.ts | 2 +- 16 files changed, 166 insertions(+), 171 deletions(-) delete mode 100644 spec-dtslint/operators/combineAll-spec.ts create mode 100644 spec-dtslint/operators/combineLatestAll-spec.ts rename spec/operators/{combineAll-spec.ts => combineLatestAll-spec.ts} (87%) create mode 100644 src/internal/operators/combineLatestAll.ts diff --git a/api_guard/dist/types/operators/index.d.ts b/api_guard/dist/types/operators/index.d.ts index 8aefb5f1f9..4aff86b454 100644 --- a/api_guard/dist/types/operators/index.d.ts +++ b/api_guard/dist/types/operators/index.d.ts @@ -16,10 +16,7 @@ export declare function bufferWhen(closingSelector: () => ObservableInput>(selector: (err: any, caught: Observable) => O): OperatorFunction>; -export declare function combineAll(): OperatorFunction, T[]>; -export declare function combineAll(): OperatorFunction; -export declare function combineAll(project: (...values: T[]) => R): OperatorFunction, R>; -export declare function combineAll(project: (...values: Array) => R): OperatorFunction; +export declare const combineAll: typeof combineLatestAll; export declare function combineLatest(project: (v1: T) => R): OperatorFunction; export declare function combineLatest(v2: ObservableInput, project: (v1: T, v2: T2) => R): OperatorFunction; @@ -36,6 +33,11 @@ export declare function combineLatest(...observables: Array(array: ObservableInput[]): OperatorFunction>; export declare function combineLatest(array: ObservableInput[], project: (v1: T, ...values: Array) => R): OperatorFunction; +export declare function combineLatestAll(): OperatorFunction, T[]>; +export declare function combineLatestAll(): OperatorFunction; +export declare function combineLatestAll(project: (...values: T[]) => R): OperatorFunction, R>; +export declare function combineLatestAll(project: (...values: Array) => R): OperatorFunction; + export declare function combineLatestWith(...otherSources: [...ObservableInputTuple]): OperatorFunction>; export declare function concat(scheduler?: SchedulerLike): MonoTypeOperatorFunction; diff --git a/docs_app/content/deprecations/scheduler-argument.md b/docs_app/content/deprecations/scheduler-argument.md index b382a0c5f6..51c14b7f6b 100644 --- a/docs_app/content/deprecations/scheduler-argument.md +++ b/docs_app/content/deprecations/scheduler-argument.md @@ -28,18 +28,18 @@ If you use any other operator from the list above and using the `scheduler` argu ### Refactoring of `of` and `from` -`scheduled` is kinda copying the behavior of `from`. Therefore if you used `from` with a `scheduler` argument, you can just replace them. +`scheduled` is kinda copying the behavior of `from`. Therefore if you used `from` with a `scheduler` argument, you can just replace them. For the `of` creation function you need to this Observable with `scheduled` and instead of passing the `scheduler` argument to `of` pass it to `scheduled`. Following code example demonstrate this process. ```ts -import { of, asyncScheduler, scheduled } from 'rxjs'; +import { of, asyncScheduler, scheduled } from 'rxjs'; // Deprecated approach -of([1,2,3], asyncScheduler).subscribe(x => console.log(x)); +of([1, 2, 3], asyncScheduler).subscribe((x) => console.log(x)); // suggested approach -scheduled([1,2,3], asyncScheduler).subscribe(x => console.log(x)); +scheduled([1, 2, 3], asyncScheduler).subscribe((x) => console.log(x)); ``` ### Refactoring of `merge`, `concat`, `combineLatest`, `startWith` and `endWith` @@ -47,55 +47,41 @@ scheduled([1,2,3], asyncScheduler).subscribe(x => console.log(x)); In case you used to pass a scheduler argument to one of these operators you probably had code like this: ```ts -import { concat, of, asyncScheduler } from 'rxjs'; +import { concat, of, asyncScheduler } from 'rxjs'; -concat( - of('hello '), - of('World'), - asyncScheduler -).subscribe(x => console.log(x)); +concat(of('hello '), of('World'), asyncScheduler).subscribe((x) => console.log(x)); ``` To work around this deprecation you can leverage the [`scheduled`](/api/index/function/scheduled) function. ```ts -import { scheduled, of, asyncScheduler } from 'rxjs'; -import { concatAll } from 'rxjs/operators' - -scheduled( - [of('hello '), of('World')], - asyncScheduler -).pipe( - concatAll() -).subscribe(x => console.log(x)); +import { scheduled, of, asyncScheduler } from 'rxjs'; +import { concatAll } from 'rxjs/operators'; + +scheduled([of('hello '), of('World')], asyncScheduler) + .pipe(concatAll()) + .subscribe((x) => console.log(x)); ``` You can apply this pattern to refactor deprecated usage of `concat`, `startWith` and `endWith` but do notice that you will want to use [mergeAll](/api/operators/mergeAll) to refactor the deprecated usage of `merge`. -With `combineLatest`, you will want to use [combineAll](/api/operators/combineAll) +With `combineLatest`, you will want to use [combineLatestAll](/api/operators/combineLatestAll) E.g. code that used to look like this: ```ts import { combineLatest, of, asyncScheduler } from 'rxjs'; -combineLatest( - of('hello '), - of('World'), - asyncScheduler -).subscribe(console.log) +combineLatest(of('hello '), of('World'), asyncScheduler).subscribe(console.log); ``` would become: ```ts import { scheduled, of, asyncScheduler } from 'rxjs'; -import { combineAll } from 'rxjs/operators' - -scheduled( - [of('hello '), of('World')], - asyncScheduler -).pipe( - combineAll() -).subscribe(x => console.log(x)); +import { combineLatestAll } from 'rxjs/operators'; + +scheduled([of('hello '), of('World')], asyncScheduler) + .pipe(combineLatestAll()) + .subscribe((x) => console.log(x)); ``` diff --git a/docs_app/content/guide/operators.md b/docs_app/content/guide/operators.md index 48f305c0db..db0c57a6f3 100644 --- a/docs_app/content/guide/operators.md +++ b/docs_app/content/guide/operators.md @@ -209,9 +209,9 @@ These are Observable creation operators that also have join functionality -- emi Also see the [Join Creation Operators](#join-creation-operators) section above. -- [`combineAll`](/api/operators/combineAll) +- [`combineLatestAll`](/api/operators/combineLatestAll) - [`concatAll`](/api/operators/concatAll) -- [`exhaust`](/api/operators/exhaust) +- [`exhaustAll`](/api/operators/exhaustAll) - [`mergeAll`](/api/operators/mergeAll) - [`switchAll`](/api/operators/switchAll) - [`startWith`](/api/operators/startWith) diff --git a/spec-dtslint/operators/combineAll-spec.ts b/spec-dtslint/operators/combineAll-spec.ts deleted file mode 100644 index 07b47e7edf..0000000000 --- a/spec-dtslint/operators/combineAll-spec.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { of } from 'rxjs'; -import { combineAll } from 'rxjs/operators'; - -it('should infer correctly', () => { - const o = of([1, 2, 3]).pipe(combineAll()); // $ExpectType Observable -}); - -it('should infer correctly with the projector', () => { - const o = of([1, 2, 3]).pipe(combineAll((values: number) => ['x', 'y', 'z'])); // $ExpectType Observable -}); - -it('is possible to make the projector have an `any` type', () => { - const o = of([1, 2, 3]).pipe(combineAll(values => ['x', 'y', 'z'])); // $ExpectType Observable -}); - -it('should enforce types', () => { - const o = of(1, 2, 3).pipe(combineAll()); // $ExpectError -}); - -it('should enforce type of the projector', () => { - const o = of([1, 2, 3]).pipe(combineAll((values: string) => ['x', 'y', 'z'])); // $ExpectError - const p = of([1, 2, 3]).pipe(combineAll(values => ['x', 'y', 'z'])); // $ExpectError -}); diff --git a/spec-dtslint/operators/combineLatestAll-spec.ts b/spec-dtslint/operators/combineLatestAll-spec.ts new file mode 100644 index 0000000000..2c98a94a4e --- /dev/null +++ b/spec-dtslint/operators/combineLatestAll-spec.ts @@ -0,0 +1,23 @@ +import { of } from 'rxjs'; +import { combineLatestAll } from 'rxjs/operators'; + +it('should infer correctly', () => { + const o = of([1, 2, 3]).pipe(combineLatestAll()); // $ExpectType Observable +}); + +it('should infer correctly with the projector', () => { + const o = of([1, 2, 3]).pipe(combineLatestAll((values: number) => ['x', 'y', 'z'])); // $ExpectType Observable +}); + +it('is possible to make the projector have an `any` type', () => { + const o = of([1, 2, 3]).pipe(combineLatestAll(values => ['x', 'y', 'z'])); // $ExpectType Observable +}); + +it('should enforce types', () => { + const o = of(1, 2, 3).pipe(combineLatestAll()); // $ExpectError +}); + +it('should enforce type of the projector', () => { + const o = of([1, 2, 3]).pipe(combineLatestAll((values: string) => ['x', 'y', 'z'])); // $ExpectError + const p = of([1, 2, 3]).pipe(combineLatestAll(values => ['x', 'y', 'z'])); // $ExpectError +}); diff --git a/spec/operators/combineAll-spec.ts b/spec/operators/combineLatestAll-spec.ts similarity index 87% rename from spec/operators/combineAll-spec.ts rename to spec/operators/combineLatestAll-spec.ts index 02a28e742f..33e50fa06a 100644 --- a/spec/operators/combineAll-spec.ts +++ b/spec/operators/combineLatestAll-spec.ts @@ -1,11 +1,11 @@ import { expect } from 'chai'; import { queueScheduler, of } from 'rxjs'; -import { combineAll, mergeMap } from 'rxjs/operators'; +import { combineLatestAll, mergeMap } from 'rxjs/operators'; import { TestScheduler } from 'rxjs/testing'; import { observableMatcher } from '../helpers/observableMatcher'; -/** @test {combineAll} */ -describe('combineAll operator', () => { +/** @test {combineLatestAll} */ +describe('combineLatestAll operator', () => { let testScheduler: TestScheduler; beforeEach(() => { @@ -19,7 +19,7 @@ describe('combineAll operator', () => { const outer = hot('-x----y--------| ', { x: x, y: y }); const expected = ' -----------------A-B--C---|'; - const result = outer.pipe(combineAll((a, b) => String(a) + String(b))); + const result = outer.pipe(combineLatestAll((a, b) => String(a) + String(b))); expectObservable(result).toBe(expected, { A: 'a1', B: 'a2', C: 'b2' }); }); @@ -33,7 +33,7 @@ describe('combineAll operator', () => { const e2subs = ' ^'; const expected = '-'; - const result = of(e1, e2).pipe(combineAll((x, y) => x + y)); + const result = of(e1, e2).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -49,7 +49,7 @@ describe('combineAll operator', () => { const e2subs = ' (^!)'; const expected = '-'; - const result = of(e1, e2).pipe(combineAll((x, y) => x + y)); + const result = of(e1, e2).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -65,7 +65,7 @@ describe('combineAll operator', () => { const e2subs = ' ^'; const expected = '-'; - const result = of(e1, e2).pipe(combineAll((x, y) => x + y)); + const result = of(e1, e2).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -81,7 +81,7 @@ describe('combineAll operator', () => { const e2subs = ' (^!)'; const expected = '|'; - const result = of(e1, e2).pipe(combineAll((x, y) => x + y)); + const result = of(e1, e2).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -97,7 +97,7 @@ describe('combineAll operator', () => { const e2subs = ' ^---!'; const expected = ' ----|'; - const result = of(e1, e2).pipe(combineAll((x, y) => x + y)); + const result = of(e1, e2).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -113,7 +113,7 @@ describe('combineAll operator', () => { const e2subs = ' ^---!'; const expected = ' ----|'; - const result = of(e2, e1).pipe(combineAll((x, y) => x + y)); + const result = of(e2, e1).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -129,7 +129,7 @@ describe('combineAll operator', () => { const e2subs = ' ^--'; const expected = ' ---'; //never - const result = of(e1, e2).pipe(combineAll((x, y) => x + y)); + const result = of(e1, e2).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -145,7 +145,7 @@ describe('combineAll operator', () => { const e2subs = ' ^---!'; const expected = ' -----'; //never - const result = of(e1, e2).pipe(combineAll((x, y) => x + y)); + const result = of(e1, e2).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -161,7 +161,7 @@ describe('combineAll operator', () => { const e2subs = ' ^---------!'; const expected = ' ----x-yz--|'; - const result = of(e1, e2).pipe(combineAll((x, y) => x + y)); + const result = of(e1, e2).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected, { x: 'bf', y: 'cf', z: 'cg' }); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -179,7 +179,7 @@ describe('combineAll operator', () => { const unsub = ' ---------! '; const values = { x: 'bf', y: 'cf', z: 'cg' }; - const result = of(e1, e2).pipe(combineAll((x, y) => x + y)); + const result = of(e1, e2).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result, unsub).toBe(expected, values); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -199,7 +199,7 @@ describe('combineAll operator', () => { const result = of(e1, e2).pipe( mergeMap((x) => of(x)), - combineAll((x, y) => x + y), + combineLatestAll((x, y) => x + y), mergeMap((x) => of(x)) ); @@ -219,7 +219,7 @@ describe('combineAll operator', () => { const e3subs = ' ^---------!'; const expected = ' -----wxyz-|'; - const result = of(e1, e2, e3).pipe(combineAll((x, y, z) => x + y + z)); + const result = of(e1, e2, e3).pipe(combineLatestAll((x, y, z) => x + y + z)); expectObservable(result).toBe(expected, { w: 'bfi', x: 'cfi', y: 'cgi', z: 'cgj' }); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -236,7 +236,7 @@ describe('combineAll operator', () => { const e2subs = ' ^-----!'; const expected = '------#'; - const result = of(e1, e2).pipe(combineAll((x, y) => x + y)); + const result = of(e1, e2).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected, null, 'shazbot!'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -252,7 +252,7 @@ describe('combineAll operator', () => { const e2subs = ' ^---!'; const expected = '----#'; - const result = of(e1, e2).pipe(combineAll((x, y) => x + y)); + const result = of(e1, e2).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected, null, 'too bad, honk'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -268,7 +268,7 @@ describe('combineAll operator', () => { const e2subs = ' ^-!'; const expected = ' --#'; - const result = of(e1, e2).pipe(combineAll((x, y) => x + y)); + const result = of(e1, e2).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected, null, 'bazinga'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -284,7 +284,7 @@ describe('combineAll operator', () => { const e2subs = ' ^-!'; const expected = ' --#'; - const result = of(e1, e2).pipe(combineAll((x, y) => x + y)); + const result = of(e1, e2).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected, null, 'bazinga'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -300,7 +300,7 @@ describe('combineAll operator', () => { const e2subs = ' ^-!'; const expected = ' --#'; - const result = of(e1, e2).pipe(combineAll((x, y) => x + y)); + const result = of(e1, e2).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected, null, 'bazinga'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -316,7 +316,7 @@ describe('combineAll operator', () => { const e2subs = ' ^-!'; const expected = ' --#'; - const result = of(e1, e2).pipe(combineAll((x, y) => x + y)); + const result = of(e1, e2).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected, null, 'flurp'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -332,7 +332,7 @@ describe('combineAll operator', () => { const e2subs = ' ^-!'; const expected = ' --#'; - const result = of(e1, e2).pipe(combineAll((x, y) => x + y)); + const result = of(e1, e2).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected, null, 'flurp'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -348,7 +348,7 @@ describe('combineAll operator', () => { const e2subs = ' ^-----!'; const expected = ' ------#'; - const result = of(e1, e2).pipe(combineAll((x, y) => x + y)); + const result = of(e1, e2).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected, null, 'wokka wokka'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -364,7 +364,7 @@ describe('combineAll operator', () => { const e2subs = ' ^----!'; const expected = ' -----#'; - const result = of(e1, e2).pipe(combineAll((x, y) => x + y)); + const result = of(e1, e2).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected, null, 'wokka wokka'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -380,7 +380,7 @@ describe('combineAll operator', () => { const e2subs = ' ^--!'; const expected = ' ---#'; - const result = of(e1, e2).pipe(combineAll((x, y) => x + y)); + const result = of(e1, e2).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected, { a: 1, b: 2}, 'wokka wokka'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -396,7 +396,7 @@ describe('combineAll operator', () => { const e2subs = ' ^--!'; const expected = ' ---#'; - const result = of(e1, e2).pipe(combineAll((x, y) => x + y)); + const result = of(e1, e2).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected, null, 'wokka wokka'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -412,7 +412,7 @@ describe('combineAll operator', () => { const rightSubs = ' ^--------!'; const expected = ' ---------#'; - const result = of(left, right).pipe(combineAll((x, y) => x + y)); + const result = of(left, right).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected, null, 'bad things'); expectSubscriptions(left.subscriptions).toBe(leftSubs); @@ -428,7 +428,7 @@ describe('combineAll operator', () => { const rightSubs = ' ^------!'; const expected = ' ---------#'; - const result = of(left, right).pipe(combineAll((x, y) => x + y)); + const result = of(left, right).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected, null, 'bad things'); expectSubscriptions(left.subscriptions).toBe(leftSubs); @@ -444,7 +444,7 @@ describe('combineAll operator', () => { const e2subs = ' ^-----------!'; const expected = ' -----x-y-z--|'; - const result = of(e1, e2).pipe(combineAll((x, y) => x + y)); + const result = of(e1, e2).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected, { x: 'be', y: 'ce', z: 'cf' }); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -460,7 +460,7 @@ describe('combineAll operator', () => { const e2subs = ' ^-------------------!'; const expected = ' -----------x--y--z--|'; - const result = of(e1, e2).pipe(combineAll((x, y) => x + y)); + const result = of(e1, e2).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected, { x: 'cd', y: 'ce', z: 'cf' }); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -476,7 +476,7 @@ describe('combineAll operator', () => { const rightSubs = ' ^--------!'; const expected = ' ---------#'; - const result = of(left, right).pipe(combineAll((x, y) => x + y)); + const result = of(left, right).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected, null, 'jenga'); expectSubscriptions(left.subscriptions).toBe(leftSubs); @@ -492,7 +492,7 @@ describe('combineAll operator', () => { const rightSubs = ' ^-------------------!'; const expected = ' -----------x--y--z--#'; - const result = of(left, right).pipe(combineAll((x, y) => x + y)); + const result = of(left, right).pipe(combineLatestAll((x, y) => x + y)); expectObservable(result).toBe(expected, { x: 'cd', y: 'ce', z: 'cf' }, 'dun dun dun'); expectSubscriptions(left.subscriptions).toBe(leftSubs); @@ -508,7 +508,7 @@ describe('combineAll operator', () => { const e2subs = ' ^--!'; const expected = ' ---#'; - const result = of(e1, e2).pipe(combineAll((x, y) => { throw 'ha ha ' + x + ', ' + y; })); + const result = of(e1, e2).pipe(combineLatestAll((x, y) => { throw 'ha ha ' + x + ', ' + y; })); expectObservable(result).toBe(expected, null, 'ha ha b, d'); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -520,7 +520,7 @@ describe('combineAll operator', () => { const a = of(1, 2, 3); const b = of(4, 5, 6, 7, 8); const expected = [[3, 4], [3, 5], [3, 6], [3, 7], [3, 8]]; - of(a, b).pipe(combineAll()).subscribe((vals) => { + of(a, b).pipe(combineLatestAll()).subscribe((vals) => { expect(vals).to.deep.equal(expected.shift()); }, null, () => { expect(expected.length).to.equal(0); @@ -533,7 +533,7 @@ describe('combineAll operator', () => { const b = of(4, 5, 6, 7, 8, queueScheduler); const r = [[1, 4], [2, 4], [2, 5], [3, 5], [3, 6], [3, 7], [3, 8]]; - of(a, b, queueScheduler).pipe(combineAll()) + of(a, b, queueScheduler).pipe(combineLatestAll()) .subscribe((vals) => { expect(vals).to.deep.equal(r.shift()); }, null, () => { diff --git a/spec/operators/index-spec.ts b/spec/operators/index-spec.ts index 16e0c3e279..ad9251b364 100644 --- a/spec/operators/index-spec.ts +++ b/spec/operators/index-spec.ts @@ -12,6 +12,7 @@ describe('operators/index', () => { expect(index.bufferWhen).to.exist; expect(index.catchError).to.exist; expect(index.combineAll).to.exist; + expect(index.combineLatestAll).to.exist; expect(index.concatAll).to.exist; expect(index.concatMap).to.exist; expect(index.concatMapTo).to.exist; @@ -46,6 +47,7 @@ describe('operators/index', () => { expect(index.max).to.exist; expect(index.mergeAll).to.exist; expect(index.mergeMap).to.exist; + expect(index.flatMap).to.exist; expect(index.mergeMap).to.exist; expect(index.mergeMapTo).to.exist; expect(index.mergeScan).to.exist; diff --git a/src/internal/observable/combineLatest.ts b/src/internal/observable/combineLatest.ts index 49f963465d..894b127dcf 100644 --- a/src/internal/observable/combineLatest.ts +++ b/src/internal/observable/combineLatest.ts @@ -188,19 +188,19 @@ export function combineLatest< ): Observable; // With a scheduler (deprecated) -/** @deprecated The scheduler argument is deprecated, use scheduled and combineAll. Details: https://rxjs.dev/deprecations/scheduler-argument */ +/** @deprecated The scheduler argument is deprecated, use scheduled and combineLatestAll. Details: https://rxjs.dev/deprecations/scheduler-argument */ export function combineLatest>(sources: [O1], scheduler: SchedulerLike): Observable<[ObservedValueOf]>; -/** @deprecated The scheduler argument is deprecated, use scheduled and combineAll. Details: https://rxjs.dev/deprecations/scheduler-argument */ +/** @deprecated The scheduler argument is deprecated, use scheduled and combineLatestAll. Details: https://rxjs.dev/deprecations/scheduler-argument */ export function combineLatest, O2 extends ObservableInput>( sources: [O1, O2], scheduler: SchedulerLike ): Observable<[ObservedValueOf, ObservedValueOf]>; -/** @deprecated The scheduler argument is deprecated, use scheduled and combineAll. Details: https://rxjs.dev/deprecations/scheduler-argument */ +/** @deprecated The scheduler argument is deprecated, use scheduled and combineLatestAll. Details: https://rxjs.dev/deprecations/scheduler-argument */ export function combineLatest, O2 extends ObservableInput, O3 extends ObservableInput>( sources: [O1, O2, O3], scheduler: SchedulerLike ): Observable<[ObservedValueOf, ObservedValueOf, ObservedValueOf]>; -/** @deprecated The scheduler argument is deprecated, use scheduled and combineAll. Details: https://rxjs.dev/deprecations/scheduler-argument */ +/** @deprecated The scheduler argument is deprecated, use scheduled and combineLatestAll. Details: https://rxjs.dev/deprecations/scheduler-argument */ export function combineLatest< O1 extends ObservableInput, O2 extends ObservableInput, @@ -210,7 +210,7 @@ export function combineLatest< sources: [O1, O2, O3, O4], scheduler: SchedulerLike ): Observable<[ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf]>; -/** @deprecated The scheduler argument is deprecated, use scheduled and combineAll. Details: https://rxjs.dev/deprecations/scheduler-argument */ +/** @deprecated The scheduler argument is deprecated, use scheduled and combineLatestAll. Details: https://rxjs.dev/deprecations/scheduler-argument */ export function combineLatest< O1 extends ObservableInput, O2 extends ObservableInput, @@ -221,7 +221,7 @@ export function combineLatest< sources: [O1, O2, O3, O4, O5], scheduler: SchedulerLike ): Observable<[ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf]>; -/** @deprecated The scheduler argument is deprecated, use scheduled and combineAll. Details: https://rxjs.dev/deprecations/scheduler-argument */ +/** @deprecated The scheduler argument is deprecated, use scheduled and combineLatestAll. Details: https://rxjs.dev/deprecations/scheduler-argument */ export function combineLatest< O1 extends ObservableInput, O2 extends ObservableInput, @@ -235,7 +235,7 @@ export function combineLatest< ): Observable< [ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf] >; -/** @deprecated The scheduler argument is deprecated, use scheduled and combineAll. Details: https://rxjs.dev/deprecations/scheduler-argument */ +/** @deprecated The scheduler argument is deprecated, use scheduled and combineLatestAll. Details: https://rxjs.dev/deprecations/scheduler-argument */ export function combineLatest>(sources: O[], scheduler: SchedulerLike): Observable[]>; /** @deprecated Pass arguments in a single array instead `combineLatest([a, b, c])` */ @@ -444,7 +444,7 @@ export function combineLatest( * // BMI is 23.671253629592222 * ``` * - * @see {@link combineAll} + * @see {@link combineLatestAll} * @see {@link merge} * @see {@link withLatestFrom} * diff --git a/src/internal/operators/combineAll.ts b/src/internal/operators/combineAll.ts index 041ddac3ea..f5ccd1dce5 100644 --- a/src/internal/operators/combineAll.ts +++ b/src/internal/operators/combineAll.ts @@ -1,56 +1,6 @@ -import { combineLatest } from '../observable/combineLatest'; -import { OperatorFunction, ObservableInput } from '../types'; -import { joinAllInternals } from './joinAllInternals'; +import { combineLatestAll } from './combineLatestAll'; -export function combineAll(): OperatorFunction, T[]>; -export function combineAll(): OperatorFunction; -export function combineAll(project: (...values: T[]) => R): OperatorFunction, R>; -export function combineAll(project: (...values: Array) => R): OperatorFunction; /** - * Flattens an Observable-of-Observables by applying {@link combineLatest} when the Observable-of-Observables completes. - * - * ![](combineAll.png) - * - * `combineAll` takes an Observable of Observables, and collects all Observables from it. Once the outer Observable completes, - * it subscribes to all collected Observables and combines their values using the {@link combineLatest} strategy, such that: - * - * * Every time an inner Observable emits, the output Observable emits - * * When the returned observable emits, it emits all of the latest values by: - * * If a `project` function is provided, it is called with each recent value from each inner Observable in whatever order they - * arrived, and the result of the `project` function is what is emitted by the output Observable. - * * If there is no `project` function, an array of all the most recent values is emitted by the output Observable. - * - * --- - * - * ## Examples - * - * ### Map two click events to a finite interval Observable, then apply `combineAll` - * - * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { map, combineAll, take } from 'rxjs/operators'; - * - * const clicks = fromEvent(document, 'click'); - * const higherOrder = clicks.pipe( - * map(ev => - * interval(Math.random() * 2000).pipe(take(3)) - * ), - * take(2) - * ); - * const result = higherOrder.pipe( - * combineAll() - * ); - * - * result.subscribe(x => console.log(x)); - * ``` - * - * @see {@link combineLatest} - * @see {@link combineLatestWith} - * @see {@link mergeAll} - * - * @param project optional function to map the most recent values from each inner Observable into a new result. - * Takes each of the most recent values from each collected inner Observable as arguments, in order. + * @deprecated renamed. Use {@link combineLatestAll}. */ -export function combineAll(project?: (...values: Array) => R) { - return joinAllInternals(combineLatest, project); -} +export const combineAll = combineLatestAll; diff --git a/src/internal/operators/combineLatestAll.ts b/src/internal/operators/combineLatestAll.ts new file mode 100644 index 0000000000..d9e4bf1074 --- /dev/null +++ b/src/internal/operators/combineLatestAll.ts @@ -0,0 +1,56 @@ +import { combineLatest } from '../observable/combineLatest'; +import { OperatorFunction, ObservableInput } from '../types'; +import { joinAllInternals } from './joinAllInternals'; + +export function combineLatestAll(): OperatorFunction, T[]>; +export function combineLatestAll(): OperatorFunction; +export function combineLatestAll(project: (...values: T[]) => R): OperatorFunction, R>; +export function combineLatestAll(project: (...values: Array) => R): OperatorFunction; +/** + * Flattens an Observable-of-Observables by applying {@link combineLatest} when the Observable-of-Observables completes. + * + * ![](combineLatestAll.png) + * + * `combineLatestAll` takes an Observable of Observables, and collects all Observables from it. Once the outer Observable completes, + * it subscribes to all collected Observables and combines their values using the {@link combineLatest} strategy, such that: + * + * * Every time an inner Observable emits, the output Observable emits + * * When the returned observable emits, it emits all of the latest values by: + * * If a `project` function is provided, it is called with each recent value from each inner Observable in whatever order they + * arrived, and the result of the `project` function is what is emitted by the output Observable. + * * If there is no `project` function, an array of all the most recent values is emitted by the output Observable. + * + * --- + * + * ## Examples + * + * ### Map two click events to a finite interval Observable, then apply `combineLatestAll` + * + * ```ts + * import { fromEvent, interval } from 'rxjs'; + * import { map, combineLatestAll, take } from 'rxjs/operators'; + * + * const clicks = fromEvent(document, 'click'); + * const higherOrder = clicks.pipe( + * map(ev => + * interval(Math.random() * 2000).pipe(take(3)) + * ), + * take(2) + * ); + * const result = higherOrder.pipe( + * combineLatestAll() + * ); + * + * result.subscribe(x => console.log(x)); + * ``` + * + * @see {@link combineLatest} + * @see {@link combineLatestWith} + * @see {@link mergeAll} + * + * @param project optional function to map the most recent values from each inner Observable into a new result. + * Takes each of the most recent values from each collected inner Observable as arguments, in order. + */ +export function combineLatestAll(project?: (...values: Array) => R) { + return joinAllInternals(combineLatest, project); +} diff --git a/src/internal/operators/concatAll.ts b/src/internal/operators/concatAll.ts index 3d9cc88ea5..3bfe06485a 100644 --- a/src/internal/operators/concatAll.ts +++ b/src/internal/operators/concatAll.ts @@ -1,4 +1,3 @@ - import { mergeAll } from './mergeAll'; import { OperatorFunction, ObservableInput, ObservedValueOf } from '../types'; @@ -48,11 +47,11 @@ export function concatAll(): OperatorFunction; * // one click = 1000ms-> 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3 * ``` * - * @see {@link combineAll} + * @see {@link combineLatestAll} * @see {@link concat} * @see {@link concatMap} * @see {@link concatMapTo} - * @see {@link exhaust} + * @see {@link exhaustAll} * @see {@link mergeAll} * @see {@link switchAll} * @see {@link switchMap} diff --git a/src/internal/operators/exhaustAll.ts b/src/internal/operators/exhaustAll.ts index 741efe767f..d842b5a996 100644 --- a/src/internal/operators/exhaustAll.ts +++ b/src/internal/operators/exhaustAll.ts @@ -38,7 +38,7 @@ export function exhaustAll(): OperatorFunction; * result.subscribe(x => console.log(x)); * ``` * - * @see {@link combineAll} + * @see {@link combineLatestAll} * @see {@link concatAll} * @see {@link switchAll} * @see {@link switchMap} @@ -79,4 +79,4 @@ export function exhaustAll(): OperatorFunction { /** * @deprecated renamed. Use {@link exhaustAll}. */ -export const exhaust = exhaustAll; \ No newline at end of file +export const exhaust = exhaustAll; diff --git a/src/internal/operators/joinAllInternals.ts b/src/internal/operators/joinAllInternals.ts index 73d62fc1c3..74876e9b78 100644 --- a/src/internal/operators/joinAllInternals.ts +++ b/src/internal/operators/joinAllInternals.ts @@ -10,7 +10,7 @@ import { toArray } from './toArray'; * Collects all of the inner sources from source observable. Then, once the * source completes, joins the values using the given static. * - * This is used for {@link combineAll} and {@link zipAll} which both have the + * This is used for {@link combineLatestAll} and {@link zipAll} which both have the * same behavior of collecting all inner observables, then operating on them. * * @param joinFn The type of static join to apply to the sources collected diff --git a/src/internal/operators/mergeAll.ts b/src/internal/operators/mergeAll.ts index 7133709fcf..35c3ad07d5 100644 --- a/src/internal/operators/mergeAll.ts +++ b/src/internal/operators/mergeAll.ts @@ -42,9 +42,9 @@ import { OperatorFunction, ObservableInput, ObservedValueOf } from '../types'; * firstOrder.subscribe(x => console.log(x)); * ``` * - * @see {@link combineAll} + * @see {@link combineLatestAll} * @see {@link concatAll} - * @see {@link exhaust} + * @see {@link exhaustAll} * @see {@link merge} * @see {@link mergeMap} * @see {@link mergeMapTo} diff --git a/src/internal/operators/switchAll.ts b/src/internal/operators/switchAll.ts index 08ea163598..f6ae5f9d5a 100644 --- a/src/internal/operators/switchAll.ts +++ b/src/internal/operators/switchAll.ts @@ -1,4 +1,4 @@ -import {OperatorFunction, ObservableInput, ObservedValueOf} from '../types'; +import { OperatorFunction, ObservableInput, ObservedValueOf } from '../types'; import { switchMap } from './switchMap'; import { identity } from '../util/identity'; @@ -51,9 +51,9 @@ export function switchAll>(): OperatorFunction