From e7b64b9072f89658c36e3a7459f373fe03f66412 Mon Sep 17 00:00:00 2001 From: Chuong Date: Mon, 23 Oct 2017 02:09:51 +0700 Subject: [PATCH 1/4] refactor player.hasStarted() update doc on hasStarted() I feel 'request' are more suitable than hasStarted (variable) because when I do "if (request === undefined)", it mean if you don't have any request, then we just return current status, it a bit more clear --- src/js/player.js | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/js/player.js b/src/js/player.js index 50d0fbe618..addd0879bf 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -314,6 +314,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 @@ -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_) { + 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_; + + return this.hasStarted_; } /** From d22370e2377f6a8a197046fa99fe08dc46eaa0f6 Mon Sep 17 00:00:00 2001 From: Chuong Date: Mon, 23 Oct 2017 02:25:57 +0700 Subject: [PATCH 2/4] fix style --- src/js/player.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/js/player.js b/src/js/player.js index addd0879bf..ed6537dccb 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -314,8 +314,8 @@ 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_ + + // Init state hasStarted_ this.hasStarted_ = false; // if the global option object was accidentally blown away by @@ -1138,16 +1138,16 @@ class Player extends Component { if (request === undefined || request === 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_; } From 10edd4ca16ba8e9cb0bb2085ef3908edeb6429ee Mon Sep 17 00:00:00 2001 From: Chuong Date: Tue, 24 Oct 2017 13:07:57 +0700 Subject: [PATCH 3/4] setter should return nothing, add comment getter --- src/js/player.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/js/player.js b/src/js/player.js index ed6537dccb..6837d4c4bd 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -1135,9 +1135,14 @@ class Player extends Component { * the boolean value of hasStarted_ */ hasStarted(request) { - if (request === undefined || request === this.hasStarted_) { + if (request === undefined) { + // act as getter, if we have no request to change return this.hasStarted_; } + + if (request === this.hasStarted_) { + return; + } this.hasStarted_ = request; @@ -1147,8 +1152,6 @@ class Player extends Component { } else { this.removeClass('vjs-has-started'); } - - return this.hasStarted_; } /** From e8818100508a9ffb88920db91014633122bd3deb Mon Sep 17 00:00:00 2001 From: Chuong Date: Tue, 24 Oct 2017 13:15:44 +0700 Subject: [PATCH 4/4] fix style --- src/js/player.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/player.js b/src/js/player.js index 6837d4c4bd..7184a490ce 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -1139,7 +1139,7 @@ class Player extends Component { // act as getter, if we have no request to change return this.hasStarted_; } - + if (request === this.hasStarted_) { return; }