Skip to content

Commit

Permalink
Use debounce instead of timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Bargs committed Dec 19, 2016
1 parent b642ba6 commit a260f69
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/ui/public/fixed_scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const SCROLLER_HEIGHT = 20;
*/
uiModules
.get('kibana')
.directive('fixedScroll', function ($timeout) {
.directive('fixedScroll', function (debounce) {
return {
restrict: 'A',
link: function ($scope, $el) {
Expand Down Expand Up @@ -105,7 +105,6 @@ uiModules

let width;
let scrollWidth;
let widthCheckTimeout = $timeout(checkWidth, 500);
function checkWidth() {
const newScrollWidth = $el.prop('scrollWidth');
const newWidth = $el.width();
Expand All @@ -116,15 +115,14 @@ uiModules

scrollWidth = newScrollWidth;
width = newWidth;

widthCheckTimeout = $timeout(checkWidth, 500);
}

$scope.$watch(debounce(checkWidth, 100));

// cleanup when the scope is destroyed
$scope.$on('$destroy', function () {
cleanUp();
$scroller = $window = null;
$timeout.cancel(widthCheckTimeout);
});
}
};
Expand Down

0 comments on commit a260f69

Please sign in to comment.