From 2c1a9dc376aa7afef76e4c7b31826dce1efaba03 Mon Sep 17 00:00:00 2001 From: kwonoj Date: Sat, 5 Sep 2015 00:06:18 -0700 Subject: [PATCH] fix(bufferCount): set default value for skip argument, do not emit empty buffer at the end --- spec/operators/bufferCount-spec.js | 13 +++++++++++++ src/operators/bufferCount.ts | 7 +++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/spec/operators/bufferCount-spec.js b/spec/operators/bufferCount-spec.js index baf68719dd..853b399d4b 100644 --- a/spec/operators/bufferCount-spec.js +++ b/spec/operators/bufferCount-spec.js @@ -17,4 +17,17 @@ describe('Observable.prototype.bufferCount', function () { expect(w).toEqual(expected.shift()) }, null, done); }, 2000); + + it('should emit buffers at buffersize of intervals if not specified', function (done) { + var expected = [ + [0, 1], + [2, 3], + [4, 5] + ]; + Observable.range(0, 6) + .bufferCount(2) + .subscribe(function (w) { + expect(w).toEqual(expected.shift()) + }, null, done); + }, 2000); }); \ No newline at end of file diff --git a/src/operators/bufferCount.ts b/src/operators/bufferCount.ts index c4dd7bfd15..efb98f9a32 100644 --- a/src/operators/bufferCount.ts +++ b/src/operators/bufferCount.ts @@ -33,7 +33,7 @@ class BufferCountSubscriber extends Subscriber { const count = (this.count += 1); const destination = this.destination; const bufferSize = this.bufferSize; - const startBufferEvery = this.startBufferEvery; + const startBufferEvery = (this.startBufferEvery == null) ? bufferSize : this.startBufferEvery; const buffers = this.buffers; const len = buffers.length; let remove = -1; @@ -64,7 +64,10 @@ class BufferCountSubscriber extends Subscriber { const destination = this.destination; const buffers = this.buffers; while (buffers.length > 0) { - destination.next(buffers.shift()); + var buffer = buffers.shift(); + if (buffer.length > 0) { + destination.next(buffer); + } } destination.complete(); }