Remove the native delta client from Android

Summary: This was an experiment to patch individual deltas in development instead of reloading the whole JS bundle. With improvements such as Fast Refresh that reduces the need for reloads and bundle splitting that reduces the number of modules and memory by 10x, we won't be needing this complex optimization that we never properly made work. This diff removes that code and I will be removing the JS side of things in Metro in a follow-up diff.

Reviewed By: fkgozali

Differential Revision: D16832709

fbshipit-source-id: 46596a3126d52d7d74f4b9ffc9a6ee9d82ec9522
This commit is contained in:
Christoph Nakazawa
2019-08-16 10:02:46 -07:00
committed by Facebook Github Bot
parent 6991e28653
commit bb625e5238
19 changed files with 197 additions and 795 deletions
@@ -1,135 +0,0 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
* directory of this source tree.
*/
package com.facebook.react.devsupport;
import static org.fest.assertions.api.Assertions.assertThat;
import com.facebook.react.common.StandardCharsets;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import okio.BufferedSource;
import okio.Okio;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class BundleDeltaClientTest {
private BundleDeltaClient mClient;
@Rule public TemporaryFolder mFolder = new TemporaryFolder();
@Before
public void setUp() {
mClient = BundleDeltaClient.create(BundleDeltaClient.ClientType.DEV_SUPPORT);
}
@Test
public void testAcceptsSimpleInitialBundle() throws IOException {
File file = mFolder.newFile();
mClient.processDelta(
bufferedSource(
"{"
+ "\"pre\": \"console.log('Hello World!');\","
+ "\"post\": \"console.log('That is all folks!');\","
+ "\"modules\": [[0, \"console.log('Best module.');\"]]"
+ "}"),
file);
assertThat(contentOf(file))
.isEqualTo(
"console.log('Hello World!');\n"
+ "console.log('Best module.');\n"
+ "console.log('That is all folks!');\n");
}
@Test
public void testPatchesInitialBundleWithDeltaBundle() throws IOException {
File file = mFolder.newFile();
mClient.processDelta(
bufferedSource(
"{"
+ "\"pre\": \"pre\","
+ "\"post\": \"post\","
+ "\"modules\": [[0, \"0\"], [1, \"1\"]]"
+ "}"),
file);
file = mFolder.newFile();
mClient.processDelta(
bufferedSource(
"{"
+ "\"added\": [[2, \"2\"]],"
+ "\"modified\": [[0, \"0.1\"]],"
+ "\"deleted\": [1]"
+ "}"),
file);
assertThat(contentOf(file)).isEqualTo("pre\n" + "0.1\n" + "2\n" + "post\n");
}
@Test
public void testSortsModulesByIdInInitialBundle() throws IOException {
File file = mFolder.newFile();
mClient.processDelta(
bufferedSource(
"{"
+ "\"pre\": \"console.log('Hello World!');\","
+ "\"post\": \"console.log('That is all folks!');\","
+ "\"modules\": [[3, \"3\"], [0, \"0\"], [2, \"2\"], [1, \"1\"]]"
+ "}"),
file);
assertThat(contentOf(file))
.isEqualTo(
"console.log('Hello World!');\n"
+ "0\n"
+ "1\n"
+ "2\n"
+ "3\n"
+ "console.log('That is all folks!');\n");
}
@Test
public void testSortsModulesByIdInPatchedBundle() throws IOException {
File file = mFolder.newFile();
mClient.processDelta(
bufferedSource(
"{"
+ "\"pre\": \"console.log('Hello World!');\","
+ "\"post\": \"console.log('That is all folks!');\","
+ "\"modules\": [[3, \"3\"], [0, \"0\"], [1, \"1\"]]"
+ "}"),
file);
file = mFolder.newFile();
mClient.processDelta(
bufferedSource(
"{"
+ "\"added\": [[2, \"2\"]],"
+ "\"modified\": [[0, \"0.1\"]],"
+ "\"deleted\": [1]"
+ "}"),
file);
assertThat(contentOf(file))
.isEqualTo(
"console.log('Hello World!');\n"
+ "0.1\n"
+ "2\n"
+ "3\n"
+ "console.log('That is all folks!');\n");
}
private static BufferedSource bufferedSource(String string) {
return Okio.buffer(
Okio.source(new ByteArrayInputStream(string.getBytes(StandardCharsets.UTF_8))));
}
private static String contentOf(File file) throws IOException {
return new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
}
}