Skip to content

Commit

Permalink
Rename BundleFetcher to SegmentFetcher
Browse files Browse the repository at this point in the history
Reviewed By: jeanlauliac

Differential Revision: D6271908

fbshipit-source-id: ed1259148ac5ca44789166e22d519a7a21f4cfd9
  • Loading branch information
fromcelticpark authored and facebook-github-bot committed Nov 8, 2017
1 parent 16bbd90 commit 963c61d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
13 changes: 7 additions & 6 deletions Libraries/Core/InitializeCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions Libraries/Utilities/BundleSegments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -30,16 +30,16 @@ async function loadForModule(moduleID: number): Promise<void> {
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;
Expand Down

0 comments on commit 963c61d

Please sign in to comment.