Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update display, instead of toggling it #2215

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/js/tech/tech.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,25 +219,23 @@ class Tech extends Component {
}

let textTracksChanges = function() {
let updateDisplay = Fn.bind(this, function() {
this.trigger('texttrackchange');
});
let updateDisplay = () => this.trigger('texttrackchange');

this.trigger('texttrackchange');
updateDisplay();

for (let i = 0; i < this.length; i++) {
let track = this[i];
for (let i = 0; i < tracks.length; i++) {
let track = tracks[i];
track.removeEventListener('cuechange', updateDisplay);
if (track.mode === 'showing') {
track.addEventListener('cuechange', updateDisplay);
}
}
};

tracks.addEventListener('change', textTracksChanges);
tracks.addEventListener('change', Fn.bind(this, textTracksChanges));

this.on('dispose', Fn.bind(this, function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.on already does a Fn.bind(this internally, so this one is redundant.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

tracks.removeEventListener('change', textTracksChanges);
tracks.removeEventListener('change', Fn.bind(this, textTracksChanges));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could bind this when textTracksChanges is created so you don't have to do it when both adding and removing it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and done

}));
}

Expand Down
2 changes: 1 addition & 1 deletion src/js/tracks/text-track-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class TextTrackDisplay extends Component {
super(player, options, ready);

player.on('loadstart', Fn.bind(this, this.toggleDisplay));
player.on('texttrackchange', Fn.bind(this, this.toggleDisplay));
player.on('texttrackchange', Fn.bind(this, this.updateDisplay));

// This used to be called during player init, but was causing an error
// if a track should show by default and the display hadn't loaded yet.
Expand Down