Convert load callbacks to async/await (#3050)

Another one of these PRs....
This commit is contained in:
Veeck 2023-02-22 20:03:05 +01:00 committed by GitHub
parent 498b440174
commit b5b61246e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 66 deletions

View file

@ -261,43 +261,42 @@ const Module = Class.extend({
/**
* Load all required stylesheets by requesting the MM object to load the files.
*
* @param {Function} callback Function called when done.
* @returns {Promise<void>}
*/
loadStyles: function (callback) {
this.loadDependencies("getStyles", callback);
loadStyles: function () {
return this.loadDependencies("getStyles");
},
/**
* Load all required scripts by requesting the MM object to load the files.
*
* @param {Function} callback Function called when done.
* @returns {Promise<void>}
*/
loadScripts: function (callback) {
this.loadDependencies("getScripts", callback);
loadScripts: function () {
return this.loadDependencies("getScripts");
},
/**
* Helper method to load all dependencies.
*
* @param {string} funcName Function name to call to get scripts or styles.
* @param {Function} callback Function called when done.
* @returns {Promise<void>}
*/
loadDependencies: function (funcName, callback) {
loadDependencies: async function (funcName) {
let dependencies = this[funcName]();
const loadNextDependency = () => {
const loadNextDependency = async () => {
if (dependencies.length > 0) {
const nextDependency = dependencies[0];
Loader.loadFile(nextDependency, this, () => {
dependencies = dependencies.slice(1);
loadNextDependency();
});
await Loader.loadFileForModule(nextDependency, this);
dependencies = dependencies.slice(1);
await loadNextDependency();
} else {
callback();
return Promise.resolve();
}
};
loadNextDependency();
await loadNextDependency();
},
/**