diff --git a/spec/operators/windowTime-spec.ts b/spec/operators/windowTime-spec.ts index 7709c38660..b8dd9a41df 100644 --- a/spec/operators/windowTime-spec.ts +++ b/spec/operators/windowTime-spec.ts @@ -23,7 +23,7 @@ describe('Observable.prototype.windowTime', () => { const x = cold( '--a--(b|) '); const y = cold( '-d--e| '); const z = cold( '-g--h| '); - const values = { x: x, y: y, z: z }; + const values = { x, y, z }; const result = source.windowTime(50, 100, rxTestScheduler); @@ -31,6 +31,43 @@ describe('Observable.prototype.windowTime', () => { expectSubscriptions(source.subscriptions).toBe(subs); }); + it('should close windows after max count is reached', () => { + const source = hot('--1--2--^--a--b--c--d--e--f--g-----|'); + const subs = '^ !'; + const timeSpan = time( '----------|'); + // 100 frames 0---------1---------2------| + const expected = 'x---------y---------z------|'; + const x = cold( '---a--(b|) '); + const y = cold( '--d--(e|) '); + const z = cold( '-g-----|'); + const values = { x, y, z }; + + const result = source.windowTime(timeSpan, null, 2, rxTestScheduler); + + expectObservable(result).toBe(expected, values); + expectSubscriptions(source.subscriptions).toBe(subs); + }); + + it('should close window after max count is reached with' + + 'windowCreationInterval', () => { + const source = hot('--1--2--^-a--b--c--de-f---g--h--i-|'); + const subs = '^ !'; + // 100 frames 0---------1---------2-----| + // 50 ----| + // 50 ----| + // 50 ----| + const expected = 'x---------y---------z-----|'; + const x = cold( '--a--(b|) '); + const y = cold( '-de-(f|) '); + const z = cold( '-h--i| '); + const values = { x, y, z }; + + const result = source.windowTime(50, 100, 3, rxTestScheduler); + + expectObservable(result).toBe(expected, values); + expectSubscriptions(source.subscriptions).toBe(subs); + }); + it('should emit windows given windowTimeSpan', () => { const source = hot('--1--2--^--a--b--c--d--e--f--g--h--|'); const subs = '^ !'; @@ -40,9 +77,9 @@ describe('Observable.prototype.windowTime', () => { const x = cold( '---a--b--c| '); const y = cold( '--d--e--f-| '); const z = cold( '-g--h--|'); - const values = { x: x, y: y, z: z }; + const values = { x, y, z }; - const result = source.windowTime(timeSpan, null, rxTestScheduler); + const result = source.windowTime(timeSpan, rxTestScheduler); expectObservable(result).toBe(expected, values); expectSubscriptions(source.subscriptions).toBe(subs); @@ -61,7 +98,7 @@ describe('Observable.prototype.windowTime', () => { const x = cold( '---a-| '); const y = cold( '--d--(e|) '); const z = cold( '-g--h| '); - const values = { x: x, y: y, z: z }; + const values = { x, y, z }; const result = source.windowTime(timeSpan, interval, rxTestScheduler); @@ -74,7 +111,7 @@ describe('Observable.prototype.windowTime', () => { const subs = '(^!)'; const expected = '(w|)'; const w = cold('|'); - const expectedValues = { w: w }; + const expectedValues = { w }; const timeSpan = time('-----|'); const interval = time('----------|'); @@ -89,7 +126,7 @@ describe('Observable.prototype.windowTime', () => { const subs = '(^!)'; const expected = '(w|)'; const w = cold('(a|)'); - const expectedValues = { w: w }; + const expectedValues = { w }; const timeSpan = time('-----|'); const interval = time('----------|'); @@ -110,7 +147,7 @@ describe('Observable.prototype.windowTime', () => { const c = cold( '---| '); const d = cold( '--'); const unsub = ' !'; - const expectedValues = { a: a, b: b, c: c, d: d }; + const expectedValues = { a, b, c, d }; const result = source.windowTime(timeSpan, interval, rxTestScheduler); @@ -123,7 +160,7 @@ describe('Observable.prototype.windowTime', () => { const subs = '(^!)'; const expected = '(w#)'; const w = cold('#'); - const expectedValues = { w: w }; + const expectedValues = { w }; const timeSpan = time('-----|'); const interval = time('----------|'); @@ -146,7 +183,7 @@ describe('Observable.prototype.windowTime', () => { const x = cold( '---a-| '); const y = cold( '--d--(e|) '); const z = cold( '-g--h| '); - const values = { x: x, y: y, z: z }; + const values = { x, y, z }; const result = source.windowTime(timeSpan, interval, rxTestScheduler); @@ -168,7 +205,7 @@ describe('Observable.prototype.windowTime', () => { const x = cold( '---a-| '); const y = cold( '-- '); const unsub = ' ! '; - const values = { x: x, y: y }; + const values = { x, y }; const result = source.windowTime(timeSpan, interval, rxTestScheduler); @@ -189,7 +226,7 @@ describe('Observable.prototype.windowTime', () => { const x = cold( '---a-| '); const y = cold( '--d-- '); const unsub = ' ! '; - const values = { x: x, y: y }; + const values = { x, y }; const result = source .mergeMap((x: string) => Observable.of(x)) diff --git a/src/operator/windowTime.ts b/src/operator/windowTime.ts index 3c563ee719..a1f9964a5b 100644 --- a/src/operator/windowTime.ts +++ b/src/operator/windowTime.ts @@ -6,6 +6,8 @@ import { async } from '../scheduler/async'; import { Subscriber } from '../Subscriber'; import { Observable } from '../Observable'; import { Subscription } from '../Subscription'; +import { isNumeric } from '../util/isNumeric'; +import { isScheduler } from '../util/isScheduler'; /** * Branch out the source Observable values as a nested Observable periodically @@ -24,7 +26,10 @@ import { Subscription } from '../Subscription'; * emits the current window and propagates the notification from the source * Observable. If `windowCreationInterval` is not provided, the output * Observable starts a new window when the previous window of duration - * `windowTimeSpan` completes. + * `windowTimeSpan` completes. If `maxWindowCount` is provided, each window + * will emit at most fixed number of values. Window will complete immediately + * after emitting last value and next one still will open as specified by + * `windowTimeSpan` and `windowCreationInterval` arguments. * * @example