From 58adb7624642cd8283a962a0d5eb015bdf9b5d17 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 30 Jul 2021 13:16:19 -0400 Subject: [PATCH] feat: allow requirejs modules to be awaited --- public/src/app.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/public/src/app.js b/public/src/app.js index 53d60ffe32..ed504fa00d 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -130,6 +130,20 @@ app.cacheBuster = null; }); }; + app.require = async (modules) => { // allows you to await require.js modules + let single = false; + if (!Array.isArray(modules)) { + modules = [modules]; + single = true; + } + + return new Promise((resolve, reject) => { + require(modules, (...exports) => { + resolve(single ? exports.pop() : exports); + }, reject); + }); + }; + app.logout = function (redirect) { redirect = redirect === undefined ? true : redirect; $(window).trigger('action:app.logout');