| 192 | |
| 193 | // copied from https://www.30secondsofcode.org/js/s/throttle |
| 194 | export const throttle = (fn, wait) => { |
| 195 | let inThrottle, lastFn, lastTime; |
| 196 | return function() { |
| 197 | const context = this, |
| 198 | args = arguments; |
| 199 | if (!inThrottle) { |
| 200 | fn.apply(context, args); |
| 201 | lastTime = Date.now(); |
| 202 | inThrottle = true; |
| 203 | } else { |
| 204 | clearTimeout(lastFn); |
| 205 | lastFn = setTimeout(function() { |
| 206 | if (Date.now() - lastTime >= wait) { |
| 207 | fn.apply(context, args); |
| 208 | lastTime = Date.now(); |
| 209 | } |
| 210 | }, Math.max(wait - (Date.now() - lastTime), 0)); |
| 211 | } |
| 212 | }; |
| 213 | }; |
| 214 | |
| 215 | // copied from https://github.com/react-bootstrap/dom-helpers |
| 216 | let scrollbarSize; |