Skip to content

Commit

Permalink
fix(infiniteGrid): remove unnecessary layout call on resize
Browse files Browse the repository at this point in the history
if width is not changed, layout should be not called on resize event.

ref o-273, o-282
  • Loading branch information
sculove authored and Taihoon Kim committed Sep 20, 2016
1 parent f620065 commit 1e945a9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/infiniteGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ eg.module("infiniteGrid", ["jQuery", eg, window, document], function($, ns, glob
var self = this;
this._resizeTimeout = setTimeout(function() {
self._refreshViewport();
self.layout(self.items, true);
(self.$el.innerWidth() !== self._containerWidth) && self.layout(self.items, true);
self._resizeTimeout = null;
}, 100);
},
Expand Down
28 changes: 28 additions & 0 deletions test/unit/js/infiniteGrid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,4 +789,32 @@ QUnit.test("check a clear after scrolling", function(assert) {
done();
}, 100);
});
});

QUnit.test("if width is not changed, layout should be not called on resize event.", function(assert) {
// Given
var done = assert.async();
var resizeCount = 0;
var layoutCount = 0;
var $global = $(window);
var inst = this.inst = new eg.InfiniteGrid("#grid");
this.inst.on("layoutComplete", function(e) {
this.off("layoutComplete");
this.on("layoutComplete", function(e) {
assert.ok(false, "layoutComplete event should not be called");
});
});
$global.on("resize", function(e) {
resizeCount++;
});

// When
$global.trigger("resize");

// Then
setTimeout(function() {
assert.ok(resizeCount > 0, "should exist resize event");
assert.equal(inst.$el.innerWidth(), inst._containerWidth, "width is not changed");
done();
},100);
});

0 comments on commit 1e945a9

Please sign in to comment.