diff --git a/spec/operators/throttle-spec.ts b/spec/operators/throttle-spec.ts index 06e1d9bc13..81ce1eb6f0 100644 --- a/spec/operators/throttle-spec.ts +++ b/spec/operators/throttle-spec.ts @@ -7,6 +7,8 @@ declare const hot: typeof marbleTestingSignature.hot; declare const cold: typeof marbleTestingSignature.cold; declare const expectObservable: typeof marbleTestingSignature.expectObservable; declare const expectSubscriptions: typeof marbleTestingSignature.expectSubscriptions; +declare const time: typeof marbleTestingSignature.time; +declare const rxTestScheduler: typeof marbleTestingSignature.rxTestScheduler; const Observable = Rx.Observable; @@ -372,5 +374,14 @@ describe('Observable.prototype.throttle', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); expectSubscriptions(e2.subscriptions).toBe(e2subs); }); + + it('should work for individual values', () => { + const s1 = cold('---------x---------x--------x------|'); + const n = cold('----(n|)'); + const exp = '-------------x---------x--------x--|'; + + expectObservable(s1.throttle(() => n, { trailing: true })) + .toBe(exp); + }); }); }); diff --git a/src/operators/throttle.ts b/src/operators/throttle.ts index f8085bd38a..c87040c0c7 100644 --- a/src/operators/throttle.ts +++ b/src/operators/throttle.ts @@ -95,22 +95,17 @@ class ThrottleSubscriber extends OuterSubscriber { } protected _next(value: T): void { - if (this.throttled) { - if (this._trailing) { - this._hasTrailingValue = true; - this._trailingValue = value; - } - } else { + if (this._trailing) { + this._hasTrailingValue = true; + this._trailingValue = value; + } + if (!this.throttled) { const duration = this.tryDurationSelector(value); if (duration) { this.add(this.throttled = subscribeToResult(this, duration)); } if (this._leading) { this.destination.next(value); - if (this._trailing) { - this._hasTrailingValue = true; - this._trailingValue = value; - } } } }