Skip to content

Commit bffcc30

Browse files
authored
Merge pull request #47 from mderrick/cancel-throttle
#35 Stop throttled function from triggering an error when unmounted
2 parents c04c010 + 1fba4ed commit bffcc30

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/components/video/Video.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ var Video = React.createClass({
7575
* @return {undefined}
7676
*/
7777
componentWillMount() {
78-
// Also bind 'this' as we call _updateStateFromVideo outside
79-
// of Reacts synthetic events as well.
80-
this._updateStateFromVideo = throttle(this.updateStateFromVideo, 100).bind(this);
78+
this._updateStateFromVideo = throttle(this.updateStateFromVideo, 100);
8179
// Set up all React media events and call method
8280
// on props if provided.
8381
this.mediaEventProps = EVENTS.reduce((p, c) => {
@@ -111,6 +109,10 @@ var Video = React.createClass({
111109
// Remove event listener from video.
112110
this.videoEl.children[this.videoEl.children.length - 1]
113111
.removeEventListener('error', this._updateStateFromVideo);
112+
// Cancel the throttled function from being called once
113+
// the video has been unmounted.
114+
// https://github.com/mderrick/react-html5video/issues/35
115+
this._updateStateFromVideo.cancel();
114116
},
115117

116118
/**

0 commit comments

Comments
 (0)