-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(never): always return the same instance (#3249)
- 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
Showing
3 changed files
with
48 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |