diff --git a/spec/operators/windowTime-spec.ts b/spec/operators/windowTime-spec.ts index 5aff47d00c8..ea0ef27a971 100644 --- a/spec/operators/windowTime-spec.ts +++ b/spec/operators/windowTime-spec.ts @@ -18,7 +18,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); @@ -26,6 +26,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 = '^ !'; @@ -35,9 +72,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); @@ -56,7 +93,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); @@ -69,7 +106,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('----------|'); @@ -84,7 +121,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('----------|'); @@ -105,7 +142,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); @@ -118,7 +155,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('----------|'); @@ -141,7 +178,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); @@ -163,7 +200,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); @@ -184,7 +221,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 3c563ee719a..9b8e616eca8 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