1
0
mirror of https://github.com/videojs/video.js.git synced 2024-11-24 08:42:25 +02:00

refactor: component.ready() (#4693)

This commit is contained in:
Chuong 2017-10-31 23:04:07 +07:00 committed by Gary Katsevman
parent a1748aa590
commit b40858bc49

View File

@ -598,18 +598,21 @@ class Component {
* Returns itself; method can be chained.
*/
ready(fn, sync = false) {
if (fn) {
if (this.isReady_) {
if (sync) {
fn.call(this);
} else {
// Call the function asynchronously by default for consistency
this.setTimeout(fn, 1);
}
} else {
this.readyQueue_ = this.readyQueue_ || [];
this.readyQueue_.push(fn);
}
if (!fn) {
return;
}
if (!this.isReady_) {
this.readyQueue_ = this.readyQueue_ || [];
this.readyQueue_.push(fn);
return;
}
if (sync) {
fn.call(this);
} else {
// Call the function asynchronously by default for consistency
this.setTimeout(fn, 1);
}
}