1/** 2 * Copyright © 2022 650 Industries. 3 * 4 * This source code is licensed under the MIT license found in the 5 * LICENSE file in the root directory of this source tree. 6 */ 7import { buildUrlForBundle } from './buildUrlForBundle'; 8import { fetchThenEvalAsync } from './fetchThenEval'; 9// import LoadingView from '../LoadingView'; 10let pendingRequests = 0; 11/** 12 * Load a bundle for a URL using fetch + eval on native and script tag injection on web. 13 * 14 * @param bundlePath Given a statement like `import('./Bacon')` `bundlePath` would be `Bacon.bundle?params=from-metro`. 15 */ 16export async function loadBundleAsync(bundlePath) { 17 const requestUrl = buildUrlForBundle(bundlePath); 18 if (process.env.NODE_ENV === 'production') { 19 return fetchThenEvalAsync(requestUrl); 20 } 21 else { 22 const LoadingView = require('../LoadingView') 23 .default; 24 // Send a signal to the `expo` package to show the loading indicator. 25 LoadingView.showMessage('Downloading...', 'load'); 26 pendingRequests++; 27 return fetchThenEvalAsync(requestUrl) 28 .then(() => { 29 if (process.env.NODE_ENV !== 'production') { 30 const HMRClient = require('../HMRClient') 31 .default; 32 HMRClient.registerBundle(requestUrl); 33 } 34 }) 35 .finally(() => { 36 if (!--pendingRequests) { 37 LoadingView.hide(); 38 } 39 }); 40 } 41} 42//# sourceMappingURL=loadBundle.js.map