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

refactor player.hasStarted() #4680

Merged
merged 4 commits into from
Oct 31, 2017
Merged
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
38 changes: 20 additions & 18 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ class Player extends Component {
// Turn off API access because we're loading a new tech that might load asynchronously
this.isReady_ = false;

// Init state hasStarted_
this.hasStarted_ = false;

// if the global option object was accidentally blown away by
// someone, bail early with an informative error
if (!this.options_ ||
Expand Down Expand Up @@ -1124,29 +1127,28 @@ class Player extends Component {
*
* @fires Player#firstplay
*
* @param {boolean} hasStarted
* @param {boolean} request
* - true: adds the class
* - false: remove the class
*
* @return {boolean}
* the boolean value of hasStarted
*/
hasStarted(hasStarted) {
if (hasStarted !== undefined) {
// only update if this is a new value
if (this.hasStarted_ !== hasStarted) {
this.hasStarted_ = hasStarted;
if (hasStarted) {
this.addClass('vjs-has-started');
// trigger the firstplay event if this newly has played
this.trigger('firstplay');
} else {
this.removeClass('vjs-has-started');
}
}
return;
* the boolean value of hasStarted_
*/
hasStarted(request) {
if (request === undefined || request === this.hasStarted_) {
Copy link
Member

Choose a reason for hiding this comment

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

A comment explaining that this is used as a getter or if the value isn't changing, we should just return what we have would be good

return this.hasStarted_;
}
return !!this.hasStarted_;

this.hasStarted_ = request;

if (this.hasStarted_) {
this.addClass('vjs-has-started');
this.trigger('firstplay');
} else {
this.removeClass('vjs-has-started');
}

return this.hasStarted_;
Copy link
Member

Choose a reason for hiding this comment

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

Our setters generally do not return anything.

Copy link
Member

Choose a reason for hiding this comment

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

As @gkatsev said, this is my only concern with the PR.

}

/**
Expand Down