Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(endWith): removed deprecated endWith(value, scheduler) call pattern #7163

Merged
merged 4 commits into from Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 1 addition & 5 deletions 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<A>
});

it('should infer type for N values', () => {
const r0 = of(a).pipe(endWith()); // $ExpectType Observable<A>
const r1 = of(a).pipe(endWith(b)); // $ExpectType Observable<A | B>
Expand Down
22 changes: 0 additions & 22 deletions spec/operators/endWith-spec.ts
Expand Up @@ -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<number>((subscriber) => {
Expand Down
26 changes: 8 additions & 18 deletions src/internal/operators/endWith.ts
@@ -1,25 +1,13 @@
/** 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<T>(scheduler: SchedulerLike): MonoTypeOperatorFunction<T>;
/** @deprecated The `scheduler` parameter will be removed in v8. Use `scheduled` and `concatAll`. Details: https://rxjs.dev/deprecations/scheduler-argument */
export function endWith<T, A extends unknown[] = T[]>(
...valuesAndScheduler: [...A, SchedulerLike]
): OperatorFunction<T, T | ValueFromArray<A>>;

export function endWith<T, A extends unknown[] = T[]>(...values: A): OperatorFunction<T, T | ValueFromArray<A>>;
import { fromArrayLike } from '../observable/innerFrom';
import { OperatorFunction, ValueFromArray } from '../types';
import { operate } from '../util/lift';
import { concatAll } from './concatAll';

/**
* 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}
*
Expand Down Expand Up @@ -63,6 +51,8 @@ export function endWith<T, A extends unknown[] = T[]>(...values: A): OperatorFun
* source, then synchronously emits the provided value(s) immediately after the
* source completes.
*/
export function endWith<T>(...values: Array<T | SchedulerLike>): MonoTypeOperatorFunction<T> {
return (source: Observable<T>) => concat(source, of(...values)) as Observable<T>;
export function endWith<T, A extends readonly unknown[] = T[]>(...values: A): OperatorFunction<T, T | ValueFromArray<A>> {
return operate((source, subscriber) => {
concatAll()(fromArrayLike([source, fromArrayLike(values)])).subscribe(subscriber);
});
}