diff --git a/spec/Observable-spec.ts b/spec/Observable-spec.ts index d9b9fb6ef5..63f5c155ac 100644 --- a/spec/Observable-spec.ts +++ b/spec/Observable-spec.ts @@ -1,7 +1,7 @@ import { expect } from 'chai'; import * as sinon from 'sinon'; import { Observer, TeardownLogic } from '../src/internal/types'; -import { Observable, config, Subscription, noop, Subscriber, Operator, NEVER, Subject, of, throwError, empty } from 'rxjs'; +import { Observable, config, Subscription, noop, Subscriber, Operator, NEVER, Subject, of, throwError, EMPTY } from 'rxjs'; import { map, multicast, refCount, filter, count, tap, combineLatest, concat, merge, race, zip, catchError, concatMap, switchMap, publish, publishLast, publishBehavior, share, finalize} from 'rxjs/operators'; import { TestScheduler } from 'rxjs/testing'; import { observableMatcher } from './helpers/observableMatcher'; @@ -224,7 +224,7 @@ describe('Observable', () => { expect(unsubscribeCalled).to.be.false; - empty().subscribe(); + EMPTY.subscribe(); expect(unsubscribeCalled).to.be.false; }); @@ -247,7 +247,7 @@ describe('Observable', () => { expect(unsubscribeCalled).to.be.false; - empty().subscribe(observer); + EMPTY.subscribe(observer); expect(unsubscribeCalled).to.be.false; }); @@ -451,13 +451,13 @@ describe('Observable', () => { }, }; - empty().subscribe(o); + EMPTY.subscribe(o); } ); it('should accept an anonymous observer with no functions at all', () => { expect(() => { - empty().subscribe({}); + EMPTY.subscribe({}); }).not.to.throw(); }); diff --git a/spec/index-spec.ts b/spec/index-spec.ts index c21c2d1e7d..b4b23e246b 100644 --- a/spec/index-spec.ts +++ b/spec/index-spec.ts @@ -60,7 +60,6 @@ describe('index', () => { expect(index.combineLatest).to.exist; expect(index.concat).to.exist; expect(index.defer).to.exist; - expect(index.empty).to.exist; expect(index.forkJoin).to.exist; expect(index.from).to.exist; expect(index.fromEvent).to.exist; diff --git a/spec/observables/empty-spec.ts b/spec/observables/empty-spec.ts index e1587b77bb..291ba69e68 100644 --- a/spec/observables/empty-spec.ts +++ b/spec/observables/empty-spec.ts @@ -1,6 +1,6 @@ /** @prettier */ import { expect } from 'chai'; -import { empty, EMPTY } from 'rxjs'; +import { EMPTY } from 'rxjs'; import { TestScheduler } from 'rxjs/testing'; import { observableMatcher } from '../helpers/observableMatcher'; @@ -12,49 +12,20 @@ describe('empty', () => { rxTestScheduler = new TestScheduler(observableMatcher); }); - it('should return EMPTY', () => { - expect(empty()).to.equal(EMPTY); - }); - - it('should create a cold observable with only complete', () => { + it('should only complete', () => { rxTestScheduler.run(({ expectObservable }) => { const expected = '|'; - const e1 = empty(); - expectObservable(e1).toBe(expected); - }); - }); - - it('should return the same instance EMPTY', () => { - const s1 = empty(); - const s2 = empty(); - expect(s1).to.equal(s2); - }); - - it('should be synchronous by default', () => { - const source = empty(); - let hit = false; - source.subscribe({ - complete() { - hit = true; - }, + expectObservable(EMPTY).toBe(expected); }); - expect(hit).to.be.true; - }); - - it('should equal EMPTY', () => { - expect(empty()).to.equal(EMPTY); }); - it('should take a scheduler', () => { - const source = empty(rxTestScheduler); + it('should be synchronous', () => { let hit = false; - source.subscribe({ + EMPTY.subscribe({ complete() { hit = true; }, }); - expect(hit).to.be.false; - rxTestScheduler.flush(); expect(hit).to.be.true; }); }); diff --git a/src/index.ts b/src/index.ts index 759b3103af..a1225a1e19 100644 --- a/src/index.ts +++ b/src/index.ts @@ -67,7 +67,6 @@ export { combineLatest } from './internal/observable/combineLatest'; export { concat } from './internal/observable/concat'; export { connectable } from './internal/observable/connectable'; export { defer } from './internal/observable/defer'; -export { empty } from './internal/observable/empty'; export { forkJoin } from './internal/observable/forkJoin'; export { from } from './internal/observable/from'; export { fromEvent } from './internal/observable/fromEvent'; diff --git a/src/internal/observable/empty.ts b/src/internal/observable/empty.ts index 8f59e45a04..f7f77ab236 100644 --- a/src/internal/observable/empty.ts +++ b/src/internal/observable/empty.ts @@ -1,5 +1,4 @@ import { Observable } from '../Observable'; -import { SchedulerLike } from '../types'; /** * A simple Observable that emits no items to the Observer and immediately @@ -64,16 +63,3 @@ import { SchedulerLike } from '../types'; * @see {@link throwError} */ export const EMPTY = new Observable((subscriber) => subscriber.complete()); - -/** - * @param scheduler A {@link SchedulerLike} to use for scheduling - * the emission of the complete notification. - * @deprecated Replaced with the {@link EMPTY} constant or {@link scheduled} (e.g. `scheduled([], scheduler)`). Will be removed in v8. - */ -export function empty(scheduler?: SchedulerLike) { - return scheduler ? emptyScheduled(scheduler) : EMPTY; -} - -function emptyScheduled(scheduler: SchedulerLike) { - return new Observable((subscriber) => scheduler.schedule(() => subscriber.complete())); -}