Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3451 from jasonaden/v6_forward_compat
V6 forward compatibility
- Loading branch information
Showing
17 changed files
with
361 additions
and
18 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
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 |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { expect } from 'chai'; | ||
import { cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing'; | ||
import * as Rx from '../../dist/package/Rx'; | ||
|
||
/** @test {timeout} */ | ||
describe('throwIfEmpty', () => { | ||
describe('with errorFactory', () => { | ||
it('should throw if empty', () => { | ||
const error = new Error('So empty inside'); | ||
let thrown: any; | ||
|
||
Rx.Observable.empty().throwIfEmpty(() => error) | ||
.subscribe({ | ||
error(err) { | ||
thrown = err; | ||
} | ||
}); | ||
|
||
expect(thrown).to.equal(error); | ||
}); | ||
|
||
it('should NOT throw if NOT empty', () => { | ||
const error = new Error('So empty inside'); | ||
let thrown: any; | ||
|
||
Rx.Observable.of('test').throwIfEmpty(() => error) | ||
.subscribe({ | ||
error(err) { | ||
thrown = err; | ||
} | ||
}); | ||
|
||
// tslint:disable-next-line:no-unused-expression | ||
expect(thrown).to.be.undefined; | ||
}); | ||
|
||
it('should pass values through', () => { | ||
const source = cold('----a---b---c---|'); | ||
const sub1 = '^ !'; | ||
const expected = '----a---b---c---|'; | ||
expectObservable( | ||
source.throwIfEmpty(() => new Error('test')) | ||
).toBe(expected); | ||
expectSubscriptions(source.subscriptions).toBe([sub1]); | ||
}); | ||
|
||
it('should never when never', () => { | ||
const source = cold('-'); | ||
const sub1 = '^'; | ||
const expected = '-'; | ||
expectObservable( | ||
source.throwIfEmpty(() => new Error('test')) | ||
).toBe(expected); | ||
expectSubscriptions(source.subscriptions).toBe([sub1]); | ||
}); | ||
|
||
it('should error when empty', () => { | ||
const source = cold('----|'); | ||
const sub1 = '^ !'; | ||
const expected = '----#'; | ||
expectObservable( | ||
source.throwIfEmpty(() => new Error('test')) | ||
).toBe(expected, undefined, new Error('test')); | ||
expectSubscriptions(source.subscriptions).toBe([sub1]); | ||
}); | ||
}); | ||
|
||
describe('without errorFactory', () => { | ||
it('should throw EmptyError if empty', () => { | ||
let thrown: any; | ||
|
||
Rx.Observable.empty().throwIfEmpty() | ||
.subscribe({ | ||
error(err) { | ||
thrown = err; | ||
} | ||
}); | ||
|
||
expect(thrown).to.be.instanceof(Rx.EmptyError); | ||
}); | ||
|
||
it('should NOT throw if NOT empty', () => { | ||
let thrown: any; | ||
|
||
Rx.Observable.of('test').throwIfEmpty() | ||
.subscribe({ | ||
error(err) { | ||
thrown = err; | ||
} | ||
}); | ||
|
||
// tslint:disable-next-line:no-unused-expression | ||
expect(thrown).to.be.undefined; | ||
}); | ||
|
||
it('should pass values through', () => { | ||
const source = cold('----a---b---c---|'); | ||
const sub1 = '^ !'; | ||
const expected = '----a---b---c---|'; | ||
expectObservable(source.throwIfEmpty()).toBe(expected); | ||
expectSubscriptions(source.subscriptions).toBe([sub1]); | ||
}); | ||
|
||
it('should never when never', () => { | ||
const source = cold('-'); | ||
const sub1 = '^'; | ||
const expected = '-'; | ||
expectObservable(source.throwIfEmpty()).toBe(expected); | ||
expectSubscriptions(source.subscriptions).toBe([sub1]); | ||
}); | ||
|
||
it('should error when empty', () => { | ||
const source = cold('----|'); | ||
const sub1 = '^ !'; | ||
const expected = '----#'; | ||
expectObservable( | ||
source.throwIfEmpty() | ||
).toBe(expected, undefined, new Rx.EmptyError()); | ||
expectSubscriptions(source.subscriptions).toBe([sub1]); | ||
}); | ||
}); | ||
}); |
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
import { Observable } from '../../Observable'; | ||
import { throwIfEmpty } from '../../operator/throwIfEmpty'; | ||
|
||
Observable.prototype.throwIfEmpty = throwIfEmpty; | ||
|
||
declare module '../../Observable' { | ||
interface Observable<T> { | ||
throwIfEmpty: typeof throwIfEmpty; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { ajax } from './observable/dom/ajax'; | ||
export { AjaxRequest, AjaxResponse, AjaxError, AjaxTimeoutError } from './observable/dom/AjaxObservable'; |
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* Observable */ | ||
export { Observable } from './Observable'; | ||
export { ConnectableObservable } from './observable/ConnectableObservable'; | ||
export { Operator } from './Operator'; | ||
export { observable } from './symbol/observable'; | ||
|
||
/* Subjects */ | ||
export { Subject } from './Subject'; | ||
export { BehaviorSubject } from './BehaviorSubject'; | ||
export { ReplaySubject } from './ReplaySubject'; | ||
export { AsyncSubject } from './AsyncSubject'; | ||
|
||
/* Schedulers */ | ||
export { asap as asapScheduler } from './scheduler/asap'; | ||
export { async as asyncScheduler } from './scheduler/async'; | ||
export { queue as queueScheduler } from './scheduler/queue'; | ||
export { animationFrame as animationFrameScheduler } from './scheduler/animationFrame'; | ||
export { VirtualTimeScheduler, VirtualAction } from './scheduler/VirtualTimeScheduler'; | ||
|
||
/* Subscription */ | ||
export { Subscription } from './Subscription'; | ||
export { Subscriber } from './Subscriber'; | ||
|
||
/* Notification */ | ||
export { Notification } from './Notification'; | ||
|
||
/* Utils */ | ||
export { pipe } from './util/pipe'; | ||
export { noop } from './util/noop'; | ||
export { identity } from './util/identity'; | ||
|
||
/* Error types */ | ||
export { ArgumentOutOfRangeError } from './util/ArgumentOutOfRangeError'; | ||
export { EmptyError } from './util/EmptyError'; | ||
export { ObjectUnsubscribedError } from './util/ObjectUnsubscribedError'; | ||
export { UnsubscriptionError } from './util/UnsubscriptionError'; | ||
export { TimeoutError } from './util/TimeoutError'; | ||
|
||
/* Static observable creation exports */ | ||
export { bindCallback } from './observable/bindCallback'; | ||
export { bindNodeCallback } from './observable/bindNodeCallback'; | ||
export { combineLatest } from './observable/combineLatest'; | ||
export { concat } from './observable/concat'; | ||
export { defer } from './observable/defer'; | ||
export { empty } from './observable/empty'; | ||
export { forkJoin } from './observable/forkJoin'; | ||
export { from } from './observable/from'; | ||
export { fromEvent } from './observable/fromEvent'; | ||
export { fromEventPattern } from './observable/fromEventPattern'; | ||
export { generate } from './observable/generate'; | ||
export { _if as iif } from './observable/if'; | ||
export { interval } from './observable/interval'; | ||
export { merge } from './observable/merge'; | ||
export { of } from './observable/of'; | ||
export { onErrorResumeNext } from './observable/onErrorResumeNext'; | ||
export { pairs } from './observable/pairs'; | ||
export { race } from './observable/race'; | ||
export { range } from './observable/range'; | ||
export { _throw as throwError } from './observable/throw'; | ||
export { timer } from './observable/timer'; | ||
export { using } from './observable/using'; | ||
export { zip } from './observable/zip'; | ||
|
||
/* Constants */ | ||
export { EMPTY } from './observable/empty'; | ||
export { NEVER } from './observable/never'; | ||
|
||
/* Types */ | ||
export * from './types'; | ||
|
||
/* Config */ | ||
// export { config } from './config'; |
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,11 @@ | ||
import { EmptyObservable } from './EmptyObservable'; | ||
import { Observable } from '../Observable'; | ||
import { EmptyObservable } from './EmptyObservable'; | ||
|
||
/** | ||
* Observable instance always typed to `never` to be forward compatible with RxJS v6. Simlar | ||
* to calling {@link empty} without a {@link Scheduler}. It is preferrable to use this over | ||
* `empty()`. | ||
*/ | ||
export const EMPTY = new Observable<never>(); | ||
|
||
export const empty = EmptyObservable.create; |
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,31 @@ | ||
import { NeverObservable } from './NeverObservable'; | ||
import { Observable } from '../Observable'; | ||
import { NeverObservable } from './NeverObservable'; | ||
import { noop } from '../util/noop'; | ||
|
||
/** | ||
* An Observable that emits no items to the Observer and never completes. Compatible with | ||
* RxJS v6 API. | ||
* | ||
* <img src="./img/never.png" width="100%"> | ||
* | ||
* 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 = NEVER.startWith(7); | ||
* result.subscribe(x => console.log(x), info, info); | ||
* | ||
* @see {@link create} | ||
* @see {@link EMPTY} | ||
* @see {@link of} | ||
* @see {@link throwError} | ||
*/ | ||
export const NEVER = new Observable<never>(noop); | ||
|
||
export const never = NeverObservable.create; |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Observable } from '../Observable'; | ||
import { throwIfEmpty as higherOrder, defaultErrorFactory } from '../operators/throwIfEmpty'; | ||
|
||
export function throwIfEmpty<T>(this: Observable<T>, | ||
errorFactory: (() => any) = defaultErrorFactory): Observable<T> { | ||
return higherOrder(errorFactory)(this) as Observable<T>; | ||
} |
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
Oops, something went wrong.