diff --git a/spec/operators/switchMapFirst-spec.js b/spec/operators/switchFirstMap-spec.js similarity index 92% rename from spec/operators/switchMapFirst-spec.js rename to spec/operators/switchFirstMap-spec.js index 654753f5c6..7e91083674 100644 --- a/spec/operators/switchMapFirst-spec.js +++ b/spec/operators/switchFirstMap-spec.js @@ -5,7 +5,7 @@ var Promise = require('promise'); var Observable = Rx.Observable; var queueScheduler = Rx.Scheduler.queue; -describe('Observable.prototype.switchMapFirst()', function () { +describe('Observable.prototype.switchFirstMap()', function () { it('should handle outer throw', function () { var x = cold('--a--b--c--|'); var xsubs = []; @@ -13,7 +13,7 @@ describe('Observable.prototype.switchMapFirst()', function () { var e1subs = '(^!)'; var expected = '#'; - var result = e1.switchMapFirst(function () { return x; }); + var result = e1.switchFirstMap(function () { return x; }); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -27,7 +27,7 @@ describe('Observable.prototype.switchMapFirst()', function () { var e1subs = '(^!)'; var expected = '|'; - var result = e1.switchMapFirst(function () { return x; }); + var result = e1.switchFirstMap(function () { return x; }); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); expectSubscriptions(e1.subscriptions).toBe(e1subs); @@ -40,7 +40,7 @@ describe('Observable.prototype.switchMapFirst()', function () { var e1subs = '^'; var expected = '-'; - var result = e1.switchMapFirst(function () { return x; }); + var result = e1.switchFirstMap(function () { return x; }); expectObservable(result).toBe(expected); expectSubscriptions(x.subscriptions).toBe(xsubs); @@ -52,7 +52,7 @@ describe('Observable.prototype.switchMapFirst()', function () { var e1subs = '^ !'; var expected = '---#'; - var result = e1.switchMapFirst(function (value) { + var result = e1.switchFirstMap(function (value) { throw 'error'; }); @@ -67,7 +67,7 @@ describe('Observable.prototype.switchMapFirst()', function () { var e1subs = '^ ! '; var expected = '-----# '; - var result = e1.switchMapFirst(function (value) { + var result = e1.switchFirstMap(function (value) { return x; }, function () { throw 'error'; @@ -91,7 +91,7 @@ describe('Observable.prototype.switchMapFirst()', function () { var observableLookup = { x: x, y: y, z: z }; - var result = e1.switchMapFirst(function (value) { + var result = e1.switchFirstMap(function (value) { return observableLookup[value]; }); @@ -116,7 +116,7 @@ describe('Observable.prototype.switchMapFirst()', function () { var observableLookup = { x: x, y: y, z: z }; - var result = e1.switchMapFirst(function (value) { + var result = e1.switchFirstMap(function (value) { return observableLookup[value]; }); @@ -140,7 +140,7 @@ describe('Observable.prototype.switchMapFirst()', function () { var observableLookup = { x: x, y: y, z: z }; - var result = e1.switchMapFirst(function (value) { + var result = e1.switchFirstMap(function (value) { return observableLookup[value]; }); @@ -162,7 +162,7 @@ describe('Observable.prototype.switchMapFirst()', function () { var observableLookup = { x: x, y: y }; - var result = e1.switchMapFirst(function (value) { + var result = e1.switchFirstMap(function (value) { return observableLookup[value]; }); @@ -183,7 +183,7 @@ describe('Observable.prototype.switchMapFirst()', function () { var observableLookup = { x: x, y: y }; - var result = e1.switchMapFirst(function (value) { + var result = e1.switchFirstMap(function (value) { return observableLookup[value]; }); @@ -206,7 +206,7 @@ describe('Observable.prototype.switchMapFirst()', function () { var observableLookup = { x: x, y: y, z: z }; - var result = e1.switchMapFirst(function (value) { + var result = e1.switchFirstMap(function (value) { return observableLookup[value]; }); @@ -228,7 +228,7 @@ describe('Observable.prototype.switchMapFirst()', function () { var observableLookup = { x: x, y: y }; - var result = e1.switchMapFirst(function (value) { + var result = e1.switchFirstMap(function (value) { return observableLookup[value]; }); @@ -249,7 +249,7 @@ describe('Observable.prototype.switchMapFirst()', function () { var observableLookup = { x: x, y: y }; - var result = e1.switchMapFirst(function (value) { + var result = e1.switchFirstMap(function (value) { return observableLookup[value]; }); @@ -270,7 +270,7 @@ describe('Observable.prototype.switchMapFirst()', function () { var observableLookup = { x: x, y: y }; - var result = e1.switchMapFirst(function (value) { + var result = e1.switchFirstMap(function (value) { return observableLookup[value]; }); @@ -291,7 +291,7 @@ describe('Observable.prototype.switchMapFirst()', function () { var observableLookup = { x: x, y: y }; - var result = e1.switchMapFirst(function (value) { + var result = e1.switchFirstMap(function (value) { return observableLookup[value]; }); @@ -310,7 +310,7 @@ describe('Observable.prototype.switchMapFirst()', function () { var observableLookup = { x: x }; - var result = e1.switchMapFirst(function (value) { + var result = e1.switchFirstMap(function (value) { return observableLookup[value]; }); @@ -344,7 +344,7 @@ describe('Observable.prototype.switchMapFirst()', function () { n: ['z', 'n', 1, 3], }; - var result = e1.switchMapFirst(function (value) { + var result = e1.switchFirstMap(function (value) { return observableLookup[value]; }, function (innerValue, outerValue, innerIndex, outerIndex) { return [innerValue, outerValue, innerIndex, outerIndex]; diff --git a/src/Observable.ts b/src/Observable.ts index 6c25e937e6..d47e9b414f 100644 --- a/src/Observable.ts +++ b/src/Observable.ts @@ -238,7 +238,7 @@ export class Observable implements CoreOperators { switch: () => Observable; switchFirst: () => Observable; switchMap: (project: ((x: T, ix: number) => Observable), projectResult?: (x: T, y: any, ix: number, iy: number) => R) => Observable; - switchMapFirst: (project: (x: T, ix: number) => Observable, rSelector?: (x: T, y: R, ix: number, iy: number) => R2) => Observable; + switchFirstMap: (project: (x: T, ix: number) => Observable, rSelector?: (x: T, y: R, ix: number, iy: number) => R2) => Observable; switchMapTo: (observable: Observable, projectResult?: (x: T, y: any, ix: number, iy: number) => R) => Observable; take: (count: number) => Observable; takeUntil: (notifier: Observable) => Observable; diff --git a/src/Rx.KitchenSink.ts b/src/Rx.KitchenSink.ts index 55f4c3c659..4ad492ddeb 100644 --- a/src/Rx.KitchenSink.ts +++ b/src/Rx.KitchenSink.ts @@ -16,7 +16,7 @@ export interface KitchenSinkOperators extends CoreOperators { timeInterval?: (scheduler?: IScheduler) => Observable; mergeScan?: (project: (acc: R, x: T) => Observable, seed: R, concurrent?: number) => Observable; switchFirst?: () => Observable; - switchMapFirst?: (project: ((x: T, ix: number) => Observable), + switchFirstMap?: (project: ((x: T, ix: number) => Observable), projectResult?: (x: T, y: any, ix: number, iy: number) => R) => Observable; } diff --git a/src/Rx.ts b/src/Rx.ts index 1fe9cfdfac..5da3b37e86 100644 --- a/src/Rx.ts +++ b/src/Rx.ts @@ -87,7 +87,7 @@ import './add/operator/subscribeOn'; import './add/operator/switch'; import './add/operator/switchFirst'; import './add/operator/switchMap'; -import './add/operator/switchMapFirst'; +import './add/operator/switchFirstMap'; import './add/operator/switchMapTo'; import './add/operator/take'; import './add/operator/takeUntil'; diff --git a/src/add/operator/switchFirstMap.ts b/src/add/operator/switchFirstMap.ts new file mode 100644 index 0000000000..dcc6d666f2 --- /dev/null +++ b/src/add/operator/switchFirstMap.ts @@ -0,0 +1,3 @@ +import {Observable} from '../../Observable'; +import {switchFirstMap} from '../../operator/switchFirstMap'; +Observable.prototype.switchFirstMap = switchFirstMap; diff --git a/src/add/operator/switchMapFirst.ts b/src/add/operator/switchMapFirst.ts deleted file mode 100644 index 1a47b35d84..0000000000 --- a/src/add/operator/switchMapFirst.ts +++ /dev/null @@ -1,3 +0,0 @@ -import {Observable} from '../../Observable'; -import {switchMapFirst} from '../../operator/switchMapFirst'; -Observable.prototype.switchMapFirst = switchMapFirst; diff --git a/src/operator/switchMapFirst.ts b/src/operator/switchFirstMap.ts similarity index 89% rename from src/operator/switchMapFirst.ts rename to src/operator/switchFirstMap.ts index 0080a44992..6d24932db8 100644 --- a/src/operator/switchMapFirst.ts +++ b/src/operator/switchFirstMap.ts @@ -6,15 +6,15 @@ import {errorObject} from '../util/errorObject'; import {OuterSubscriber} from '../OuterSubscriber'; import {subscribeToResult} from '../util/subscribeToResult'; -export function switchMapFirst(project: (value: T, index: number) => Observable, +export function switchFirstMap(project: (value: T, index: number) => Observable, resultSelector?: (outerValue: T, innerValue: R, outerIndex: number, innerIndex: number) => R2): Observable { - return this.lift(new SwitchMapFirstOperator(project, resultSelector)); + return this.lift(new SwitchFirstMapOperator(project, resultSelector)); } -class SwitchMapFirstOperator implements Operator { +class SwitchFirstMapOperator implements Operator { constructor(private project: (value: T, index: number) => Observable, private resultSelector?: (outerValue: T, innerValue: R, @@ -23,11 +23,11 @@ class SwitchMapFirstOperator implements Operator { } call(subscriber: Subscriber): Subscriber { - return new SwitchMapFirstSubscriber(subscriber, this.project, this.resultSelector); + return new SwitchFirstMapSubscriber(subscriber, this.project, this.resultSelector); } } -class SwitchMapFirstSubscriber extends OuterSubscriber { +class SwitchFirstMapSubscriber extends OuterSubscriber { private hasSubscription: boolean = false; private hasCompleted: boolean = false; private index: number = 0;