Skip to content

Commit

Permalink
feat(inspectTime): add inspectTime operator
Browse files Browse the repository at this point in the history
RxJS 5's `sampleTime` operator deviated from expected Rx behavior, but has value, so we're moving it
to be named `inspectTime`.

BREAKING CHANGE: `sampleTime` is now `inspectTime`
  • Loading branch information
benlesh committed Dec 14, 2015
1 parent f9944ae commit 6835dcd
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
var Rx = require('../../dist/cjs/Rx');
var Observable = Rx.Observable;

describe('Observable.prototype.sampleTime', function () {
it('should get samples on a delay', function () {
describe('Observable.prototype.inspectTime', function () {
it('should get inspections on a delay', function () {
var e1 = hot('----a-^--b----c----d----e----f----|');
var e1subs = '^ !';
var expected = '-----------c----------e-----|';
// timer -----------!----------!---------

expectObservable(e1.sampleTime(110, rxTestScheduler)).toBe(expected);
expectObservable(e1.inspectTime(110, rxTestScheduler)).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

it('should sample nothing if source has not nexted by time of sample', function () {
it('should inspect nothing if source has not nexted by time of inspect', function () {
var e1 = hot('----a-^-------------b-------------|');
var e1subs = '^ !';
var expected = '----------------------b-----|';
// timer -----------!----------!---------

expectObservable(e1.sampleTime(110, rxTestScheduler)).toBe(expected);
expectObservable(e1.inspectTime(110, rxTestScheduler)).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

Expand All @@ -29,7 +29,7 @@ describe('Observable.prototype.sampleTime', function () {
var expected = '-----------c------#';
// timer -----------!----------!---------

expectObservable(e1.sampleTime(110, rxTestScheduler)).toBe(expected);
expectObservable(e1.inspectTime(110, rxTestScheduler)).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

Expand All @@ -40,7 +40,7 @@ describe('Observable.prototype.sampleTime', function () {
var expected = '-----------c----- ';
// timer -----------!----------!---------

expectObservable(e1.sampleTime(110, rxTestScheduler), unsub).toBe(expected);
expectObservable(e1.inspectTime(110, rxTestScheduler), unsub).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

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

var result = e1
.mergeMap(function (x) { return Observable.of(x); })
.sampleTime(110, rxTestScheduler)
.inspectTime(110, rxTestScheduler)
.mergeMap(function (x) { return Observable.of(x); });

expectObservable(result, unsub).toBe(expected);
Expand All @@ -65,7 +65,7 @@ describe('Observable.prototype.sampleTime', function () {
var e1subs = '(^!)';
var expected = '|';

expectObservable(e1.sampleTime(60, rxTestScheduler)).toBe(expected);
expectObservable(e1.inspectTime(60, rxTestScheduler)).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

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

expectObservable(e1.sampleTime(60, rxTestScheduler)).toBe(expected);
expectObservable(e1.inspectTime(60, rxTestScheduler)).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

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

expectObservable(e1.sampleTime(60, rxTestScheduler)).toBe(expected);
expectObservable(e1.inspectTime(60, rxTestScheduler)).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
});
2 changes: 1 addition & 1 deletion src/CoreOperators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface CoreOperators<T> {
durationSelector?: (group: GroupedObservable<R>) => Observable<any>) => Observable<GroupedObservable<R>>;
ignoreElements?: () => Observable<T>;
inspect?: (notifier: Observable<any>) => Observable<T>;
inspectTime?: (delay: number, scheduler?: Scheduler) => Observable<T>;
last?: <R>(predicate?: (value: T, index: number) => boolean,
resultSelector?: (value: T, index: number) => R,
defaultValue?: any) => Observable<T> | Observable<R>;
Expand All @@ -63,7 +64,6 @@ export interface CoreOperators<T> {
repeat?: (count?: number) => Observable<T>;
retry?: (count?: number) => Observable<T>;
retryWhen?: (notifier: (errors: Observable<any>) => Observable<any>) => Observable<T>;
sampleTime?: (delay: number, scheduler?: Scheduler) => Observable<T>;
scan?: <R>(project: (acc: R, x: T) => R, acc?: R) => Observable<R>;
share?: () => Observable<T>;
single?: (predicate?: (value: T, index: number) => boolean) => Observable<T>;
Expand Down
2 changes: 1 addition & 1 deletion src/Observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export class Observable<T> implements CoreOperators<T> {
durationSelector?: (group: GroupedObservable<R>) => Observable<any>) => Observable<GroupedObservable<R>>;
ignoreElements: () => Observable<T>;
inspect: (notifier: Observable<any>) => Observable<T>;
inspectTime: (delay: number, scheduler?: Scheduler) => Observable<T>;
last: <R>(predicate?: (value: T, index: number) => boolean,
resultSelector?: (value: T, index: number) => R,
thisArg?: any, defaultValue?: any) => Observable<T> | Observable<R>;
Expand All @@ -245,7 +246,6 @@ export class Observable<T> implements CoreOperators<T> {
repeat: (count?: number) => Observable<T>;
retry: (count?: number) => Observable<T>;
retryWhen: (notifier: (errors: Observable<any>) => Observable<any>) => Observable<T>;
sampleTime: (delay: number, scheduler?: Scheduler) => Observable<T>;
scan: <R>(accumulator: (acc: R, x: T) => R, seed?: T | R) => Observable<R>;
share: () => Observable<T>;
single: (predicate?: (value: T, index: number) => boolean) => 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 @@ -75,6 +75,7 @@ import './add/operator/first';
import './add/operator/groupBy';
import './add/operator/ignoreElements';
import './add/operator/inspect';
import './add/operator/inspectTime';
import './add/operator/extended/isEmpty';
import './add/operator/every';
import './add/operator/last';
Expand All @@ -99,7 +100,6 @@ import './add/operator/reduce';
import './add/operator/repeat';
import './add/operator/retry';
import './add/operator/retryWhen';
import './add/operator/sampleTime';
import './add/operator/scan';
import './add/operator/share';
import './add/operator/single';
Expand Down
2 changes: 1 addition & 1 deletion src/Rx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import './add/operator/first';
import './add/operator/groupBy';
import './add/operator/ignoreElements';
import './add/operator/inspect';
import './add/operator/inspectTime';
import './add/operator/every';
import './add/operator/last';
import './add/operator/map';
Expand All @@ -75,7 +76,6 @@ import './add/operator/reduce';
import './add/operator/repeat';
import './add/operator/retry';
import './add/operator/retryWhen';
import './add/operator/sampleTime';
import './add/operator/scan';
import './add/operator/share';
import './add/operator/single';
Expand Down
5 changes: 5 additions & 0 deletions src/add/operator/inspectTime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {Observable} from '../../Observable';
import {inspectTime} from '../../operator/inspectTime';
Observable.prototype.inspectTime = inspectTime;

export var _void: void;
5 changes: 0 additions & 5 deletions src/add/operator/sampleTime.ts

This file was deleted.

10 changes: 5 additions & 5 deletions src/operator/sampleTime.ts → src/operator/inspectTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import {Subscriber} from '../Subscriber';
import {Scheduler} from '../Scheduler';
import {asap} from '../scheduler/asap';

export function sampleTime<T>(delay: number, scheduler: Scheduler = asap): Observable<T> {
return this.lift(new SampleTimeOperator(delay, scheduler));
export function inspectTime<T>(delay: number, scheduler: Scheduler = asap): Observable<T> {
return this.lift(new InspectTimeOperator(delay, scheduler));
}

class SampleTimeOperator<T, R> implements Operator<T, R> {
class InspectTimeOperator<T, R> implements Operator<T, R> {
constructor(private delay: number, private scheduler: Scheduler) {
}

call(subscriber: Subscriber<R>) {
return new SampleTimeSubscriber(subscriber, this.delay, this.scheduler);
return new InspectTimeSubscriber(subscriber, this.delay, this.scheduler);
}
}

class SampleTimeSubscriber<T> extends Subscriber<T> {
class InspectTimeSubscriber<T> extends Subscriber<T> {
lastValue: T;
hasValue: boolean = false;

Expand Down

0 comments on commit 6835dcd

Please sign in to comment.