From 6581e3b5c7bc978b7e291cc736a9928f26eef38d Mon Sep 17 00:00:00 2001 From: demensky Date: Sat, 21 Jan 2023 02:28:24 +0200 Subject: [PATCH 1/4] feat(endWith): removed deprecated `endWith(value, scheduler)` call pattern BREAKING CHANGE: `endWith(value, scheduler)` call pattern is no longer available. [Read more](https://rxjs.dev/deprecations/scheduler-argument). --- spec-dtslint/operators/endWith-spec.ts | 6 +----- spec/operators/endWith-spec.ts | 22 ---------------------- src/internal/operators/endWith.ts | 21 ++++----------------- 3 files changed, 5 insertions(+), 44 deletions(-) diff --git a/spec-dtslint/operators/endWith-spec.ts b/spec-dtslint/operators/endWith-spec.ts index cc3a7e9931..ae1acdbdf0 100644 --- a/spec-dtslint/operators/endWith-spec.ts +++ b/spec-dtslint/operators/endWith-spec.ts @@ -1,11 +1,7 @@ -import { of, asyncScheduler } from 'rxjs'; +import { of } from 'rxjs'; import { endWith } from 'rxjs/operators'; import { A, B, a, b, c, d, e, f, g, h } from '../helpers'; -it('should support a scheduler', () => { - const r = of(a).pipe(endWith(asyncScheduler)); // $ExpectType Observable -}); - it('should infer type for N values', () => { const r0 = of(a).pipe(endWith()); // $ExpectType Observable const r1 = of(a).pipe(endWith(b)); // $ExpectType Observable diff --git a/spec/operators/endWith-spec.ts b/spec/operators/endWith-spec.ts index 439c39691d..e259779217 100644 --- a/spec/operators/endWith-spec.ts +++ b/spec/operators/endWith-spec.ts @@ -178,28 +178,6 @@ describe('endWith', () => { }); }); - it('should accept scheduler as last argument with single value', () => { - testScheduler.run(({ hot, expectObservable, expectSubscriptions }) => { - const e1 = hot(' --a--| '); - const e1subs = ' ^----! '; - const expected = '--a--(x|)'; - - expectObservable(e1.pipe(endWith(defaultEndValue, testScheduler))).toBe(expected); - expectSubscriptions(e1.subscriptions).toBe(e1subs); - }); - }); - - it('should accept scheduler as last argument with multiple value', () => { - testScheduler.run(({ hot, expectObservable, expectSubscriptions }) => { - const e1 = hot(' -----a--| '); - const e1subs = ' ^-------! '; - const expected = '-----a--(yz|)'; - - expectObservable(e1.pipe(endWith('y', 'z', testScheduler))).toBe(expected); - expectSubscriptions(e1.subscriptions).toBe(e1subs); - }); - }); - it('should stop listening to a synchronous observable when unsubscribed', () => { const sideEffects: number[] = []; const synchronousObservable = new Observable((subscriber) => { diff --git a/src/internal/operators/endWith.ts b/src/internal/operators/endWith.ts index 436e5b301a..ebd22af2e5 100644 --- a/src/internal/operators/endWith.ts +++ b/src/internal/operators/endWith.ts @@ -1,25 +1,12 @@ /** prettier */ -import { Observable } from '../Observable'; import { concat } from '../observable/concat'; -import { of } from '../observable/of'; -import { MonoTypeOperatorFunction, SchedulerLike, OperatorFunction, ValueFromArray } from '../types'; - -/** @deprecated The `scheduler` parameter will be removed in v8. Use `scheduled` and `concatAll`. Details: https://rxjs.dev/deprecations/scheduler-argument */ -export function endWith(scheduler: SchedulerLike): MonoTypeOperatorFunction; -/** @deprecated The `scheduler` parameter will be removed in v8. Use `scheduled` and `concatAll`. Details: https://rxjs.dev/deprecations/scheduler-argument */ -export function endWith( - ...valuesAndScheduler: [...A, SchedulerLike] -): OperatorFunction>; - -export function endWith(...values: A): OperatorFunction>; +import { fromArrayLike } from '../observable/innerFrom'; +import { OperatorFunction, ValueFromArray } from '../types'; /** * Returns an observable that will emit all values from the source, then synchronously emit * the provided value(s) immediately after the source completes. * - * NOTE: Passing a last argument of a Scheduler is _deprecated_, and may result in incorrect - * types in TypeScript. - * * This is useful for knowing when an observable ends. Particularly when paired with an * operator like {@link takeUntil} * @@ -63,6 +50,6 @@ export function endWith(...values: A): OperatorFun * source, then synchronously emits the provided value(s) immediately after the * source completes. */ -export function endWith(...values: Array): MonoTypeOperatorFunction { - return (source: Observable) => concat(source, of(...values)) as Observable; +export function endWith(...values: A): OperatorFunction> { + return (source) => concat(source, fromArrayLike(values as readonly ValueFromArray[])); } From 48f0730eb9fcdda7ca145c5426eb26e8fc31ffc4 Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Fri, 20 Jan 2023 21:27:19 -0600 Subject: [PATCH 2/4] refactor(endWith): use concatAll and fromeArrayLike --- src/internal/operators/endWith.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/internal/operators/endWith.ts b/src/internal/operators/endWith.ts index ebd22af2e5..2f9f933026 100644 --- a/src/internal/operators/endWith.ts +++ b/src/internal/operators/endWith.ts @@ -1,7 +1,8 @@ /** prettier */ import { concat } from '../observable/concat'; import { fromArrayLike } from '../observable/innerFrom'; -import { OperatorFunction, ValueFromArray } from '../types'; +import { MonoTypeOperatorFunction, SchedulerLike, OperatorFunction, ValueFromArray } from '../types'; +import { concatAll } from './concatAll'; /** * Returns an observable that will emit all values from the source, then synchronously emit @@ -51,5 +52,5 @@ import { OperatorFunction, ValueFromArray } from '../types'; * source completes. */ export function endWith(...values: A): OperatorFunction> { - return (source) => concat(source, fromArrayLike(values as readonly ValueFromArray[])); + return (source) => concatAll()(fromArrayLike([source, ...values] as any)); } From e1115df1809a5dfaa6b11ccbfc8b2e4bd56dcb23 Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Fri, 20 Jan 2023 21:36:48 -0600 Subject: [PATCH 3/4] refactor: Use `operate`. Ensure variables are properly wrapped before `concat`-ing --- src/internal/operators/endWith.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/internal/operators/endWith.ts b/src/internal/operators/endWith.ts index 2f9f933026..d909325f0c 100644 --- a/src/internal/operators/endWith.ts +++ b/src/internal/operators/endWith.ts @@ -1,7 +1,7 @@ /** prettier */ -import { concat } from '../observable/concat'; import { fromArrayLike } from '../observable/innerFrom'; import { MonoTypeOperatorFunction, SchedulerLike, OperatorFunction, ValueFromArray } from '../types'; +import { operate } from '../util/lift'; import { concatAll } from './concatAll'; /** @@ -52,5 +52,7 @@ import { concatAll } from './concatAll'; * source completes. */ export function endWith(...values: A): OperatorFunction> { - return (source) => concatAll()(fromArrayLike([source, ...values] as any)); + return operate((source, subscriber) => { + concatAll()(fromArrayLike([source, fromArrayLike(values)])).subscribe(subscriber); + }); } From 38ef6687f31a1c01af331ebb50fcc8585289cf18 Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Fri, 20 Jan 2023 21:41:30 -0600 Subject: [PATCH 4/4] refactor: Remove unused declarations. Make lint happy --- src/internal/operators/endWith.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal/operators/endWith.ts b/src/internal/operators/endWith.ts index d909325f0c..df937ef6db 100644 --- a/src/internal/operators/endWith.ts +++ b/src/internal/operators/endWith.ts @@ -1,6 +1,6 @@ /** prettier */ import { fromArrayLike } from '../observable/innerFrom'; -import { MonoTypeOperatorFunction, SchedulerLike, OperatorFunction, ValueFromArray } from '../types'; +import { OperatorFunction, ValueFromArray } from '../types'; import { operate } from '../util/lift'; import { concatAll } from './concatAll';