Skip to content

Commit

Permalink
feat(throwError): removed deprecated throwError(errorFactory, schedul…
Browse files Browse the repository at this point in the history
…er) call pattern

BREAKING CHANGE: `throwError(errorFactory, scheduler)` call pattern is no longer available. [Read more](https://rxjs.dev/deprecations/scheduler-argument).
  • Loading branch information
demensky committed Oct 30, 2022
1 parent ac0ed79 commit aa69074
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 32 deletions.
1 change: 0 additions & 1 deletion api_guard/dist/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,6 @@ export interface ThrottleConfig {
export declare function throttleTime<T>(duration: number, scheduler?: SchedulerLike, config?: import("./throttle").ThrottleConfig): MonoTypeOperatorFunction<T>;

export declare function throwError(errorFactory: () => any): Observable<never>;
export declare function throwError(errorFactory: () => any, scheduler: SchedulerLike): Observable<never>;

export declare function throwIfEmpty<T>(errorFactory?: () => any): MonoTypeOperatorFunction<T>;

Expand Down
6 changes: 1 addition & 5 deletions spec-dtslint/observables/throwError-spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { throwError, animationFrameScheduler } from 'rxjs';
import { throwError } from 'rxjs';

it('should error for incorrect errorFactory', () => {
const a = throwError(1); // $ExpectError
Expand All @@ -12,7 +12,3 @@ it('should accept any type and return never observable with support of factory',
const c = throwError(() => ({ a: 1 })); // $ExpectType Observable<never>
const d = throwError(() => ({ a: 2 })); // $ExpectType Observable<never>
});

it('should support a factory and a scheduler', () => {
const a = throwError(() => 1, animationFrameScheduler); // $ExpectType Observable<never>
});
8 changes: 0 additions & 8 deletions spec/observables/throwError-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ describe('throwError', () => {
});
});

it('should accept scheduler', () => {
rxTest.run(({ expectObservable }) => {
const e = throwError(() => 'error', rxTest);

expectObservable(e).toBe('#');
});
});

it('should accept a factory function', () => {
let calls = 0;
let errors: any[] = [];
Expand Down
22 changes: 4 additions & 18 deletions src/internal/observable/throwError.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Observable } from '../Observable';
import { Subscriber } from '../Subscriber';
import { SchedulerLike } from '../types';

/**
* Creates an observable that will create an error instance and push it to the consumer as an error
Expand Down Expand Up @@ -94,20 +92,8 @@ import { SchedulerLike } from '../types';
*
* @param errorFactory A factory function that will create the error instance that is pushed.
*/
export function throwError(errorFactory: () => any): Observable<never>;

/**
* Notifies the consumer of an error using a given scheduler by scheduling it at delay `0` upon subscription.
*
* @param errorFactory An error instance or error factory
* @param scheduler A scheduler to use to schedule the error notification
* @deprecated The `scheduler` parameter will be removed in v8.
* Use `throwError` in combination with {@link observeOn}: `throwError(() => new Error('test')).pipe(observeOn(scheduler));`.
* Details: https://rxjs.dev/deprecations/scheduler-argument
*/
export function throwError(errorFactory: () => any, scheduler: SchedulerLike): Observable<never>;

export function throwError(errorFactory: () => any, scheduler?: SchedulerLike): Observable<never> {
const init = (subscriber: Subscriber<never>) => subscriber.error(errorFactory());
return new Observable(scheduler ? (subscriber) => scheduler.schedule(init as any, 0, subscriber) : init);
export function throwError(errorFactory: () => any): Observable<never> {
return new Observable((subscriber) => {
subscriber.error(errorFactory());
});
}

0 comments on commit aa69074

Please sign in to comment.