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