Skip to content

Commit 73d2f7b

Browse files
fixed iteration logic
1 parent f8cc572 commit 73d2f7b

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

test/test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,19 @@ tf.test('stop thaw block', function() {
108108
tf.assertEquals(t.thaws[0].i === -1, true, 'is thawing');
109109
tf.assertEquals(t.thaws[1].i === -1, true, 'is thawing');
110110
tf.assertEquals(t.thaws[2].i === -1, true, 'is thawing');
111+
});
112+
113+
tf.test('thaw block iteration', function() {
114+
var t = new Thaw.Block({
115+
each: function() {
116+
117+
}
118+
},2);
119+
120+
t.addArray([0,1,2,3]);
121+
t.addArray([0,1,2,3]);
122+
t.addArray([0,1,2,3]);
123+
124+
tf.assertEquals(t.thaws[0].items.length === 8, true, 'added to correct array');
125+
tf.assertEquals(t.thaws[1].items.length === 4, true, 'added to correct array');
111126
});

thaw.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ var Thaw = (function(window) {
195195
Thaw.Block = function(options, count) {
196196
this.index = 0;
197197
this.thaws = [];
198-
this.count = 200 || count;
198+
this.count = count || 200;
199199
this.options = options;
200200
};
201201

@@ -207,7 +207,8 @@ var Thaw = (function(window) {
207207
* @returns {Thaw.Block}
208208
*/
209209
add: function(item) {
210-
this._next().add(item);
210+
var next = this._next();
211+
next.add(item);
211212

212213
return this;
213214
},
@@ -218,7 +219,9 @@ var Thaw = (function(window) {
218219
* @returns {Thaw.Block}
219220
*/
220221
addArray: function(items) {
221-
this._next().addArray(items);
222+
var next = this._next();
223+
next.addArray(items);
224+
222225
return this;
223226
},
224227

@@ -228,7 +231,9 @@ var Thaw = (function(window) {
228231
* @returns {Thaw.Block}
229232
*/
230233
insert: function(item) {
231-
this._next().insert(item);
234+
var next = this._next();
235+
next.insert(item);
236+
232237
return this;
233238
},
234239

@@ -238,7 +243,9 @@ var Thaw = (function(window) {
238243
* @returns {Thaw.Block}
239244
*/
240245
insertArray: function(items) {
241-
this._next().insertArray(items);
246+
var next = this._next();
247+
next.insertArray(items);
248+
242249
return this;
243250
},
244251

@@ -275,7 +282,7 @@ var Thaw = (function(window) {
275282
}
276283

277284
this.index++;
278-
if (this.index > this.count) {
285+
if (this.index >= this.count) {
279286
this.index = 0;
280287
}
281288

0 commit comments

Comments
 (0)