-
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.
- Loading branch information
Showing
13 changed files
with
193 additions
and
116 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
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,124 @@ | ||
import { expect } from 'chai'; | ||
import { bindCallback } from '../dist/cjs/observable/bindCallback'; | ||
import { bindNodeCallback } from '../dist/cjs/observable/bindNodeCallback'; | ||
import { combineLatest } from '../dist/cjs/observable/combineLatest'; | ||
import { concat } from '../dist/cjs/observable/concat'; | ||
import { defer } from '../dist/cjs/observable/defer'; | ||
import { empty } from '../dist/cjs/observable/empty'; | ||
import { forkJoin } from '../dist/cjs/observable/forkJoin'; | ||
import { from } from '../dist/cjs/observable/from'; | ||
import { fromEvent } from '../dist/cjs/observable/fromEvent'; | ||
import { fromEventPattern } from '../dist/cjs/observable/fromEventPattern'; | ||
import { fromPromise } from '../dist/cjs/observable/fromPromise'; | ||
import { _if } from '../dist/cjs/observable/if'; | ||
import { interval } from '../dist/cjs/observable/interval'; | ||
import { merge } from '../dist/cjs/observable/merge'; | ||
import { never } from '../dist/cjs/observable/never'; | ||
import { of } from '../dist/cjs/observable/of'; | ||
import { onErrorResumeNext } from '../dist/cjs/observable/onErrorResumeNext'; | ||
import { pairs } from '../dist/cjs/observable/pairs'; | ||
import { race } from '../dist/cjs/observable/race'; | ||
import { range } from '../dist/cjs/observable/range'; | ||
import { _throw } from '../dist/cjs/observable/throw'; | ||
import { timer } from '../dist/cjs/observable/timer'; | ||
import { using } from '../dist/cjs/observable/using'; | ||
import { zip } from '../dist/cjs/observable/zip'; | ||
import * as Rx from '../dist/cjs/Rx'; | ||
|
||
describe('exports', () => { | ||
it('should have rxjs/observable/bindCallback', () => { | ||
expect(bindCallback).to.equal(Rx.Observable.bindCallback); | ||
}); | ||
|
||
it('should have rxjs/observable/bindNodeCallback', () => { | ||
expect(bindNodeCallback).to.equal(Rx.Observable.bindNodeCallback); | ||
}); | ||
|
||
it('should have rxjs/observable/combineLatest', () => { | ||
expect(combineLatest).to.equal(Rx.Observable.combineLatest); | ||
}); | ||
|
||
it('should have rxjs/observable/concat', () => { | ||
expect(concat).to.equal(Rx.Observable.concat); | ||
}); | ||
|
||
it('should have rxjs/observable/defer', () => { | ||
expect(defer).to.equal(Rx.Observable.defer); | ||
}); | ||
|
||
it('should have rxjs/observable/empty', () => { | ||
expect(empty).to.equal(Rx.Observable.empty); | ||
}); | ||
|
||
it('should have rxjs/observable/forkJoin', () => { | ||
expect(forkJoin).to.equal(Rx.Observable.forkJoin); | ||
}); | ||
|
||
it('should have rxjs/observable/from', () => { | ||
expect(from).to.equal(Rx.Observable.from); | ||
}); | ||
|
||
it('should have rxjs/observable/fromEvent', () => { | ||
expect(fromEvent).to.equal(Rx.Observable.fromEvent); | ||
}); | ||
|
||
it('should have rxjs/observable/fromEventPattern', () => { | ||
expect(fromEventPattern).to.equal(Rx.Observable.fromEventPattern); | ||
}); | ||
|
||
it('should have rxjs/observable/fromPromise', () => { | ||
expect(fromPromise).to.equal(Rx.Observable.fromPromise); | ||
}); | ||
|
||
it('should have rxjs/observable/if', () => { | ||
expect(_if).to.equal(Rx.Observable.if); | ||
}); | ||
|
||
it('should have rxjs/observable/interval', () => { | ||
expect(interval).to.equal(Rx.Observable.interval); | ||
}); | ||
|
||
it('should have rxjs/observable/merge', () => { | ||
expect(merge).to.equal(Rx.Observable.merge); | ||
}); | ||
|
||
it('should have rxjs/observable/never', () => { | ||
expect(never).to.equal(Rx.Observable.never); | ||
}); | ||
|
||
it('should have rxjs/observable/of', () => { | ||
expect(of).to.equal(Rx.Observable.of); | ||
}); | ||
|
||
it('should have rxjs/observable/onErrorResumeNext', () => { | ||
expect(onErrorResumeNext).to.equal(Rx.Observable.onErrorResumeNext); | ||
}); | ||
|
||
it('should have rxjs/observable/pairs', () => { | ||
expect(pairs).to.equal(Rx.Observable.pairs); | ||
}); | ||
|
||
it('should have rxjs/observable/race', () => { | ||
expect(race).to.equal(Rx.Observable.race); | ||
}); | ||
|
||
it('should have rxjs/observable/range', () => { | ||
expect(range).to.equal(Rx.Observable.range); | ||
}); | ||
|
||
it('should have rxjs/observable/throw', () => { | ||
expect(_throw).to.equal(Rx.Observable.throw); | ||
}); | ||
|
||
it('should have rxjs/observable/timer', () => { | ||
expect(timer).to.equal(Rx.Observable.timer); | ||
}); | ||
|
||
it('should have rxjs/observable/using', () => { | ||
expect(using).to.equal(Rx.Observable.using); | ||
}); | ||
|
||
it('should have rxjs/observable/zip', () => { | ||
expect(zip).to.equal(Rx.Observable.zip); | ||
}); | ||
}); |
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,10 +1,10 @@ | ||
import { Observable } from '../../Observable'; | ||
import { GenerateObservable } from '../../observable/GenerateObservable'; | ||
import { generate as staticGenerate } from '../../observable/generate'; | ||
|
||
Observable.generate = GenerateObservable.create; | ||
Observable.generate = staticGenerate; | ||
|
||
declare module '../../Observable' { | ||
namespace Observable { | ||
export let generate: typeof GenerateObservable.create; | ||
export let generate: typeof staticGenerate; | ||
} | ||
} |
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,10 +1,10 @@ | ||
import { Observable } from '../../Observable'; | ||
import { onErrorResumeNextStatic } from '../../operator/onErrorResumeNext'; | ||
import { onErrorResumeNext as staticOnErrorResumeNext } from '../../observable/onErrorResumeNext'; | ||
|
||
Observable.onErrorResumeNext = onErrorResumeNextStatic; | ||
Observable.onErrorResumeNext = staticOnErrorResumeNext; | ||
|
||
declare module '../../Observable' { | ||
namespace Observable { | ||
export let onErrorResumeNext: typeof onErrorResumeNextStatic; | ||
export let onErrorResumeNext: typeof staticOnErrorResumeNext; | ||
} | ||
} |
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,10 +1,10 @@ | ||
import { Observable } from '../../Observable'; | ||
import { race as raceStatic } from '../../observable/race'; | ||
import { race as staticRace } from '../../observable/race'; | ||
|
||
Observable.race = raceStatic; | ||
Observable.race = staticRace; | ||
|
||
declare module '../../Observable' { | ||
namespace Observable { | ||
export let race: typeof raceStatic; | ||
export let race: typeof staticRace; | ||
} | ||
} |
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,3 @@ | ||
import { GenerateObservable } from './GenerateObservable'; | ||
|
||
export const generate = GenerateObservable.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,3 @@ | ||
import { onErrorResumeNextStatic } from '../operator/onErrorResumeNext'; | ||
|
||
export const onErrorResumeNext = onErrorResumeNextStatic; |
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,100 +1,3 @@ | ||
import { Observable } from '../Observable'; | ||
import { isArray } from '../util/isArray'; | ||
import { ArrayObservable } from '../observable/ArrayObservable'; | ||
import { Operator } from '../Operator'; | ||
import { Subscriber } from '../Subscriber'; | ||
import { Subscription, TeardownLogic } from '../Subscription'; | ||
import { OuterSubscriber } from '../OuterSubscriber'; | ||
import { InnerSubscriber } from '../InnerSubscriber'; | ||
import { subscribeToResult } from '../util/subscribeToResult'; | ||
import { raceStatic } from '../operator/race'; | ||
|
||
/** | ||
* Returns an Observable that mirrors the first source Observable to emit an item. | ||
* @param {...Observables} ...observables sources used to race for which Observable emits first. | ||
* @return {Observable} an Observable that mirrors the output of the first Observable to emit an item. | ||
* @static true | ||
* @name race | ||
* @owner Observable | ||
*/ | ||
export function race<T>(observables: Array<Observable<T>>): Observable<T>; | ||
export function race<T>(observables: Array<Observable<any>>): Observable<T>; | ||
export function race<T>(...observables: Array<Observable<T> | Array<Observable<T>>>): Observable<T>; | ||
export function race<T>(...observables: Array<Observable<any> | Array<Observable<any>>>): Observable<T> { | ||
// if the only argument is an array, it was most likely called with | ||
// `race([obs1, obs2, ...])` | ||
if (observables.length === 1) { | ||
if (isArray(observables[0])) { | ||
observables = <Array<Observable<any>>>observables[0]; | ||
} else { | ||
return <Observable<any>>observables[0]; | ||
} | ||
} | ||
|
||
return new ArrayObservable<T>(<any>observables).lift(new RaceOperator<T>()); | ||
} | ||
|
||
export class RaceOperator<T> implements Operator<T, T> { | ||
call(subscriber: Subscriber<T>, source: any): TeardownLogic { | ||
return source.subscribe(new RaceSubscriber(subscriber)); | ||
} | ||
} | ||
|
||
/** | ||
* We need this JSDoc comment for affecting ESDoc. | ||
* @ignore | ||
* @extends {Ignored} | ||
*/ | ||
export class RaceSubscriber<T> extends OuterSubscriber<T, T> { | ||
private hasFirst: boolean = false; | ||
private observables: Observable<any>[] = []; | ||
private subscriptions: Subscription[] = []; | ||
|
||
constructor(destination: Subscriber<T>) { | ||
super(destination); | ||
} | ||
|
||
protected _next(observable: any): void { | ||
this.observables.push(observable); | ||
} | ||
|
||
protected _complete() { | ||
const observables = this.observables; | ||
const len = observables.length; | ||
|
||
if (len === 0) { | ||
this.destination.complete(); | ||
} else { | ||
for (let i = 0; i < len && !this.hasFirst; i++) { | ||
let observable = observables[i]; | ||
let subscription = subscribeToResult(this, observable, observable, i); | ||
|
||
if (this.subscriptions) { | ||
this.subscriptions.push(subscription); | ||
} | ||
this.add(subscription); | ||
} | ||
this.observables = null; | ||
} | ||
} | ||
|
||
notifyNext(outerValue: T, innerValue: T, | ||
outerIndex: number, innerIndex: number, | ||
innerSub: InnerSubscriber<T, T>): void { | ||
if (!this.hasFirst) { | ||
this.hasFirst = true; | ||
|
||
for (let i = 0; i < this.subscriptions.length; i++) { | ||
if (i !== outerIndex) { | ||
let subscription = this.subscriptions[i]; | ||
|
||
subscription.unsubscribe(); | ||
this.remove(subscription); | ||
} | ||
} | ||
|
||
this.subscriptions = null; | ||
} | ||
|
||
this.destination.next(innerValue); | ||
} | ||
} | ||
export const race = raceStatic; |
Oops, something went wrong.