Skip to content

Commit

Permalink
feat(exhaust): rename switchFirst operators to exhaust
Browse files Browse the repository at this point in the history
BREAKING CHANGE: switchFirst is now exhaust
BREAKING CHANGE: switchFirstMap is now exhaustMap
closes #915
  • Loading branch information
benlesh committed Dec 9, 2015
1 parent eae4b00 commit 9b565c9
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 54 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.switchFirst()', function () {
describe('Observable.prototype.exhaust()', function () {
it('should switch to first immediately-scheduled inner Observable', function () {
var e1 = cold( '(ab|)');
var e1subs = '(^!)';
var e2 = cold( '(cd|)');
var e2subs = [];
var expected = '(ab|)';

expectObservable(Observable.of(e1, e2).switchFirst()).toBe(expected);
expectObservable(Observable.of(e1, e2).exhaust()).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
expectSubscriptions(e2.subscriptions).toBe(e2subs);
});
Expand All @@ -23,7 +23,7 @@ describe('Observable.prototype.switchFirst()', function () {
var e1subs = '(^!)';
var expected = '#';

expectObservable(e1.switchFirst()).toBe(expected);
expectObservable(e1.exhaust()).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

Expand All @@ -32,7 +32,7 @@ describe('Observable.prototype.switchFirst()', function () {
var e1subs = '(^!)';
var expected = '|';

expectObservable(e1.switchFirst()).toBe(expected);
expectObservable(e1.exhaust()).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

Expand All @@ -41,7 +41,7 @@ describe('Observable.prototype.switchFirst()', function () {
var e1subs = '^';
var expected = '-';

expectObservable(e1.switchFirst()).toBe(expected);
expectObservable(e1.exhaust()).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

Expand All @@ -55,7 +55,7 @@ describe('Observable.prototype.switchFirst()', function () {
var e1 = hot( '------x-------y-----z-------------|', { x: x, y: y, z: z });
var expected = '--------a---b---c------g--h---i---|';

expectObservable(e1.switchFirst()).toBe(expected);
expectObservable(e1.exhaust()).toBe(expected);
expectSubscriptions(x.subscriptions).toBe(xsubs);
expectSubscriptions(y.subscriptions).toBe(ysubs);
expectSubscriptions(z.subscriptions).toBe(zsubs);
Expand All @@ -70,7 +70,7 @@ describe('Observable.prototype.switchFirst()', function () {
var unsub = ' ! ';
var expected = '--------a---b--- ';

expectObservable(e1.switchFirst(), unsub).toBe(expected);
expectObservable(e1.exhaust(), unsub).toBe(expected);
expectSubscriptions(x.subscriptions).toBe(xsubs);
expectSubscriptions(y.subscriptions).toBe(ysubs);
});
Expand All @@ -86,7 +86,7 @@ describe('Observable.prototype.switchFirst()', function () {

var result = e1
.mergeMap(function (i) { return Observable.of(i); })
.switchFirst()
.exhaust()
.mergeMap(function (i) { return Observable.of(i); });

expectObservable(result, unsub).toBe(expected);
Expand All @@ -104,7 +104,7 @@ describe('Observable.prototype.switchFirst()', function () {
var e1 = hot( '---x---y------z----------| ', { x: x, y: y, z: z });
var expected = '-----a---b-------f--g---h--';

expectObservable(e1.switchFirst()).toBe(expected);
expectObservable(e1.exhaust()).toBe(expected);
expectSubscriptions(x.subscriptions).toBe(xsubs);
expectSubscriptions(y.subscriptions).toBe(ysubs);
expectSubscriptions(z.subscriptions).toBe(zsubs);
Expand All @@ -118,7 +118,7 @@ describe('Observable.prototype.switchFirst()', function () {
var e1 = hot( '------(xy)------------|', { x: x, y: y });
var expected = '--------a---b---c-----|';

expectObservable(e1.switchFirst()).toBe(expected);
expectObservable(e1.exhaust()).toBe(expected);
expectSubscriptions(x.subscriptions).toBe(xsubs);
expectSubscriptions(y.subscriptions).toBe(ysubs);
});
Expand All @@ -131,7 +131,7 @@ describe('Observable.prototype.switchFirst()', function () {
var e1 = hot( '------x-------y------| ', { x: x, y: y });
var expected = '--------a---# ';

expectObservable(e1.switchFirst()).toBe(expected);
expectObservable(e1.exhaust()).toBe(expected);
expectSubscriptions(x.subscriptions).toBe(xsubs);
expectSubscriptions(y.subscriptions).toBe(ysubs);
});
Expand All @@ -144,7 +144,7 @@ describe('Observable.prototype.switchFirst()', function () {
var e1 = hot( '------x-------y-------# ', { x: x, y: y });
var expected = '--------a---b---c-----# ';

expectObservable(e1.switchFirst()).toBe(expected);
expectObservable(e1.exhaust()).toBe(expected);
expectSubscriptions(x.subscriptions).toBe(xsubs);
expectSubscriptions(y.subscriptions).toBe(ysubs);
});
Expand All @@ -154,7 +154,7 @@ describe('Observable.prototype.switchFirst()', function () {
var e1subs = '^ !';
var expected = '------|';

expectObservable(e1.switchFirst()).toBe(expected);
expectObservable(e1.exhaust()).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

Expand All @@ -163,7 +163,7 @@ describe('Observable.prototype.switchFirst()', function () {
var e1subs = '^';
var expected = '-';

expectObservable(e1.switchFirst()).toBe(expected);
expectObservable(e1.exhaust()).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

Expand All @@ -173,15 +173,15 @@ describe('Observable.prototype.switchFirst()', function () {
var e1 = hot( '------x---------------|', { x: x });
var expected = '--------a---b---c-----|';

expectObservable(e1.switchFirst()).toBe(expected);
expectObservable(e1.exhaust()).toBe(expected);
expectSubscriptions(x.subscriptions).toBe(xsubs);
});

it('should handle an observable of promises', function (done) {
var expected = [1];

Observable.of(Promise.resolve(1), Promise.resolve(2), Promise.resolve(3))
.switchFirst()
.exhaust()
.subscribe(function (x) {
expect(x).toBe(expected.shift());
}, null, function () {
Expand All @@ -192,7 +192,7 @@ describe('Observable.prototype.switchFirst()', function () {

it('should handle an observable of promises, where one rejects', function (done) {
Observable.of(Promise.reject(2), Promise.resolve(1))
.switchFirst()
.exhaust()
.subscribe(function (x) {
expect(false).toBe(true);
}, function (err) {
Expand Down
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.switchFirstMap()', function () {
describe('Observable.prototype.exhaustMap()', 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.switchFirstMap(function () { return x; });
var result = e1.exhaustMap(function () { return x; });

expectObservable(result).toBe(expected);
expectSubscriptions(x.subscriptions).toBe(xsubs);
Expand All @@ -27,7 +27,7 @@ describe('Observable.prototype.switchFirstMap()', function () {
var e1subs = '(^!)';
var expected = '|';

var result = e1.switchFirstMap(function () { return x; });
var result = e1.exhaustMap(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.switchFirstMap()', function () {
var e1subs = '^';
var expected = '-';

var result = e1.switchFirstMap(function () { return x; });
var result = e1.exhaustMap(function () { return x; });

expectObservable(result).toBe(expected);
expectSubscriptions(x.subscriptions).toBe(xsubs);
Expand All @@ -52,7 +52,7 @@ describe('Observable.prototype.switchFirstMap()', function () {
var e1subs = '^ !';
var expected = '---#';

var result = e1.switchFirstMap(function (value) {
var result = e1.exhaustMap(function (value) {
throw 'error';
});

Expand All @@ -67,7 +67,7 @@ describe('Observable.prototype.switchFirstMap()', function () {
var e1subs = '^ ! ';
var expected = '-----# ';

var result = e1.switchFirstMap(function (value) {
var result = e1.exhaustMap(function (value) {
return x;
}, function () {
throw 'error';
Expand All @@ -91,7 +91,7 @@ describe('Observable.prototype.switchFirstMap()', function () {

var observableLookup = { x: x, y: y, z: z };

var result = e1.switchFirstMap(function (value) {
var result = e1.exhaustMap(function (value) {
return observableLookup[value];
});

Expand All @@ -116,7 +116,7 @@ describe('Observable.prototype.switchFirstMap()', function () {

var observableLookup = { x: x, y: y, z: z };

var result = e1.switchFirstMap(function (value) {
var result = e1.exhaustMap(function (value) {
return observableLookup[value];
});

Expand All @@ -143,7 +143,7 @@ describe('Observable.prototype.switchFirstMap()', function () {

var result = e1
.mergeMap(function (i) { return Observable.of(i); })
.switchFirstMap(function (value) { return observableLookup[value]; })
.exhaustMap(function (value) { return observableLookup[value]; })
.mergeMap(function (i) { return Observable.of(i); });

expectObservable(result, unsub).toBe(expected);
Expand All @@ -166,7 +166,7 @@ describe('Observable.prototype.switchFirstMap()', function () {

var observableLookup = { x: x, y: y, z: z };

var result = e1.switchFirstMap(function (value) {
var result = e1.exhaustMap(function (value) {
return observableLookup[value];
});

Expand All @@ -188,7 +188,7 @@ describe('Observable.prototype.switchFirstMap()', function () {

var observableLookup = { x: x, y: y };

var result = e1.switchFirstMap(function (value) {
var result = e1.exhaustMap(function (value) {
return observableLookup[value];
});

Expand All @@ -209,7 +209,7 @@ describe('Observable.prototype.switchFirstMap()', function () {

var observableLookup = { x: x, y: y };

var result = e1.switchFirstMap(function (value) {
var result = e1.exhaustMap(function (value) {
return observableLookup[value];
});

Expand All @@ -232,7 +232,7 @@ describe('Observable.prototype.switchFirstMap()', function () {

var observableLookup = { x: x, y: y, z: z };

var result = e1.switchFirstMap(function (value) {
var result = e1.exhaustMap(function (value) {
return observableLookup[value];
});

Expand All @@ -254,7 +254,7 @@ describe('Observable.prototype.switchFirstMap()', function () {

var observableLookup = { x: x, y: y };

var result = e1.switchFirstMap(function (value) {
var result = e1.exhaustMap(function (value) {
return observableLookup[value];
});

Expand All @@ -275,7 +275,7 @@ describe('Observable.prototype.switchFirstMap()', function () {

var observableLookup = { x: x, y: y };

var result = e1.switchFirstMap(function (value) {
var result = e1.exhaustMap(function (value) {
return observableLookup[value];
});

Expand All @@ -296,7 +296,7 @@ describe('Observable.prototype.switchFirstMap()', function () {

var observableLookup = { x: x, y: y };

var result = e1.switchFirstMap(function (value) {
var result = e1.exhaustMap(function (value) {
return observableLookup[value];
});

Expand All @@ -317,7 +317,7 @@ describe('Observable.prototype.switchFirstMap()', function () {

var observableLookup = { x: x, y: y };

var result = e1.switchFirstMap(function (value) {
var result = e1.exhaustMap(function (value) {
return observableLookup[value];
});

Expand All @@ -336,7 +336,7 @@ describe('Observable.prototype.switchFirstMap()', function () {

var observableLookup = { x: x };

var result = e1.switchFirstMap(function (value) {
var result = e1.exhaustMap(function (value) {
return observableLookup[value];
});

Expand Down Expand Up @@ -370,7 +370,7 @@ describe('Observable.prototype.switchFirstMap()', function () {
n: ['z', 'n', 1, 3],
};

var result = e1.switchFirstMap(function (value) {
var result = e1.exhaustMap(function (value) {
return observableLookup[value];
}, function (innerValue, outerValue, innerIndex, outerIndex) {
return [innerValue, outerValue, innerIndex, outerIndex];
Expand Down
4 changes: 2 additions & 2 deletions src/Observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ export class Observable<T> implements CoreOperators<T> {
startWith: (x: T) => Observable<T>;
subscribeOn: (scheduler: Scheduler, delay?: number) => Observable<T>;
switch: <R>() => Observable<R>;
switchFirst: <T>() => Observable<T>;
exhaust: <T>() => Observable<T>;
switchMap: <R>(project: ((x: T, ix: number) => Observable<any>), projectResult?: (x: T, y: any, ix: number, iy: number) => R) => 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>;
exhaustMap: <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
4 changes: 2 additions & 2 deletions src/Rx.KitchenSink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export interface KitchenSinkOperators<T> extends CoreOperators<T> {
min?: <T, R>(comparer?: (x: R, y: T) => R) => Observable<R>;
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>;
switchFirstMap?: <R>(project: ((x: T, ix: number) => Observable<any>),
exhaust?: () => Observable<T>;
exhaustMap?: <R>(project: ((x: T, ix: number) => Observable<any>),
projectResult?: (x: T, y: any, ix: number, iy: number) => R) => Observable<R>;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Rx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ import './add/operator/skipWhile';
import './add/operator/startWith';
import './add/operator/subscribeOn';
import './add/operator/switch';
import './add/operator/switchFirst';
import './add/operator/exhaust';
import './add/operator/switchMap';
import './add/operator/switchFirstMap';
import './add/operator/exhaustMap';
import './add/operator/switchMapTo';
import './add/operator/take';
import './add/operator/takeUntil';
Expand Down
3 changes: 3 additions & 0 deletions src/add/operator/exhaust.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {Observable} from '../../Observable';
import {exhaust} from '../../operator/exhaust';
Observable.prototype.exhaust = exhaust;
3 changes: 3 additions & 0 deletions src/add/operator/exhaustMap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {Observable} from '../../Observable';
import {exhaustMap} from '../../operator/exhaustMap';
Observable.prototype.exhaustMap = exhaustMap;
3 changes: 0 additions & 3 deletions src/add/operator/switchFirst.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/add/operator/switchFirstMap.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/operator/switchFirst.ts → src/operator/exhaust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {Subscription} from '../Subscription';
import {OuterSubscriber} from '../OuterSubscriber';
import {subscribeToResult} from '../util/subscribeToResult';

export function switchFirst<T>(): Observable<T> {
export function exhaust<T>(): Observable<T> {
return this.lift(new SwitchFirstOperator());
}

Expand Down
Loading

0 comments on commit 9b565c9

Please sign in to comment.