Skip to content

Commit

Permalink
fix(pb-mixin): fix bug in wait method introduced by 189d5a1
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgangmm committed May 19, 2024
1 parent b16730a commit afb665d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/pb-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,7 @@ export const pbMixin = (superclass) => class PbMixin extends superclass {
* @param {Function} callback function to be called when all components are ready
*/
wait(callback) {
if (!this.waitFor) {
callback();
return;
}
window.addEventListener('DOMContentLoaded', () => {
const _checkAndWait = () => {
const targetNodes = Array.from(document.querySelectorAll(this.waitFor));
const targets = targetNodes.filter(target => this.emitsOnSameChannel(target));
const targetCount = targets.length;
Expand Down Expand Up @@ -247,7 +243,19 @@ export const pbMixin = (superclass) => class PbMixin extends superclass {
}
});
});
});
}

if (!this.waitFor) {
callback();
return;
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
_checkAndWait();
});
} else {
_checkAndWait();
}
}

/**
Expand Down

0 comments on commit afb665d

Please sign in to comment.