Skip to content

Commit

Permalink
fix: resize event listeners to be removed on destroy()
Browse files Browse the repository at this point in the history
  • Loading branch information
yitengjun committed May 8, 2022
1 parent 7bc5fd9 commit 839a5a7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/ukiyo.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class Ukiyo {

// Resize properties
this.timer = null;
this.reset = this.reset.bind(this);
this.resizeEvent = this.resize.bind(this);

this.observer = null;
this.requestId = null;
Expand Down Expand Up @@ -273,9 +273,9 @@ export default class Ukiyo {
_addEvent() {
// Resize Event
if (navigator.userAgent.match(/(iPhone|iPad|iPod|Android)/)) {
window.addEventListener('orientationchange', this.resize.bind(this));
window.addEventListener('orientationchange', this.resizeEvent);
} else {
window.addEventListener('resize', this.resize.bind(this));
window.addEventListener('resize', this.resizeEvent);
}
}

Expand All @@ -284,7 +284,7 @@ export default class Ukiyo {
*/
resize() {
clearTimeout(this.timer);
this.timer = setTimeout(this.reset, 450);
this.timer = setTimeout(this.reset.bind(this), 450);
}

/**
Expand Down Expand Up @@ -338,6 +338,9 @@ export default class Ukiyo {

this.wrapper.replaceWith(...this.wrapper.childNodes);

window.removeEventListener('resize', this.resizeEvent);
window.removeEventListener('orientationchange', this.resizeEvent);

this.isInit = false;
}
}

0 comments on commit 839a5a7

Please sign in to comment.