Skip to content

Commit

Permalink
fix(uiGridAutoResize): Asking for grid $elm sizing in a digest loop a…
Browse files Browse the repository at this point in the history
…lways triggers `refresh`, not conditionally as designed.

We allow `elementWidth` and `elementHeight` call only once per 200ms to prevent from perf degradation.

Fixes #6561 #6499.
  • Loading branch information
falsyvalues authored and mportuga committed Feb 3, 2018
1 parent 626622a commit 835153c
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/features/auto-resize-grid/js/auto-resize.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,35 @@
require: 'uiGrid',
scope: false,
link: function($scope, $elm, $attrs, uiGridCtrl) {
var timeout = null;
var elementWidth,
elementHeight;

var debounce = function(width, height) {
if (timeout !== null) {
clearTimeout(timeout);
}
timeout = setTimeout(function() {
uiGridCtrl.grid.gridWidth = width;
uiGridCtrl.grid.gridHeight = height;
uiGridCtrl.grid.refresh();
timeout = null;
}, 400);
};
var updateWidth = gridUtil.throttle(function() {
elementWidth = gridUtil.elementWidth($elm);
}, 200);

var updateHeight = gridUtil.throttle(function() {
elementHeight = gridUtil.elementHeight($elm);
}, 200);

var refresh = gridUtil.throttle(function(width, height) {
uiGridCtrl.grid.gridWidth = width;
uiGridCtrl.grid.gridHeight = height;
uiGridCtrl.grid.refresh();
}, 300);

$scope.$watchGroup([
function() {
return gridUtil.elementWidth($elm);
updateWidth();
return elementWidth;
},
function() {
return gridUtil.elementHeight($elm);
updateHeight();
return elementHeight;
}
], function(newValues, oldValues, scope) {
if (!angular.equals(newValues, oldValues)) {
debounce(newValues[0], newValues[1]);
refresh(newValues[0], newValues[1]);
}
});
}
Expand Down

0 comments on commit 835153c

Please sign in to comment.