diff --git a/spec/operators/throttle-spec.ts b/spec/operators/throttle-spec.ts index 7bdce50eec..24210dab6b 100644 --- a/spec/operators/throttle-spec.ts +++ b/spec/operators/throttle-spec.ts @@ -2,6 +2,7 @@ import { expect } from 'chai'; import * as Rx from '../../src/Rx'; import marbleTestingSignature = require('../helpers/marble-testing'); // tslint:disable-line:no-require-imports +declare const type; declare const { asDiagram }; declare const hot: typeof marbleTestingSignature.hot; declare const cold: typeof marbleTestingSignature.cold; @@ -338,6 +339,22 @@ describe('Observable.prototype.throttle', () => { ); }); + type('should support selectors of the same type', () => { + /* tslint:disable:no-unused-variable */ + let o: Rx.Observable; + let s: Rx.Observable; + let r: Rx.Observable = o.throttle((n) => s); + /* tslint:enable:no-unused-variable */ + }); + + type('should support selectors of a different type', () => { + /* tslint:disable:no-unused-variable */ + let o: Rx.Observable; + let s: Rx.Observable; + let r: Rx.Observable = o.throttle((n) => s); + /* tslint:enable:no-unused-variable */ + }); + describe('throttle(fn, { leading: true, trailing: true })', () => { asDiagram('throttle(fn, { leading: true, trailing: true })')('should immediately emit the first value in each time window', () => { const e1 = hot('-a-xy-----b--x--cxxx--|'); diff --git a/src/internal/operators/throttle.ts b/src/internal/operators/throttle.ts index 640323a13a..7e620baaba 100644 --- a/src/internal/operators/throttle.ts +++ b/src/internal/operators/throttle.ts @@ -59,13 +59,13 @@ export const defaultThrottleConfig: ThrottleConfig = { * @method throttle * @owner Observable */ -export function throttle(durationSelector: (value: T) => SubscribableOrPromise, +export function throttle(durationSelector: (value: T) => SubscribableOrPromise, config: ThrottleConfig = defaultThrottleConfig): MonoTypeOperatorFunction { return (source: Observable) => source.lift(new ThrottleOperator(durationSelector, config.leading, config.trailing)); } class ThrottleOperator implements Operator { - constructor(private durationSelector: (value: T) => SubscribableOrPromise, + constructor(private durationSelector: (value: T) => SubscribableOrPromise, private leading: boolean, private trailing: boolean) { } @@ -88,7 +88,7 @@ class ThrottleSubscriber extends OuterSubscriber { private _hasTrailingValue = false; constructor(protected destination: Subscriber, - private durationSelector: (value: T) => SubscribableOrPromise, + private durationSelector: (value: T) => SubscribableOrPromise, private _leading: boolean, private _trailing: boolean) { super(destination); diff --git a/src/internal/patching/operator/throttle.ts b/src/internal/patching/operator/throttle.ts index 5829716508..c2b2a77c1b 100644 --- a/src/internal/patching/operator/throttle.ts +++ b/src/internal/patching/operator/throttle.ts @@ -42,7 +42,7 @@ import { throttle as higherOrder, ThrottleConfig, defaultThrottleConfig } from ' * @owner Observable */ export function throttle(this: Observable, - durationSelector: (value: T) => SubscribableOrPromise, + durationSelector: (value: T) => SubscribableOrPromise, config: ThrottleConfig = defaultThrottleConfig): Observable { return higherOrder(durationSelector, config)(this); }