Rename BundleFetcher to SegmentFetcher

Reviewed By: jeanlauliac

Differential Revision: D6271908

fbshipit-source-id: ed1259148ac5ca44789166e22d519a7a21f4cfd9
This commit is contained in:
Alex Dvornikov 2017-11-08 07:44:43 -08:00 committed by Facebook Github Bot
parent 16bbd908e7
commit 963c61d4d5
2 changed files with 13 additions and 12 deletions

View File

@ -206,16 +206,17 @@ BatchedBridge.registerLazyCallableModule('RCTDeviceEventEmitter', () => require(
BatchedBridge.registerLazyCallableModule('RCTNativeAppEventEmitter', () => require('RCTNativeAppEventEmitter')); BatchedBridge.registerLazyCallableModule('RCTNativeAppEventEmitter', () => require('RCTNativeAppEventEmitter'));
BatchedBridge.registerLazyCallableModule('PerformanceLogger', () => require('PerformanceLogger')); BatchedBridge.registerLazyCallableModule('PerformanceLogger', () => require('PerformanceLogger'));
global.fetchBundle = function( global.fetchSegment = function(
bundleId: number, segmentId: number,
callback: (?Error) => void, callback: (?Error) => void,
) { ) {
const {BundleFetcher} = require('NativeModules'); const {SegmentFetcher} = require('NativeModules');
if (!BundleFetcher) { if (!SegmentFetcher) {
throw new Error('BundleFetcher is missing'); 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) { if (errorObject) {
const error = new Error(errorObject.message); const error = new Error(errorObject.message);
(error: any).code = errorObject.code; (error: any).code = errorObject.code;

View File

@ -17,7 +17,7 @@ let segmentLoaders = new Map();
/** /**
* Ensure that a bundle segment is ready for use, for example requiring some of * 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 * 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. * never gettting removed during this instance of the JavaScript VM.
*/ */
@ -30,16 +30,16 @@ async function loadForModule(moduleID: number): Promise<void> {
if (segmentLoader != null) { if (segmentLoader != null) {
return await segmentLoader; return await segmentLoader;
} }
// FIXME: `fetchBundle` should be renamed `fetchSegment`.
const {fetchBundle} = global; const {fetchSegment} = global;
if (fetchBundle == null) { if (fetchSegment == null) {
throw new Error( 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.', 'must be provided to be able to load particular bundle segments.',
); );
} }
segmentLoader = new Promise((resolve, reject) => { segmentLoader = new Promise((resolve, reject) => {
fetchBundle(segmentId, error => { fetchSegment(segmentId, error => {
if (error != null) { if (error != null) {
reject(error); reject(error);
return; return;