Skip to content

Commit

Permalink
fix(bufferCount): set default value for skip argument, do not emit em…
Browse files Browse the repository at this point in the history
…pty buffer at the end
  • Loading branch information
kwonoj committed Sep 5, 2015
1 parent e077230 commit 2c1a9dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 13 additions & 0 deletions spec/operators/bufferCount-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
7 changes: 5 additions & 2 deletions src/operators/bufferCount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BufferCountSubscriber<T> extends Subscriber<T> {
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;
Expand Down Expand Up @@ -64,7 +64,10 @@ class BufferCountSubscriber<T> extends Subscriber<T> {
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();
}
Expand Down

0 comments on commit 2c1a9dc

Please sign in to comment.