export function unloadApplication(appName, opts={waitForUnmount: false}) { if (typeof appName !== 'string') { throw new Error(`unloadApplication requires a string 'appName'`); } const app = find(apps, App => App.name === appName); if (!app) { throw new Error(`Could not unload application '${appName}' because no such application has been declared`); } const appUnloadInfo = getAppUnloadInfo(app.name); if (opts && opts.waitForUnmount) { // We need to wait for unmount before unloading the app if (appUnloadInfo) { // Someone else is already waiting for this, too return appUnloadInfo.promise; } else { // We're the first ones wanting the app to be resolved. const promise = new Promise((resolve, reject) => { addAppToUnload(app, () => promise, resolve, reject); }); return promise; } } else { /* We should unmount the app, unload it, and remount it immediately. */ let resultPromise; if (appUnloadInfo) { // Someone else is already waiting for this app to unload resultPromise = appUnloadInfo.promise; immediatelyUnloadApp(app, appUnloadInfo.resolve, appUnloadInfo.reject); } else { // We're the first ones wanting the app to be resolved. resultPromise = new Promise((resolve, reject) => { addAppToUnload(app, () => resultPromise, resolve, reject); immediatelyUnloadApp(app, resolve, reject); }); } return resultPromise; } }
export function getAppStatus(appName) { const app = find(apps, app => app.name === appName); return app ? app.status : null; }
function isArrayOfFns(arr) { return Array.isArray(arr) && !find(arr, item => typeof item !== 'function'); }