`CatalystInstanceImpl`: Method for loading from delta client

Summary:
Adds `loadScriptFromDeltaBundle` / `jniLoadScriptFromDeltaBundle` methods to `CatalystInstanceImpl`.

These methods allow to run JS coming from a native delta client as RAM bundles, to leverage the RAM bundle mechanism for development / reload scenarios.

Reviewed By: fromcelticpark

Differential Revision: D7845140

fbshipit-source-id: b79b340f36c28939a31eb63a3c463d0792a208f7
This commit is contained in:
David Aurelio 2018-05-03 08:38:06 -07:00 committed by Facebook Github Bot
parent 82b8a9221a
commit 36f254aa75
3 changed files with 29 additions and 0 deletions

View File

@ -221,10 +221,19 @@ public class CatalystInstanceImpl implements CatalystInstance {
jniLoadScriptFromFile(fileName, sourceURL, loadSynchronously); jniLoadScriptFromFile(fileName, sourceURL, loadSynchronously);
} }
/* package */ void loadScriptFromDeltaBundle(
String sourceURL,
NativeDeltaClient deltaClient,
boolean loadSynchronously) {
mSourceURL = sourceURL;
jniLoadScriptFromDeltaBundle(sourceURL, deltaClient, loadSynchronously);
}
private native void jniSetSourceURL(String sourceURL); private native void jniSetSourceURL(String sourceURL);
private native void jniRegisterSegment(int segmentId, String path); private native void jniRegisterSegment(int segmentId, String path);
private native void jniLoadScriptFromAssets(AssetManager assetManager, String assetURL, boolean loadSynchronously); private native void jniLoadScriptFromAssets(AssetManager assetManager, String assetURL, boolean loadSynchronously);
private native void jniLoadScriptFromFile(String fileName, String sourceURL, boolean loadSynchronously); private native void jniLoadScriptFromFile(String fileName, String sourceURL, boolean loadSynchronously);
private native void jniLoadScriptFromDeltaBundle(String sourceURL, NativeDeltaClient deltaClient, boolean loadSynchronously);
@Override @Override
public void runJSBundle() { public void runJSBundle() {

View File

@ -4,17 +4,21 @@
#include <mutex> #include <mutex>
#include <condition_variable> #include <condition_variable>
#include <sstream>
#include <vector>
#include <cxxreact/CxxNativeModule.h> #include <cxxreact/CxxNativeModule.h>
#include <cxxreact/Instance.h> #include <cxxreact/Instance.h>
#include <cxxreact/JSBigString.h> #include <cxxreact/JSBigString.h>
#include <cxxreact/JSBundleType.h> #include <cxxreact/JSBundleType.h>
#include <cxxreact/JSDeltaBundleClient.h>
#include <cxxreact/JSIndexedRAMBundle.h> #include <cxxreact/JSIndexedRAMBundle.h>
#include <cxxreact/MethodCall.h> #include <cxxreact/MethodCall.h>
#include <cxxreact/ModuleRegistry.h> #include <cxxreact/ModuleRegistry.h>
#include <cxxreact/RecoverableError.h> #include <cxxreact/RecoverableError.h>
#include <cxxreact/RAMBundleRegistry.h> #include <cxxreact/RAMBundleRegistry.h>
#include <fb/log.h> #include <fb/log.h>
#include <fb/fbjni/ByteBuffer.h>
#include <folly/dynamic.h> #include <folly/dynamic.h>
#include <folly/Memory.h> #include <folly/Memory.h>
#include <jni/Countable.h> #include <jni/Countable.h>
@ -100,6 +104,7 @@ void CatalystInstanceImpl::registerNatives() {
makeNativeMethod("jniRegisterSegment", CatalystInstanceImpl::jniRegisterSegment), makeNativeMethod("jniRegisterSegment", CatalystInstanceImpl::jniRegisterSegment),
makeNativeMethod("jniLoadScriptFromAssets", CatalystInstanceImpl::jniLoadScriptFromAssets), makeNativeMethod("jniLoadScriptFromAssets", CatalystInstanceImpl::jniLoadScriptFromAssets),
makeNativeMethod("jniLoadScriptFromFile", CatalystInstanceImpl::jniLoadScriptFromFile), makeNativeMethod("jniLoadScriptFromFile", CatalystInstanceImpl::jniLoadScriptFromFile),
makeNativeMethod("jniLoadScriptFromDeltaBundle", CatalystInstanceImpl::jniLoadScriptFromDeltaBundle),
makeNativeMethod("jniCallJSFunction", CatalystInstanceImpl::jniCallJSFunction), makeNativeMethod("jniCallJSFunction", CatalystInstanceImpl::jniCallJSFunction),
makeNativeMethod("jniCallJSCallback", CatalystInstanceImpl::jniCallJSCallback), makeNativeMethod("jniCallJSCallback", CatalystInstanceImpl::jniCallJSCallback),
makeNativeMethod("setGlobalVariable", CatalystInstanceImpl::setGlobalVariable), makeNativeMethod("setGlobalVariable", CatalystInstanceImpl::setGlobalVariable),
@ -210,6 +215,19 @@ void CatalystInstanceImpl::jniLoadScriptFromFile(const std::string& fileName,
} }
} }
void CatalystInstanceImpl::jniLoadScriptFromDeltaBundle(
const std::string& sourceURL,
jni::alias_ref<NativeDeltaClient::jhybridobject> jDeltaClient,
bool loadSynchronously) {
auto deltaClient = jDeltaClient->cthis()->getDeltaClient();
auto registry = RAMBundleRegistry::singleBundleRegistry(
folly::make_unique<JSDeltaBundleClientRAMBundle>(deltaClient));
instance_->loadRAMBundle(
std::move(registry), deltaClient->getStartupCode(), sourceURL, loadSynchronously);
}
void CatalystInstanceImpl::jniCallJSFunction(std::string module, std::string method, NativeArray* arguments) { void CatalystInstanceImpl::jniCallJSFunction(std::string module, std::string method, NativeArray* arguments) {
// We want to share the C++ code, and on iOS, modules pass module/method // We want to share the C++ code, and on iOS, modules pass module/method
// names as strings all the way through to JS, and there's no way to do // names as strings all the way through to JS, and there's no way to do

View File

@ -10,6 +10,7 @@
#include "JMessageQueueThread.h" #include "JMessageQueueThread.h"
#include "JSLoader.h" #include "JSLoader.h"
#include "ModuleRegistryBuilder.h" #include "ModuleRegistryBuilder.h"
#include "NativeDeltaClient.h"
namespace facebook { namespace facebook {
namespace react { namespace react {
@ -66,6 +67,7 @@ class CatalystInstanceImpl : public jni::HybridClass<CatalystInstanceImpl> {
void jniLoadScriptFromAssets(jni::alias_ref<JAssetManager::javaobject> assetManager, const std::string& assetURL, bool loadSynchronously); void jniLoadScriptFromAssets(jni::alias_ref<JAssetManager::javaobject> assetManager, const std::string& assetURL, bool loadSynchronously);
void jniLoadScriptFromFile(const std::string& fileName, const std::string& sourceURL, bool loadSynchronously); void jniLoadScriptFromFile(const std::string& fileName, const std::string& sourceURL, bool loadSynchronously);
void jniLoadScriptFromDeltaBundle(const std::string& sourceURL, jni::alias_ref<NativeDeltaClient::jhybridobject> deltaClient, bool loadSynchronously);
void jniCallJSFunction(std::string module, std::string method, NativeArray* arguments); void jniCallJSFunction(std::string module, std::string method, NativeArray* arguments);
void jniCallJSCallback(jint callbackId, NativeArray* arguments); void jniCallJSCallback(jint callbackId, NativeArray* arguments);
void setGlobalVariable(std::string propName, void setGlobalVariable(std::string propName,