From 452ac1b58e5eb5db470fbda9cfdbded277e92ccc Mon Sep 17 00:00:00 2001 From: Alex Dvornikov Date: Thu, 12 Oct 2017 09:20:17 -0700 Subject: [PATCH] Added "fetchBundle" global function Reviewed By: jeanlauliac Differential Revision: D5985425 fbshipit-source-id: 72de85d354e85b8f7d98c95d5aa5348484d26204 --- Libraries/Core/InitializeCore.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Libraries/Core/InitializeCore.js b/Libraries/Core/InitializeCore.js index 4cd6754ee01f6d..4531b114efd90f 100644 --- a/Libraries/Core/InitializeCore.js +++ b/Libraries/Core/InitializeCore.js @@ -222,6 +222,26 @@ BatchedBridge.registerLazyCallableModule('RCTDeviceEventEmitter', () => require( BatchedBridge.registerLazyCallableModule('RCTNativeAppEventEmitter', () => require('RCTNativeAppEventEmitter')); BatchedBridge.registerLazyCallableModule('PerformanceLogger', () => require('PerformanceLogger')); +global.fetchBundle = function( + bundleId: number, + callback: (?Error) => void, +) { + const {BundleFetcher} = require('NativeModules'); + if (!BundleFetcher) { + throw new Error('BundleFetcher is missing'); + } + + BundleFetcher.fetchBundle(bundleId, (errorObject: ?{message: string, code: string}) => { + if (errorObject) { + const error = new Error(errorObject.message); + (error: any).code = errorObject.code; + callback(error); + } + + callback(null); + }); +}; + // Set up devtools if (__DEV__) { if (!global.__RCTProfileIsProfiling) {