Skip to content

Commit

Permalink
feat(never): always return the same instance (#3249)
Browse files Browse the repository at this point in the history
- never always returns the same Observable instance
- Remove NeverObservable
- never return value now typed as `Observable<never>` (lol)

BREAKING CHANGE: `never()` always returns the same instance
BREAKING CHANGE: TypeScript typing for `never()` is now `Observable<never>` and the function no longer requires a generic type.
  • Loading branch information
benlesh authored Jan 22, 2018
1 parent 1548393 commit d57fa52
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 61 deletions.
15 changes: 9 additions & 6 deletions spec/observables/never-spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import * as Rx from '../../src/Rx';
import { never } from '../../src/create';
import { expect } from 'chai';
import marbleTestingSignature = require('../helpers/marble-testing'); // tslint:disable-line:no-require-imports

declare const { asDiagram };
declare const asDiagram: any;
declare const expectObservable: typeof marbleTestingSignature.expectObservable;

const Observable = Rx.Observable;

/** @test {never} */
describe('Observable.never', () => {
describe('never', () => {
asDiagram('never')('should create a cold observable that never emits', () => {
const expected = '-';
const e1 = Observable.never();
const e1 = never();
expectObservable(e1).toBe(expected);
});

it('should return the same instance every time', () => {
expect(never()).to.equal(never());
});
});
53 changes: 0 additions & 53 deletions src/internal/observable/NeverObservable.ts

This file was deleted.

41 changes: 39 additions & 2 deletions src/internal/observable/never.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
import { NeverObservable } from './NeverObservable';
import { Observable } from '../Observable';
import { noop } from '../util/noop';

export const never = NeverObservable.create;
/** @internal */
export const NEVER = new Observable<never>(noop);

/**
* Creates an Observable that emits no items to the Observer.
*
* <span class="informal">An Observable that never emits anything.</span>
*
* <img src="./img/never.png" width="100%">
*
* This static operator is useful for creating a simple Observable that emits
* neither values nor errors nor the completion notification. It can be used
* for testing purposes or for composing with other Observables. Please note
* that by never emitting a complete notification, this Observable keeps the
* subscription from being disposed automatically. Subscriptions need to be
* manually disposed.
*
* @example <caption>Emit the number 7, then never emit anything else (not even complete).</caption>
* function info() {
* console.log('Will not be called');
* }
* var result = Rx.Observable.never().startWith(7);
* result.subscribe(x => console.log(x), info, info);
*
* @see {@link create}
* @see {@link empty}
* @see {@link of}
* @see {@link throw}
*
* @return {Observable} A "never" Observable: never emits anything.
* @static true
* @name never
* @owner Observable
*/
export function never(): Observable<never> {
return NEVER;
}

0 comments on commit d57fa52

Please sign in to comment.