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 component.ready() #4693

Merged
merged 1 commit into from
Oct 31, 2017
Merged
Changes from all 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
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);
Copy link
Contributor

Choose a reason for hiding this comment

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

You could return after this and get rid of the else here, I think that it would fit better with the new flow of this function.

Copy link
Contributor Author

@kocoten1992 kocoten1992 Oct 26, 2017

Choose a reason for hiding this comment

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

Uhm no, the point was to easy read/debug, abusing that in only 4 line of code would make thing harder

But feel free to edit anyway

} else {
// Call the function asynchronously by default for consistency
this.setTimeout(fn, 1);
}
}

Expand Down