Skip to content
Permalink
Browse files

Remove event listeners if controls are removed

  • Loading branch information...
ferjm committed Jun 18, 2019
1 parent ef02196 commit ef5ded943cec8cd299c67095755a71833bfda56a
Showing with 11 additions and 6 deletions.
  1. +11 −6 resources/media-controls.js
@@ -80,11 +80,9 @@
// Get the instance of the host of these controls.
this.media = this.controls.host;

this.shutthingDown = false;
this.mutationObserver = new MutationObserver(() => {
// We can only get here if the `controls` attribute is removed.
this.shutthingDown = true;
this.mutationObserver.disconnect();
this.cleanup();
});
this.mutationObserver.observe(this.media, {
attributeFilter: ["controls"]
@@ -208,15 +206,22 @@
this.onStateChange(null);
}

cleanup() {
this.mutationObserver.disconnect();
this.mediaEvents.forEach(event => {
this.media.removeEventListener(event, this);
});
this.controlEvents.forEach(({ el, type }) => {
el.removeEventListener(type, this);
});
}

// State change handler
onStateChange(from) {
this.render(from);
}

render(from = this.state) {
if (this.shutthingDown) {
return;
}
const isAudioOnly = this.media.localName == "audio";
if (!isAudioOnly) {
// XXX This should ideally use clientHeight/clientWidth,

0 comments on commit ef5ded9

Please sign in to comment.
You can’t perform that action at this time.