Skip to content

Commit 644123a

Browse files
davidaureliofacebook-github-bot
authored andcommitted
Consolidate bundle URL creation
Summary: `DevServerHelper` had multiple places that created bundle URLs. This consolidates that logic into a single place, and uses an enum for different "bundle types" (bundle, bundle deltas, source maps). Reviewed By: pakoito Differential Revision: D6900906 fbshipit-source-id: 64ed9360ea85dc5755308d822d5fc55fe8cb5a55
1 parent 1ea3065 commit 644123a

File tree

1 file changed

+34
-28
lines changed

1 file changed

+34
-28
lines changed

Diff for: ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java

+34-28
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,22 @@ public interface SymbolicationListener {
106106
void onSymbolicationComplete(@Nullable Iterable<StackFrame> stackFrames);
107107
}
108108

109+
private enum BundleType {
110+
BUNDLE("bundle"),
111+
DELTA("delta"),
112+
MAP("map");
113+
114+
private final String mTypeID;
115+
116+
BundleType(String typeID) {
117+
mTypeID = typeID;
118+
}
119+
120+
public String typeID() {
121+
return mTypeID;
122+
}
123+
}
124+
109125
private final DevInternalSettings mSettings;
110126
private final OkHttpClient mClient;
111127
private final Handler mRestartOnChangePollingHandler;
@@ -427,16 +443,20 @@ private boolean getJSMinifyMode() {
427443
return mSettings.isJSMinifyEnabled();
428444
}
429445

430-
private static String createBundleURL(
431-
String host, String jsModulePath, boolean devMode, boolean jsMinify, boolean useDeltas) {
446+
private String createBundleURL(String mainModuleID, BundleType type, String host) {
432447
return String.format(
433448
Locale.US,
434449
BUNDLE_URL_FORMAT,
435450
host,
436-
jsModulePath,
437-
useDeltas ? "delta" : "bundle",
438-
devMode,
439-
jsMinify);
451+
mainModuleID,
452+
type.typeID(),
453+
getDevMode(),
454+
getJSMinifyMode());
455+
}
456+
457+
private String createBundleURL(String mainModuleID, BundleType type) {
458+
return createBundleURL(
459+
mainModuleID, type, mSettings.getPackagerConnectionSettings().getDebugServerHost());
440460
}
441461

442462
private static String createResourceURL(String host, String resourcePath) {
@@ -453,11 +473,10 @@ private static String createOpenStackFrameURL(String host) {
453473

454474
public String getDevServerBundleURL(final String jsModulePath) {
455475
return createBundleURL(
456-
mSettings.getPackagerConnectionSettings().getDebugServerHost(),
457-
jsModulePath,
458-
getDevMode(),
459-
getJSMinifyMode(),
460-
mSettings.isBundleDeltasEnabled());
476+
jsModulePath,
477+
mSettings.isBundleDeltasEnabled() ? BundleType.DELTA : BundleType.BUNDLE,
478+
mSettings.getPackagerConnectionSettings().getDebugServerHost()
479+
);
461480
}
462481

463482
public void isPackagerRunning(final PackagerStatusCallback callback) {
@@ -614,33 +633,20 @@ public void onResponse(Call call, Response response) throws IOException {
614633
}
615634

616635
public String getSourceMapUrl(String mainModuleName) {
617-
return String.format(
618-
Locale.US,
619-
BUNDLE_URL_FORMAT,
620-
mSettings.getPackagerConnectionSettings().getDebugServerHost(),
621-
mainModuleName,
622-
"map",
623-
getDevMode(),
624-
getJSMinifyMode());
636+
return createBundleURL(mainModuleName, BundleType.MAP);
625637
}
626638

627639
public String getSourceUrl(String mainModuleName) {
628-
return String.format(
629-
Locale.US,
630-
BUNDLE_URL_FORMAT,
631-
mSettings.getPackagerConnectionSettings().getDebugServerHost(),
632-
mainModuleName,
633-
mSettings.isBundleDeltasEnabled() ? "delta" : "bundle",
634-
getDevMode(),
635-
getJSMinifyMode());
640+
return createBundleURL(
641+
mainModuleName, mSettings.isBundleDeltasEnabled() ? BundleType.DELTA : BundleType.BUNDLE);
636642
}
637643

638644
public String getJSBundleURLForRemoteDebugging(String mainModuleName) {
639645
// The host we use when connecting to the JS bundle server from the emulator is not the
640646
// same as the one needed to connect to the same server from the JavaScript proxy running on the
641647
// host itself.
642648
return createBundleURL(
643-
getHostForJSProxy(), mainModuleName, getDevMode(), getJSMinifyMode(), false);
649+
mainModuleName, BundleType.BUNDLE, getHostForJSProxy());
644650
}
645651

646652
/**

0 commit comments

Comments
 (0)