Skip to content

Commit

Permalink
refactor: component.ready() (#4693)
Browse files Browse the repository at this point in the history
  • Loading branch information
kocoten1992 authored and gkatsev committed Oct 31, 2017
1 parent a1748aa commit b40858b
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/js/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit b40858b

Please sign in to comment.