Skip to content

Commit 835153c

Browse files
falsyvaluesmportuga
authored andcommitted
fix(uiGridAutoResize): Asking for grid $elm sizing in a digest loop always triggers refresh, not conditionally as designed.
We allow `elementWidth` and `elementHeight` call only once per 200ms to prevent from perf degradation. Fixes #6561 #6499.
1 parent 626622a commit 835153c

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

src/features/auto-resize-grid/js/auto-resize.js

+20-15
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,35 @@
1919
require: 'uiGrid',
2020
scope: false,
2121
link: function($scope, $elm, $attrs, uiGridCtrl) {
22-
var timeout = null;
22+
var elementWidth,
23+
elementHeight;
2324

24-
var debounce = function(width, height) {
25-
if (timeout !== null) {
26-
clearTimeout(timeout);
27-
}
28-
timeout = setTimeout(function() {
29-
uiGridCtrl.grid.gridWidth = width;
30-
uiGridCtrl.grid.gridHeight = height;
31-
uiGridCtrl.grid.refresh();
32-
timeout = null;
33-
}, 400);
34-
};
25+
var updateWidth = gridUtil.throttle(function() {
26+
elementWidth = gridUtil.elementWidth($elm);
27+
}, 200);
28+
29+
var updateHeight = gridUtil.throttle(function() {
30+
elementHeight = gridUtil.elementHeight($elm);
31+
}, 200);
32+
33+
var refresh = gridUtil.throttle(function(width, height) {
34+
uiGridCtrl.grid.gridWidth = width;
35+
uiGridCtrl.grid.gridHeight = height;
36+
uiGridCtrl.grid.refresh();
37+
}, 300);
3538

3639
$scope.$watchGroup([
3740
function() {
38-
return gridUtil.elementWidth($elm);
41+
updateWidth();
42+
return elementWidth;
3943
},
4044
function() {
41-
return gridUtil.elementHeight($elm);
45+
updateHeight();
46+
return elementHeight;
4247
}
4348
], function(newValues, oldValues, scope) {
4449
if (!angular.equals(newValues, oldValues)) {
45-
debounce(newValues[0], newValues[1]);
50+
refresh(newValues[0], newValues[1]);
4651
}
4752
});
4853
}

0 commit comments

Comments
 (0)