Skip to content

Commit

Permalink
feat(switchFirstMap): rename switchMapFirst to switchFirstMap
Browse files Browse the repository at this point in the history
related #915
  • Loading branch information
benlesh committed Dec 8, 2015
1 parent c9da8cb commit eddd4dc
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ 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 = [];
var e1 = cold('#');
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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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';
});

Expand All @@ -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';
Expand All @@ -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];
});

Expand All @@ -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];
});

Expand All @@ -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];
});

Expand All @@ -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];
});

Expand All @@ -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];
});

Expand All @@ -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];
});

Expand All @@ -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];
});

Expand All @@ -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];
});

Expand All @@ -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];
});

Expand All @@ -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];
});

Expand All @@ -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];
});

Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/Observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export class Observable<T> implements CoreOperators<T> {
switch: <R>() => Observable<R>;
switchFirst: <T>() => Observable<T>;
switchMap: <R>(project: ((x: T, ix: number) => Observable<any>), projectResult?: (x: T, y: any, ix: number, iy: number) => R) => Observable<R>;
switchMapFirst: <T, R, R2>(project: (x: T, ix: number) => Observable<R>, rSelector?: (x: T, y: R, ix: number, iy: number) => R2) => Observable<R>;
switchFirstMap: <T, R, R2>(project: (x: T, ix: number) => Observable<R>, rSelector?: (x: T, y: R, ix: number, iy: number) => R2) => Observable<R>;
switchMapTo: <R>(observable: Observable<any>, projectResult?: (x: T, y: any, ix: number, iy: number) => R) => Observable<R>;
take: (count: number) => Observable<T>;
takeUntil: (notifier: Observable<any>) => Observable<T>;
Expand Down
2 changes: 1 addition & 1 deletion src/Rx.KitchenSink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface KitchenSinkOperators<T> extends CoreOperators<T> {
timeInterval?: <T>(scheduler?: IScheduler) => Observable<T>;
mergeScan?: <T, R>(project: (acc: R, x: T) => Observable<R>, seed: R, concurrent?: number) => Observable<R>;
switchFirst?: () => Observable<T>;
switchMapFirst?: <R>(project: ((x: T, ix: number) => Observable<any>),
switchFirstMap?: <R>(project: ((x: T, ix: number) => Observable<any>),
projectResult?: (x: T, y: any, ix: number, iy: number) => R) => Observable<R>;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
3 changes: 3 additions & 0 deletions src/add/operator/switchFirstMap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {Observable} from '../../Observable';
import {switchFirstMap} from '../../operator/switchFirstMap';
Observable.prototype.switchFirstMap = switchFirstMap;
3 changes: 0 additions & 3 deletions src/add/operator/switchMapFirst.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import {errorObject} from '../util/errorObject';
import {OuterSubscriber} from '../OuterSubscriber';
import {subscribeToResult} from '../util/subscribeToResult';

export function switchMapFirst<T, R, R2>(project: (value: T, index: number) => Observable<R>,
export function switchFirstMap<T, R, R2>(project: (value: T, index: number) => Observable<R>,
resultSelector?: (outerValue: T,
innerValue: R,
outerIndex: number,
innerIndex: number) => R2): Observable<R> {
return this.lift(new SwitchMapFirstOperator(project, resultSelector));
return this.lift(new SwitchFirstMapOperator(project, resultSelector));
}

class SwitchMapFirstOperator<T, R, R2> implements Operator<T, R> {
class SwitchFirstMapOperator<T, R, R2> implements Operator<T, R> {
constructor(private project: (value: T, index: number) => Observable<R>,
private resultSelector?: (outerValue: T,
innerValue: R,
Expand All @@ -23,11 +23,11 @@ class SwitchMapFirstOperator<T, R, R2> implements Operator<T, R> {
}

call(subscriber: Subscriber<R>): Subscriber<T> {
return new SwitchMapFirstSubscriber(subscriber, this.project, this.resultSelector);
return new SwitchFirstMapSubscriber(subscriber, this.project, this.resultSelector);
}
}

class SwitchMapFirstSubscriber<T, R, R2> extends OuterSubscriber<T, R> {
class SwitchFirstMapSubscriber<T, R, R2> extends OuterSubscriber<T, R> {
private hasSubscription: boolean = false;
private hasCompleted: boolean = false;
private index: number = 0;
Expand Down

0 comments on commit eddd4dc

Please sign in to comment.