Skip to content

Commit

Permalink
timeline: properly unsubscribe on destroy; resolve #848
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Dec 3, 2016
1 parent bf370ed commit 0699fc7
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions plugin/wavesurfer.timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ WaveSurfer.Timeline = {
var wavesurfer = this.wavesurfer = params.wavesurfer;

if (!this.wavesurfer) {
throw Error('No WaveSurfer intance provided');
throw Error('No WaveSurfer instance provided');
}

var drawer = this.drawer = this.wavesurfer.drawer;
Expand Down Expand Up @@ -42,12 +42,19 @@ WaveSurfer.Timeline = {
drawer.wrapper.addEventListener('scroll', function (e) {
this.updateScroll(e);
}.bind(this));
wavesurfer.on('redraw', this.render.bind(this));
wavesurfer.on('destroy', this.destroy.bind(this));

this._onRedraw = wavesurfer.on('redraw', this.render.bind(this));
this._onDestroy = wavesurfer.on('destroy', this.destroy.bind(this));
},

destroy: function () {
// Unsubscribe from internal wavesurfer events
this._onRedraw.un();
this._onDestroy.un();

// Unsubscribe from external timeline events
this.unAll();

if (this.wrapper && this.wrapper.parentNode) {
this.wrapper.parentNode.removeChild(this.wrapper);
this.wrapper = null;
Expand Down

0 comments on commit 0699fc7

Please sign in to comment.