From 6835dcd6d3c0efc6e09509dfada74daec8c80c09 Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Mon, 14 Dec 2015 09:13:21 -0800 Subject: [PATCH] feat(inspectTime): add inspectTime operator 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` --- ...sampleTime-spec.js => inspectTime-spec.js} | 22 +++++++++---------- src/CoreOperators.ts | 2 +- src/Observable.ts | 2 +- src/Rx.KitchenSink.ts | 2 +- src/Rx.ts | 2 +- src/add/operator/inspectTime.ts | 5 +++++ src/add/operator/sampleTime.ts | 5 ----- .../{sampleTime.ts => inspectTime.ts} | 10 ++++----- 8 files changed, 25 insertions(+), 25 deletions(-) rename spec/operators/{sampleTime-spec.js => inspectTime-spec.js} (79%) create mode 100644 src/add/operator/inspectTime.ts delete mode 100644 src/add/operator/sampleTime.ts rename src/operator/{sampleTime.ts => inspectTime.ts} (72%) diff --git a/spec/operators/sampleTime-spec.js b/spec/operators/inspectTime-spec.js similarity index 79% rename from spec/operators/sampleTime-spec.js rename to spec/operators/inspectTime-spec.js index d604ad4982..e5be0a65ee 100644 --- a/spec/operators/sampleTime-spec.js +++ b/spec/operators/inspectTime-spec.js @@ -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); }); @@ -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); }); @@ -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); }); @@ -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); @@ -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); }); @@ -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); }); @@ -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); }); }); \ No newline at end of file diff --git a/src/CoreOperators.ts b/src/CoreOperators.ts index d8ad6fb7ca..cee2ce009f 100644 --- a/src/CoreOperators.ts +++ b/src/CoreOperators.ts @@ -40,6 +40,7 @@ export interface CoreOperators { durationSelector?: (group: GroupedObservable) => Observable) => Observable>; ignoreElements?: () => Observable; inspect?: (notifier: Observable) => Observable; + inspectTime?: (delay: number, scheduler?: Scheduler) => Observable; last?: (predicate?: (value: T, index: number) => boolean, resultSelector?: (value: T, index: number) => R, defaultValue?: any) => Observable | Observable; @@ -63,7 +64,6 @@ export interface CoreOperators { repeat?: (count?: number) => Observable; retry?: (count?: number) => Observable; retryWhen?: (notifier: (errors: Observable) => Observable) => Observable; - sampleTime?: (delay: number, scheduler?: Scheduler) => Observable; scan?: (project: (acc: R, x: T) => R, acc?: R) => Observable; share?: () => Observable; single?: (predicate?: (value: T, index: number) => boolean) => Observable; diff --git a/src/Observable.ts b/src/Observable.ts index 436c18edf9..a4329bd386 100644 --- a/src/Observable.ts +++ b/src/Observable.ts @@ -221,6 +221,7 @@ export class Observable implements CoreOperators { durationSelector?: (group: GroupedObservable) => Observable) => Observable>; ignoreElements: () => Observable; inspect: (notifier: Observable) => Observable; + inspectTime: (delay: number, scheduler?: Scheduler) => Observable; last: (predicate?: (value: T, index: number) => boolean, resultSelector?: (value: T, index: number) => R, thisArg?: any, defaultValue?: any) => Observable | Observable; @@ -245,7 +246,6 @@ export class Observable implements CoreOperators { repeat: (count?: number) => Observable; retry: (count?: number) => Observable; retryWhen: (notifier: (errors: Observable) => Observable) => Observable; - sampleTime: (delay: number, scheduler?: Scheduler) => Observable; scan: (accumulator: (acc: R, x: T) => R, seed?: T | R) => Observable; share: () => Observable; single: (predicate?: (value: T, index: number) => boolean) => Observable; diff --git a/src/Rx.KitchenSink.ts b/src/Rx.KitchenSink.ts index 193b103e48..4a99a65488 100644 --- a/src/Rx.KitchenSink.ts +++ b/src/Rx.KitchenSink.ts @@ -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'; @@ -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'; diff --git a/src/Rx.ts b/src/Rx.ts index 81d37f374e..b72edcfe86 100644 --- a/src/Rx.ts +++ b/src/Rx.ts @@ -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'; @@ -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'; diff --git a/src/add/operator/inspectTime.ts b/src/add/operator/inspectTime.ts new file mode 100644 index 0000000000..8b8859b271 --- /dev/null +++ b/src/add/operator/inspectTime.ts @@ -0,0 +1,5 @@ +import {Observable} from '../../Observable'; +import {inspectTime} from '../../operator/inspectTime'; +Observable.prototype.inspectTime = inspectTime; + +export var _void: void; \ No newline at end of file diff --git a/src/add/operator/sampleTime.ts b/src/add/operator/sampleTime.ts deleted file mode 100644 index 7a3d4833d3..0000000000 --- a/src/add/operator/sampleTime.ts +++ /dev/null @@ -1,5 +0,0 @@ -import {Observable} from '../../Observable'; -import {sampleTime} from '../../operator/sampleTime'; -Observable.prototype.sampleTime = sampleTime; - -export var _void: void; \ No newline at end of file diff --git a/src/operator/sampleTime.ts b/src/operator/inspectTime.ts similarity index 72% rename from src/operator/sampleTime.ts rename to src/operator/inspectTime.ts index e414724718..ed726ddd54 100644 --- a/src/operator/sampleTime.ts +++ b/src/operator/inspectTime.ts @@ -4,20 +4,20 @@ import {Subscriber} from '../Subscriber'; import {Scheduler} from '../Scheduler'; import {asap} from '../scheduler/asap'; -export function sampleTime(delay: number, scheduler: Scheduler = asap): Observable { - return this.lift(new SampleTimeOperator(delay, scheduler)); +export function inspectTime(delay: number, scheduler: Scheduler = asap): Observable { + return this.lift(new InspectTimeOperator(delay, scheduler)); } -class SampleTimeOperator implements Operator { +class InspectTimeOperator implements Operator { constructor(private delay: number, private scheduler: Scheduler) { } call(subscriber: Subscriber) { - return new SampleTimeSubscriber(subscriber, this.delay, this.scheduler); + return new InspectTimeSubscriber(subscriber, this.delay, this.scheduler); } } -class SampleTimeSubscriber extends Subscriber { +class InspectTimeSubscriber extends Subscriber { lastValue: T; hasValue: boolean = false;