Skip to content

Commit

Permalink
feat: rename and alias combineLatest as combineLatestAll for cons…
Browse files Browse the repository at this point in the history
…istency (#6079)

* chore: rename and alias comblineLatestAll

Closes #4590

* chore: update api_guardian

* chore: update docs and test
  • Loading branch information
cartant authored Mar 8, 2021
1 parent 8128b4c commit 42cee80
Show file tree
Hide file tree
Showing 16 changed files with 166 additions and 171 deletions.
10 changes: 6 additions & 4 deletions api_guard/dist/types/operators/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ export declare function bufferWhen<T>(closingSelector: () => ObservableInput<any

export declare function catchError<T, O extends ObservableInput<any>>(selector: (err: any, caught: Observable<T>) => O): OperatorFunction<T, T | ObservedValueOf<O>>;

export declare function combineAll<T>(): OperatorFunction<ObservableInput<T>, T[]>;
export declare function combineAll<T>(): OperatorFunction<any, T[]>;
export declare function combineAll<T, R>(project: (...values: T[]) => R): OperatorFunction<ObservableInput<T>, R>;
export declare function combineAll<R>(project: (...values: Array<any>) => R): OperatorFunction<any, R>;
export declare const combineAll: typeof combineLatestAll;

export declare function combineLatest<T, R>(project: (v1: T) => R): OperatorFunction<T, R>;
export declare function combineLatest<T, T2, R>(v2: ObservableInput<T2>, project: (v1: T, v2: T2) => R): OperatorFunction<T, R>;
Expand All @@ -36,6 +33,11 @@ export declare function combineLatest<T, R>(...observables: Array<ObservableInpu
export declare function combineLatest<T, R>(array: ObservableInput<T>[]): OperatorFunction<T, Array<T>>;
export declare function combineLatest<T, TOther, R>(array: ObservableInput<TOther>[], project: (v1: T, ...values: Array<TOther>) => R): OperatorFunction<T, R>;

export declare function combineLatestAll<T>(): OperatorFunction<ObservableInput<T>, T[]>;
export declare function combineLatestAll<T>(): OperatorFunction<any, T[]>;
export declare function combineLatestAll<T, R>(project: (...values: T[]) => R): OperatorFunction<ObservableInput<T>, R>;
export declare function combineLatestAll<R>(project: (...values: Array<any>) => R): OperatorFunction<any, R>;

export declare function combineLatestWith<T, A extends readonly unknown[]>(...otherSources: [...ObservableInputTuple<A>]): OperatorFunction<T, Cons<T, A>>;

export declare function concat<T>(scheduler?: SchedulerLike): MonoTypeOperatorFunction<T>;
Expand Down
52 changes: 19 additions & 33 deletions docs_app/content/deprecations/scheduler-argument.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,74 +28,60 @@ 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`

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));
```
4 changes: 2 additions & 2 deletions docs_app/content/guide/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 0 additions & 23 deletions spec-dtslint/operators/combineAll-spec.ts

This file was deleted.

23 changes: 23 additions & 0 deletions spec-dtslint/operators/combineLatestAll-spec.ts
Original file line number Diff line number Diff line change
@@ -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<number[]>
});

it('should infer correctly with the projector', () => {
const o = of([1, 2, 3]).pipe(combineLatestAll((values: number) => ['x', 'y', 'z'])); // $ExpectType Observable<string[]>
});

it('is possible to make the projector have an `any` type', () => {
const o = of([1, 2, 3]).pipe(combineLatestAll<string[]>(values => ['x', 'y', 'z'])); // $ExpectType Observable<string[]>
});

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<number[]>(values => ['x', 'y', 'z'])); // $ExpectError
});
Loading

0 comments on commit 42cee80

Please sign in to comment.