UNPKG

@bacons/expo-metro-runtime

Version:

Tools for making experimental Metro bundler features work

40 lines 1.61 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.loadBundleAsync = void 0; const react_native_1 = require("react-native"); const HMRClient_1 = __importDefault(require("../HMRClient")); const LoadingView_1 = __importDefault(require("../LoadingView")); const buildUrlForBundle_1 = require("./buildUrlForBundle"); const fetchThenEval_1 = require("./fetchThenEval"); let pendingRequests = 0; /** * Load a bundle for a URL using fetch + eval on native and script tag injection on web. * * @param bundlePath Given a statement like `import('./Bacon')` `bundlePath` would be `Bacon`. */ function loadBundleAsync(bundlePath) { const requestUrl = (0, buildUrlForBundle_1.buildUrlForBundle)(bundlePath, { modulesOnly: "true", runModule: "false", platform: react_native_1.Platform.OS, // The JavaScript loader does not support bytecode. runtimeBytecodeVersion: null, }); // Send a signal to the `expo` package to show the loading indicator. LoadingView_1.default.showMessage("Downloading...", "load"); pendingRequests++; return (0, fetchThenEval_1.fetchThenEvalAsync)(requestUrl) .then(() => { HMRClient_1.default.registerBundle(requestUrl); }) .finally(() => { if (!--pendingRequests) { LoadingView_1.default.hide(); } }); } exports.loadBundleAsync = loadBundleAsync; //# sourceMappingURL=loadBundlePolyfill.js.map