From 963c61d4d546c94b689281ca1f5105ad050e10ff Mon Sep 17 00:00:00 2001 From: Alex Dvornikov Date: Wed, 8 Nov 2017 07:44:43 -0800 Subject: [PATCH] Rename BundleFetcher to SegmentFetcher Reviewed By: jeanlauliac Differential Revision: D6271908 fbshipit-source-id: ed1259148ac5ca44789166e22d519a7a21f4cfd9 --- Libraries/Core/InitializeCore.js | 13 +++++++------ Libraries/Utilities/BundleSegments.js | 12 ++++++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Libraries/Core/InitializeCore.js b/Libraries/Core/InitializeCore.js index 90e9360cb90919..8a4e2218767836 100644 --- a/Libraries/Core/InitializeCore.js +++ b/Libraries/Core/InitializeCore.js @@ -206,16 +206,17 @@ BatchedBridge.registerLazyCallableModule('RCTDeviceEventEmitter', () => require( BatchedBridge.registerLazyCallableModule('RCTNativeAppEventEmitter', () => require('RCTNativeAppEventEmitter')); BatchedBridge.registerLazyCallableModule('PerformanceLogger', () => require('PerformanceLogger')); -global.fetchBundle = function( - bundleId: number, +global.fetchSegment = function( + segmentId: number, callback: (?Error) => void, ) { - const {BundleFetcher} = require('NativeModules'); - if (!BundleFetcher) { - throw new Error('BundleFetcher is missing'); + const {SegmentFetcher} = require('NativeModules'); + if (!SegmentFetcher) { + throw new Error('SegmentFetcher is missing. Please ensure that it is ' + + 'included as a NativeModule.'); } - BundleFetcher.fetchBundle(bundleId, (errorObject: ?{message: string, code: string}) => { + SegmentFetcher.fetchSegment(segmentId, (errorObject: ?{message: string, code: string}) => { if (errorObject) { const error = new Error(errorObject.message); (error: any).code = errorObject.code; diff --git a/Libraries/Utilities/BundleSegments.js b/Libraries/Utilities/BundleSegments.js index b7a2cd9332ff12..5b86b1b8aa8b57 100644 --- a/Libraries/Utilities/BundleSegments.js +++ b/Libraries/Utilities/BundleSegments.js @@ -17,7 +17,7 @@ let segmentLoaders = new Map(); /** * Ensure that a bundle segment is ready for use, for example requiring some of - * its module. We cache load promises so as to avoid calling `fetchBundle` twice + * its module. We cache load promises so as to avoid calling `fetchSegment` twice * for the same bundle. We assume that once a segment is fetched/loaded, it is * never gettting removed during this instance of the JavaScript VM. */ @@ -30,16 +30,16 @@ async function loadForModule(moduleID: number): Promise { if (segmentLoader != null) { return await segmentLoader; } - // FIXME: `fetchBundle` should be renamed `fetchSegment`. - const {fetchBundle} = global; - if (fetchBundle == null) { + + const {fetchSegment} = global; + if (fetchSegment == null) { throw new Error( - 'When bundle splitting is enabled, the `global.fetchBundle` function ' + + 'When bundle splitting is enabled, the `global.fetchSegment` function ' + 'must be provided to be able to load particular bundle segments.', ); } segmentLoader = new Promise((resolve, reject) => { - fetchBundle(segmentId, error => { + fetchSegment(segmentId, error => { if (error != null) { reject(error); return;