diff --git a/src/operator/timeInterval.ts b/src/operator/timeInterval.ts index 760f0b4d31..4302b519b5 100644 --- a/src/operator/timeInterval.ts +++ b/src/operator/timeInterval.ts @@ -1,8 +1,8 @@ -import { Operator } from '../Operator'; import { Observable } from '../Observable'; -import { Subscriber } from '../Subscriber'; import { IScheduler } from '../Scheduler'; import { async } from '../scheduler/async'; +import { timeInterval as higherOrder, TimeInterval } from '../operators/timeInterval'; +export {TimeInterval}; /** * @param scheduler @@ -11,44 +11,5 @@ import { async } from '../scheduler/async'; * @owner Observable */ export function timeInterval(this: Observable, scheduler: IScheduler = async): Observable> { - return this.lift(new TimeIntervalOperator(scheduler)); -} - -export class TimeInterval { - constructor(public value: T, public interval: number) { - - } -}; - -class TimeIntervalOperator implements Operator> { - constructor(private scheduler: IScheduler) { - - } - - call(observer: Subscriber>, source: any): any { - return source.subscribe(new TimeIntervalSubscriber(observer, this.scheduler)); - } -} - -/** - * We need this JSDoc comment for affecting ESDoc. - * @ignore - * @extends {Ignored} - */ -class TimeIntervalSubscriber extends Subscriber { - private lastTime: number = 0; - - constructor(destination: Subscriber>, private scheduler: IScheduler) { - super(destination); - - this.lastTime = scheduler.now(); - } - - protected _next(value: T) { - let now = this.scheduler.now(); - let span = now - this.lastTime; - this.lastTime = now; - - this.destination.next(new TimeInterval(value, span)); - } + return higherOrder(scheduler)(this); } diff --git a/src/operators/index.ts b/src/operators/index.ts index b0fd4a0502..9c4faccb26 100644 --- a/src/operators/index.ts +++ b/src/operators/index.ts @@ -67,6 +67,7 @@ export { takeLast } from './takeLast'; export { tap } from './tap'; export { throttle } from './throttle'; export { throttleTime } from './throttleTime'; +export { timeInterval } from './timeInterval'; export { timestamp } from './timestamp'; export { toArray } from './toArray'; export { window } from './window'; diff --git a/src/operators/timeInterval.ts b/src/operators/timeInterval.ts new file mode 100644 index 0000000000..65e5b36df8 --- /dev/null +++ b/src/operators/timeInterval.ts @@ -0,0 +1,49 @@ +import { Operator } from '../Operator'; +import { Observable } from '../Observable'; +import { Subscriber } from '../Subscriber'; +import { IScheduler } from '../Scheduler'; +import { async } from '../scheduler/async'; +import { OperatorFunction } from '../interfaces'; + +export function timeInterval(scheduler: IScheduler = async): OperatorFunction> { + return (source: Observable) => source.lift(new TimeIntervalOperator(scheduler)); +} + +export class TimeInterval { + constructor(public value: T, public interval: number) { + + } +}; + +class TimeIntervalOperator implements Operator> { + constructor(private scheduler: IScheduler) { + + } + + call(observer: Subscriber>, source: any): any { + return source.subscribe(new TimeIntervalSubscriber(observer, this.scheduler)); + } +} + +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +class TimeIntervalSubscriber extends Subscriber { + private lastTime: number = 0; + + constructor(destination: Subscriber>, private scheduler: IScheduler) { + super(destination); + + this.lastTime = scheduler.now(); + } + + protected _next(value: T) { + let now = this.scheduler.now(); + let span = now - this.lastTime; + this.lastTime = now; + + this.destination.next(new TimeInterval(value, span)); + } +}