Skip to content

Commit

Permalink
Remove _fireOnDomLoad (#845)
Browse files Browse the repository at this point in the history
We can remove the `_fireOnDomLoad` from the manual initializer because the setup function itself is called during `DOMContentLoaded`

J=none
TEST=manual

Smoke test runtime config and manual initialization
  • Loading branch information
cea2aj authored Jun 23, 2021
1 parent 86cfe45 commit 4320780
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions static/js/manual-initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,14 @@ export default class ManualInitializer {
);
}, 5000);
window.AnswersExperience.init = (config = {}) => {
this._fireOnDomLoad(() => {
Object.entries(config).forEach(([key, value]) => {
window.AnswersExperience.runtimeConfig.set(key, value);
});
clearTimeout(runtimeConfigNotProvidedTimeout);
if (!this._hasAnswersInitialized) {
this._initAnswers();
}
this._hasAnswersInitialized = true;
Object.entries(config).forEach(([key, value]) => {
window.AnswersExperience.runtimeConfig.set(key, value);
});
}
}

/**
* Executes the provided function on DOM load
* @param {Function} cb
*/
_fireOnDomLoad (cb) {
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', cb);
} else {
cb();
clearTimeout(runtimeConfigNotProvidedTimeout);
if (!this._hasAnswersInitialized) {
this._initAnswers();
}
this._hasAnswersInitialized = true;
}
}
}

0 comments on commit 4320780

Please sign in to comment.