Skip to content

Commit 2c1a9dc

Browse files
committed
fix(bufferCount): set default value for skip argument, do not emit empty buffer at the end
1 parent e077230 commit 2c1a9dc

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

spec/operators/bufferCount-spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,17 @@ describe('Observable.prototype.bufferCount', function () {
1717
expect(w).toEqual(expected.shift())
1818
}, null, done);
1919
}, 2000);
20+
21+
it('should emit buffers at buffersize of intervals if not specified', function (done) {
22+
var expected = [
23+
[0, 1],
24+
[2, 3],
25+
[4, 5]
26+
];
27+
Observable.range(0, 6)
28+
.bufferCount(2)
29+
.subscribe(function (w) {
30+
expect(w).toEqual(expected.shift())
31+
}, null, done);
32+
}, 2000);
2033
});

src/operators/bufferCount.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class BufferCountSubscriber<T> extends Subscriber<T> {
3333
const count = (this.count += 1);
3434
const destination = this.destination;
3535
const bufferSize = this.bufferSize;
36-
const startBufferEvery = this.startBufferEvery;
36+
const startBufferEvery = (this.startBufferEvery == null) ? bufferSize : this.startBufferEvery;
3737
const buffers = this.buffers;
3838
const len = buffers.length;
3939
let remove = -1;
@@ -64,7 +64,10 @@ class BufferCountSubscriber<T> extends Subscriber<T> {
6464
const destination = this.destination;
6565
const buffers = this.buffers;
6666
while (buffers.length > 0) {
67-
destination.next(buffers.shift());
67+
var buffer = buffers.shift();
68+
if (buffer.length > 0) {
69+
destination.next(buffer);
70+
}
6871
}
6972
destination.complete();
7073
}

0 commit comments

Comments
 (0)