1
0
mirror of https://github.com/videojs/video.js.git synced 2025-01-04 06:48:49 +02:00

fix: add debounced.cancel and use it in ResizeManager (#5378)

It's possible that ResizeManager will trigger its debounce handler but
then get disposed before the handler runs. This can cause tests to fail,
so, instead, we should cancel the debounce when ResizeManager is
disposed.
This commit is contained in:
Gary Katsevman 2018-08-13 16:39:50 -04:00 committed by GitHub
parent c3098eeadc
commit 8e9d92cc98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -114,6 +114,10 @@ class ResizeManager extends Component {
this.off('load', this.loadListener_);
}
if (this.debouncedHandler_) {
this.debouncedHandler_.cancel();
}
this.ResizeObserver = null;
this.resizeObserver = null;
this.debouncedHandler_ = null;

View File

@ -98,8 +98,13 @@ export const throttle = function(fn, wait) {
export const debounce = function(func, wait, immediate, context = window) {
let timeout;
const cancel = () => {
context.clearTimeout(timeout);
timeout = null;
};
/* eslint-disable consistent-this */
return function() {
const debounced = function() {
const self = this;
const args = arguments;
@ -119,4 +124,8 @@ export const debounce = function(func, wait, immediate, context = window) {
timeout = context.setTimeout(later, wait);
};
/* eslint-enable consistent-this */
debounced.cancel = cancel;
return debounced;
};