Skip to content

Commit

Permalink
feat(empty): removed deprecated empty function.
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `empty` no longer exists, use `EMPTY` or if you need scheduling, `scheduled`.
  • Loading branch information
benlesh committed Jan 11, 2022
1 parent d79fd00 commit 9bab0d0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 55 deletions.
10 changes: 5 additions & 5 deletions spec/Observable-spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -224,7 +224,7 @@ describe('Observable', () => {

expect(unsubscribeCalled).to.be.false;

empty().subscribe();
EMPTY.subscribe();

expect(unsubscribeCalled).to.be.false;
});
Expand All @@ -247,7 +247,7 @@ describe('Observable', () => {

expect(unsubscribeCalled).to.be.false;

empty().subscribe(observer);
EMPTY.subscribe(observer);

expect(unsubscribeCalled).to.be.false;
});
Expand Down Expand Up @@ -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(<any>{});
EMPTY.subscribe(<any>{});
}).not.to.throw();
});

Expand Down
1 change: 0 additions & 1 deletion spec/index-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
39 changes: 5 additions & 34 deletions spec/observables/empty-spec.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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;
});
});
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
14 changes: 0 additions & 14 deletions src/internal/observable/empty.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Observable } from '../Observable';
import { SchedulerLike } from '../types';

/**
* A simple Observable that emits no items to the Observer and immediately
Expand Down Expand Up @@ -64,16 +63,3 @@ import { SchedulerLike } from '../types';
* @see {@link throwError}
*/
export const EMPTY = new Observable<never>((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<never>((subscriber) => scheduler.schedule(() => subscriber.complete()));
}

0 comments on commit 9bab0d0

Please sign in to comment.