From b52e5d50319871edb2815fff444ef2ff45789f75 Mon Sep 17 00:00:00 2001 From: Adrien Denat Date: Sat, 14 Jul 2018 20:54:21 +0200 Subject: [PATCH] Switch from debounce to throttle so method is called at regular time (fix #166) --- packages/simplebar/package.json | 2 +- packages/simplebar/src/simplebar.js | 6 ++---- yarn.lock | 4 ++++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/simplebar/package.json b/packages/simplebar/package.json index 48b3f093..77ac735a 100644 --- a/packages/simplebar/package.json +++ b/packages/simplebar/package.json @@ -24,7 +24,7 @@ "test:e2e": "jest -c jest-e2e.config.js" }, "dependencies": { - "lodash.debounce": "^4.0.8", + "lodash.throttle": "^4.1.1", "resize-observer-polyfill": "^1.5.0", "scrollbarwidth": "^0.1.3" }, diff --git a/packages/simplebar/src/simplebar.js b/packages/simplebar/src/simplebar.js index fff412fb..4c6c1039 100755 --- a/packages/simplebar/src/simplebar.js +++ b/packages/simplebar/src/simplebar.js @@ -1,5 +1,5 @@ import scrollbarWidth from 'scrollbarwidth'; -import debounce from 'lodash.debounce'; +import throttle from 'lodash.throttle'; import ResizeObserver from 'resize-observer-polyfill'; export default class SimpleBar { @@ -25,9 +25,7 @@ export default class SimpleBar { this.classNames = this.options.classNames; this.offsetSize = 20; - this.recalculate = debounce(this.recalculate.bind(this), 1000, { - leading: true - }); + this.recalculate = throttle(this.recalculate.bind(this), 1000); this.init(); } diff --git a/yarn.lock b/yarn.lock index 8bb2cee3..ebd8c149 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5920,6 +5920,10 @@ lodash.templatesettings@^4.0.0: dependencies: lodash._reinterpolate "~3.0.0" +lodash.throttle@^4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/lodash.throttle/-/lodash.throttle-4.1.1.tgz#c23e91b710242ac70c37f1e1cda9274cc39bf2f4" + lodash.unescape@4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/lodash.unescape/-/lodash.unescape-4.0.1.tgz#bf2249886ce514cda112fae9218cdc065211fc9c"