BREAKING - (Re)moving JSBundleLoader.getSourceUrl()

Summary:
== What ==

Changing the `JSBundleLoader` API, to remove `String getSourceUrl()`, instead `JSBundleLoader.loadScript` now returns the source URL it loaded.

This change has a knock-on effect: We can no longer populate `SourceCodeModule` when we construct it, because at that time, we do not know the source URL.

In order to solve this I have made the following changes:

 -  Added `CatalystInstance.getSourceURL()`, to return the source URL from the instance after the JS Bundle has been loaded, or `null` otherwise.
 -  Removed `ReactInstanceManager.getSourceUrl()`, because its only purpose was to populate `SourceCodeModule`.
 -  Also removed `ReactInstanceManager.getJSBundleFile()` because it was only being used in a test confirming that the `ReactInstanceManager` knew its bundle file as soon as it was constructed, which is no longer necessarily true.
 -  Initialise `SourceCodeModule` with the `ReactContext` instance it belongs to.
 -  Override `NativeModule.initialize()` in `SourceCodeModule` to fetch the source URL. When the `SourceCodeModule` is constructed, the context does not have a properly initialised `CatalystInstance`, but by the time we call initialise on it, the `ReactContext` has a `CatalystInstance` and that in turn has a source URL.

== Why ==

The reason for this change is that it allows us to add implementations of `JSBundleLoader`, that cannot determine their source URL until after having performed a load successfully. In particular I plan to introduce `FallbackJSBundleLoader` which will try to load from multiple sources in sequence stopping after the first successful load. As load failures could happen for a variety of reasons, we can't know what the true source URL is without performing the load.

Reviewed By: javache

Differential Revision: D4398956

fbshipit-source-id: 51ff4e289c8723e9d242f23267181c775a6abe6f
This commit is contained in:
Ashok Menon
2017-01-13 03:52:07 -08:00
committed by Facebook Github Bot
parent 8e4f33e669
commit 89d72c99be
8 changed files with 44 additions and 61 deletions

View File

@@ -14,7 +14,9 @@ import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.BaseJavaModule;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.module.annotations.ReactModule;
/**
@@ -23,10 +25,21 @@ import com.facebook.react.module.annotations.ReactModule;
@ReactModule(name = "RCTSourceCode")
public class SourceCodeModule extends BaseJavaModule {
private final String mSourceUrl;
private final ReactContext mReactContext;
private @Nullable String mSourceUrl;
public SourceCodeModule(String sourceUrl) {
mSourceUrl = sourceUrl;
public SourceCodeModule(ReactContext reactContext) {
mReactContext = reactContext;
}
@Override
public void initialize() {
super.initialize();
mSourceUrl =
Assertions.assertNotNull(
mReactContext.getCatalystInstance().getSourceURL(),
"No source URL loaded, have you initialised the instance?");
}
@Override