From 8f85abdb14b4e4abf521e23cf69e15d06a8c3480 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Thu, 3 May 2018 08:38:11 -0700 Subject: [PATCH] `JSBundleLoader`: allow to load with delta client Summary: Adds glue between `CatalystInstance` and `JSBundleLoader`: Adds the possibility to create a `JSBundleLoader` instance that calls into `CatalystInstanceImpl#loadScriptFromDeltaBundle(...)`. Reviewed By: fromcelticpark Differential Revision: D7845134 fbshipit-source-id: 9585b44a6e7c63245c9f634543642be55c928896 --- .../facebook/react/bridge/JSBundleLoader.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/JSBundleLoader.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/JSBundleLoader.java index 61bc6f018..c62b1675a 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/JSBundleLoader.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/JSBundleLoader.java @@ -8,6 +8,7 @@ package com.facebook.react.bridge; import android.content.Context; +import com.facebook.react.bridge.NativeDeltaClient; import com.facebook.react.common.DebugServerException; /** @@ -78,6 +79,28 @@ public abstract class JSBundleLoader { }; } + /** + * This loader is used to load delta bundles from the dev server. We pass each delta message to + * the loader and process it in C++. Passing it as a string leads to inefficiencies due to memory + * copies, which will have to be addressed in a follow-up. + * @param nativeDeltaClient + */ + public static JSBundleLoader createDeltaFromNetworkLoader( + final String sourceURL, + final NativeDeltaClient nativeDeltaClient) { + return new JSBundleLoader() { + @Override + public String loadScript(CatalystInstanceImpl instance) { + try { + instance.loadScriptFromDeltaBundle(sourceURL, nativeDeltaClient, false); + return sourceURL; + } catch (Exception e) { + throw DebugServerException.makeGeneric(e.getMessage(), e); + } + } + }; + } + /** * This loader is used when proxy debugging is enabled. In that case there is no point in fetching * the bundle from device as remote executor will have to do it anyway.