Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/ui/public/debounce/debounce.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ module.service('debounce', ['$timeout', function ($timeout) {
let result;
options = _.defaults(options || {}, {
leading: false,
trailing: true
trailing: true,
invokeApply: true,
});

function debounce() {
Expand All @@ -32,7 +33,7 @@ module.service('debounce', ['$timeout', function ($timeout) {
if (timeout) {
$timeout.cancel(timeout);
}
timeout = $timeout(later, wait);
timeout = $timeout(later, wait, options.invokeApply);

if (callNow) {
result = func.apply(self, args);
Expand Down
17 changes: 9 additions & 8 deletions src/ui/public/directives/__tests__/fixed_scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import Promise from 'bluebird';
describe('FixedScroll directive', function () {

let compile;
let flushPendingTasks;
const trash = [];

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.module(function ($provide) {
$provide.service('debounce', () => {
return targetFunction => targetFunction;
});
}));
beforeEach(ngMock.inject(function ($compile, $rootScope) {
beforeEach(ngMock.inject(function ($compile, $rootScope, $timeout) {

flushPendingTasks = function flushPendingTasks() {
$rootScope.$digest();
$timeout.flush();
};

compile = function (ratioY, ratioX) {
if (ratioX == null) ratioX = ratioY;
Expand Down Expand Up @@ -46,7 +47,7 @@ describe('FixedScroll directive', function () {
}).appendTo($el);

$compile($parent)($rootScope);
$rootScope.$digest();
flushPendingTasks();

return {
$container: $el,
Expand Down Expand Up @@ -97,7 +98,7 @@ describe('FixedScroll directive', function () {

expect(off.callCount).to.be(0);
els.$container.width(els.$container.prop('scrollWidth'));
els.$container.scope().$digest();
flushPendingTasks();
expect(off.callCount).to.be(2);
checkThisVals('$.fn.off', off);

Expand Down
6 changes: 4 additions & 2 deletions src/ui/public/fixed_scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,16 @@ uiModules
const newWidth = $el.width();

if (scrollWidth !== newScrollWidth || width !== newWidth) {
setup();
$scope.$apply(setup);

scrollWidth = newScrollWidth;
width = newWidth;
}
}

const debouncedCheckWidth = debounce(checkWidth, 100);
const debouncedCheckWidth = debounce(checkWidth, 100, {
invokeApply: false,
});
$scope.$watch(debouncedCheckWidth);

// cleanup when the scope is destroyed
Expand Down