Permalink
Browse files

refactor: component.ready() (#4693)

  • Loading branch information...
kocoten1992 authored and gkatsev committed Oct 31, 2017
1 parent a1748aa commit b40858bc49ce3400ce30d22b6e44d8b53cca518e
Showing with 15 additions and 12 deletions.
  1. +15 −12 src/js/component.js
View
@@ -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);
}
}

0 comments on commit b40858b

Please sign in to comment.