mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-06-18 22:05:06 +08:00
Remove RAMBundleRegistry subclasses
Differential Revision: D6262247 fbshipit-source-id: 708f919e34f1706d9aca19a34ad8ea506e9f8d8b
This commit is contained in:
committed by
Facebook Github Bot
parent
b0193b098c
commit
6ecae73fe5
@@ -35,8 +35,8 @@
|
||||
#import <cxxreact/JSBundleType.h>
|
||||
#import <cxxreact/JSCExecutor.h>
|
||||
#import <cxxreact/JSIndexedRAMBundle.h>
|
||||
#include <cxxreact/JSIndexedRAMBundleRegistry.h>
|
||||
#import <cxxreact/Platform.h>
|
||||
#import <cxxreact/RAMBundleRegistry.h>
|
||||
#import <jschelpers/Value.h>
|
||||
|
||||
#import "NSDataBigString.h"
|
||||
@@ -1152,8 +1152,8 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
|
||||
? [[self.delegate jsSegmentsDirectory].path stringByAppendingString:@"/"]
|
||||
: nil;
|
||||
auto registry = jsSegmentsDirectory != nil
|
||||
? std::make_unique<JSIndexedRAMBundleRegistry>(std::move(ramBundle), jsSegmentsDirectory.UTF8String)
|
||||
: std::make_unique<RAMBundleRegistry>(std::move(ramBundle));
|
||||
? RAMBundleRegistry::multipleBundlesRegistry(std::move(ramBundle), JSIndexedRAMBundle::buildFactory(jsSegmentsDirectory.UTF8String))
|
||||
: RAMBundleRegistry::singleBundleRegistry(std::move(ramBundle));
|
||||
self->_reactInstance->loadRAMBundle(std::move(registry), std::move(scriptStr),
|
||||
sourceUrlStr.UTF8String, !async);
|
||||
}
|
||||
|
||||
@@ -1023,7 +1023,6 @@
|
||||
597633371F4E021D005BE8A4 /* RCTShadowView+Internal.m in Sources */ = {isa = PBXBuildFile; fileRef = 597633341F4E021D005BE8A4 /* RCTShadowView+Internal.m */; };
|
||||
597633381F4E021D005BE8A4 /* RCTShadowView+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 597633351F4E021D005BE8A4 /* RCTShadowView+Internal.h */; };
|
||||
597633391F4E021D005BE8A4 /* RCTShadowView+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 597633351F4E021D005BE8A4 /* RCTShadowView+Internal.h */; };
|
||||
598FD1911F816998006C54CB /* JSIndexedRAMBundleRegistry.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = C6D3801E1F71D91600621378 /* JSIndexedRAMBundleRegistry.h */; };
|
||||
598FD1921F816A2A006C54CB /* RAMBundleRegistry.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = C6D380181F71D75B00621378 /* RAMBundleRegistry.h */; };
|
||||
598FD1931F817284006C54CB /* PrivateDataBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9936F3351F5F2F480010BF04 /* PrivateDataBase.cpp */; };
|
||||
598FD1941F8172A9006C54CB /* PrivateDataBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 9936F3361F5F2F480010BF04 /* PrivateDataBase.h */; };
|
||||
@@ -1158,7 +1157,6 @@
|
||||
C654505E1F3BD9280090799B /* RCTManagedPointer.h in Headers */ = {isa = PBXBuildFile; fileRef = C654505D1F3BD9280090799B /* RCTManagedPointer.h */; };
|
||||
C654505F1F3BD9280090799B /* RCTManagedPointer.h in Headers */ = {isa = PBXBuildFile; fileRef = C654505D1F3BD9280090799B /* RCTManagedPointer.h */; };
|
||||
C669D8981F72E3DE006748EB /* RAMBundleRegistry.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = C6D380181F71D75B00621378 /* RAMBundleRegistry.h */; };
|
||||
C669D8B91F72E4B7006748EB /* JSIndexedRAMBundleRegistry.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = C6D3801E1F71D91600621378 /* JSIndexedRAMBundleRegistry.h */; };
|
||||
C6827DF61EF17CCC00D66BEF /* RCTJSEnvironment.h in Headers */ = {isa = PBXBuildFile; fileRef = C6827DF51EF17CCC00D66BEF /* RCTJSEnvironment.h */; };
|
||||
C6827DF71EF17CCC00D66BEF /* RCTJSEnvironment.h in Headers */ = {isa = PBXBuildFile; fileRef = C6827DF51EF17CCC00D66BEF /* RCTJSEnvironment.h */; };
|
||||
C6827DFB1EF1800E00D66BEF /* RCTJSEnvironment.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = C6827DF51EF17CCC00D66BEF /* RCTJSEnvironment.h */; };
|
||||
@@ -1167,10 +1165,6 @@
|
||||
C6D3801B1F71D76200621378 /* RAMBundleRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = C6D380181F71D75B00621378 /* RAMBundleRegistry.h */; };
|
||||
C6D3801C1F71D76700621378 /* RAMBundleRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6D380191F71D75B00621378 /* RAMBundleRegistry.cpp */; };
|
||||
C6D3801D1F71D76800621378 /* RAMBundleRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6D380191F71D75B00621378 /* RAMBundleRegistry.cpp */; };
|
||||
C6D380201F71D91D00621378 /* JSIndexedRAMBundleRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = C6D3801E1F71D91600621378 /* JSIndexedRAMBundleRegistry.h */; };
|
||||
C6D380211F71D91E00621378 /* JSIndexedRAMBundleRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = C6D3801E1F71D91600621378 /* JSIndexedRAMBundleRegistry.h */; };
|
||||
C6D380221F71D92300621378 /* JSIndexedRAMBundleRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6D3801F1F71D91600621378 /* JSIndexedRAMBundleRegistry.cpp */; };
|
||||
C6D380231F71D92400621378 /* JSIndexedRAMBundleRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6D3801F1F71D91600621378 /* JSIndexedRAMBundleRegistry.cpp */; };
|
||||
CF2731C01E7B8DE40044CA4F /* RCTDeviceInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = CF2731BE1E7B8DE40044CA4F /* RCTDeviceInfo.h */; };
|
||||
CF2731C11E7B8DE40044CA4F /* RCTDeviceInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = CF2731BF1E7B8DE40044CA4F /* RCTDeviceInfo.m */; };
|
||||
CF2731C21E7B8DEF0044CA4F /* RCTDeviceInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = CF2731BE1E7B8DE40044CA4F /* RCTDeviceInfo.h */; };
|
||||
@@ -1455,7 +1449,6 @@
|
||||
dstSubfolderSpec = 16;
|
||||
files = (
|
||||
598FD1921F816A2A006C54CB /* RAMBundleRegistry.h in Copy Headers */,
|
||||
598FD1911F816998006C54CB /* JSIndexedRAMBundleRegistry.h in Copy Headers */,
|
||||
3DA9823B1E5B1053004F2374 /* CxxModule.h in Copy Headers */,
|
||||
3DA9823C1E5B1053004F2374 /* CxxNativeModule.h in Copy Headers */,
|
||||
3DA9823D1E5B1053004F2374 /* JSExecutor.h in Copy Headers */,
|
||||
@@ -1674,7 +1667,6 @@
|
||||
dstPath = include/cxxreact;
|
||||
dstSubfolderSpec = 16;
|
||||
files = (
|
||||
C669D8B91F72E4B7006748EB /* JSIndexedRAMBundleRegistry.h in Copy Headers */,
|
||||
C669D8981F72E3DE006748EB /* RAMBundleRegistry.h in Copy Headers */,
|
||||
3DA981A01E5B0E34004F2374 /* CxxModule.h in Copy Headers */,
|
||||
3DA981A11E5B0E34004F2374 /* CxxNativeModule.h in Copy Headers */,
|
||||
@@ -2194,8 +2186,6 @@
|
||||
C6827DF51EF17CCC00D66BEF /* RCTJSEnvironment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTJSEnvironment.h; sourceTree = "<group>"; };
|
||||
C6D380181F71D75B00621378 /* RAMBundleRegistry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RAMBundleRegistry.h; sourceTree = "<group>"; };
|
||||
C6D380191F71D75B00621378 /* RAMBundleRegistry.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RAMBundleRegistry.cpp; sourceTree = "<group>"; };
|
||||
C6D3801E1F71D91600621378 /* JSIndexedRAMBundleRegistry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSIndexedRAMBundleRegistry.h; sourceTree = "<group>"; };
|
||||
C6D3801F1F71D91600621378 /* JSIndexedRAMBundleRegistry.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSIndexedRAMBundleRegistry.cpp; sourceTree = "<group>"; };
|
||||
CF2731BE1E7B8DE40044CA4F /* RCTDeviceInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTDeviceInfo.h; sourceTree = "<group>"; };
|
||||
CF2731BF1E7B8DE40044CA4F /* RCTDeviceInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTDeviceInfo.m; sourceTree = "<group>"; };
|
||||
E3BBC8EB1ADE6F47001BBD81 /* RCTTextDecorationLineType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTTextDecorationLineType.h; sourceTree = "<group>"; };
|
||||
@@ -2905,8 +2895,6 @@
|
||||
3D92B0AB1E03699D0018521A /* JSExecutor.h */,
|
||||
3D92B0C61E03699D0018521A /* JSIndexedRAMBundle.cpp */,
|
||||
3D92B0C71E03699D0018521A /* JSIndexedRAMBundle.h */,
|
||||
C6D3801F1F71D91600621378 /* JSIndexedRAMBundleRegistry.cpp */,
|
||||
C6D3801E1F71D91600621378 /* JSIndexedRAMBundleRegistry.h */,
|
||||
3D92B0C81E03699D0018521A /* JSModulesUnbundle.h */,
|
||||
3D92B0C91E03699D0018521A /* MessageQueueThread.h */,
|
||||
3D92B0CA1E03699D0018521A /* MethodCall.cpp */,
|
||||
@@ -3154,7 +3142,6 @@
|
||||
27595AC61E575C7800CCE2B1 /* JsArgumentHelpers.h in Headers */,
|
||||
27595AD71E575C7800CCE2B1 /* SampleCxxModule.h in Headers */,
|
||||
27595AD21E575C7800CCE2B1 /* MethodCall.h in Headers */,
|
||||
C6D380211F71D91E00621378 /* JSIndexedRAMBundleRegistry.h in Headers */,
|
||||
3D3030221DF8294C00D6DDAE /* JSBundleType.h in Headers */,
|
||||
27595ACA1E575C7800CCE2B1 /* JSCMemory.h in Headers */,
|
||||
3D74547D1E54758900E74ADD /* JSBigString.h in Headers */,
|
||||
@@ -3244,7 +3231,6 @@
|
||||
27595AAB1E575C7800CCE2B1 /* JsArgumentHelpers.h in Headers */,
|
||||
27595ABC1E575C7800CCE2B1 /* SampleCxxModule.h in Headers */,
|
||||
27595AB71E575C7800CCE2B1 /* MethodCall.h in Headers */,
|
||||
C6D380201F71D91D00621378 /* JSIndexedRAMBundleRegistry.h in Headers */,
|
||||
3D3CD9471DE5FC7800167DC4 /* oss-compat-util.h in Headers */,
|
||||
27595AAF1E575C7800CCE2B1 /* JSCMemory.h in Headers */,
|
||||
3D74547C1E54758900E74ADD /* JSBigString.h in Headers */,
|
||||
@@ -4133,7 +4119,6 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
C6D380221F71D92300621378 /* JSIndexedRAMBundleRegistry.cpp in Sources */,
|
||||
3DC159E51E83E1E9007B1282 /* JSBigString.cpp in Sources */,
|
||||
13F8877B1E29726200C3C7A1 /* JSIndexedRAMBundle.cpp in Sources */,
|
||||
13F8877D1E29726200C3C7A1 /* ModuleRegistry.cpp in Sources */,
|
||||
@@ -4159,7 +4144,6 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
C6D380231F71D92400621378 /* JSIndexedRAMBundleRegistry.cpp in Sources */,
|
||||
3DC159E61E83E1FA007B1282 /* JSBigString.cpp in Sources */,
|
||||
13F8878E1E29726300C3C7A1 /* JSIndexedRAMBundle.cpp in Sources */,
|
||||
13F887901E29726300C3C7A1 /* ModuleRegistry.cpp in Sources */,
|
||||
|
||||
@@ -14,7 +14,6 @@ LOCAL_SRC_FILES := \
|
||||
JSLoader.cpp \
|
||||
JSLogging.cpp \
|
||||
JniJSModulesUnbundle.cpp \
|
||||
JniRAMBundleRegistry.cpp \
|
||||
MethodInvoker.cpp \
|
||||
ModuleRegistryBuilder.cpp \
|
||||
NativeArray.cpp \
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
#include <cxxreact/JSBigString.h>
|
||||
#include <cxxreact/JSBundleType.h>
|
||||
#include <cxxreact/JSIndexedRAMBundle.h>
|
||||
#include <cxxreact/JSIndexedRAMBundleRegistry.h>
|
||||
#include <cxxreact/MethodCall.h>
|
||||
#include <cxxreact/RecoverableError.h>
|
||||
#include <cxxreact/ModuleRegistry.h>
|
||||
#include <cxxreact/RecoverableError.h>
|
||||
#include <cxxreact/RAMBundleRegistry.h>
|
||||
#include <fb/log.h>
|
||||
#include <folly/dynamic.h>
|
||||
#include <folly/Memory.h>
|
||||
@@ -22,9 +22,8 @@
|
||||
|
||||
#include "CxxModuleWrapper.h"
|
||||
#include "JavaScriptExecutorHolder.h"
|
||||
#include "JniJSModulesUnbundle.h"
|
||||
#include "JniRAMBundleRegistry.h"
|
||||
#include "JNativeRunnable.h"
|
||||
#include "JniJSModulesUnbundle.h"
|
||||
#include "NativeArray.h"
|
||||
|
||||
using namespace facebook::jni;
|
||||
@@ -193,9 +192,7 @@ void CatalystInstanceImpl::jniLoadScriptFromAssets(
|
||||
auto script = loadScriptFromAssets(manager, sourceURL);
|
||||
if (JniJSModulesUnbundle::isUnbundle(manager, sourceURL)) {
|
||||
auto bundle = JniJSModulesUnbundle::fromEntryFile(manager, sourceURL);
|
||||
auto registry = jsSegmentsDirectory_.empty()
|
||||
? folly::make_unique<RAMBundleRegistry>(std::move(bundle))
|
||||
: folly::make_unique<JniRAMBundleRegistry>(std::move(bundle), manager, sourceURL);
|
||||
auto registry = RAMBundleRegistry::singleBundleRegistry(std::move(bundle));
|
||||
instance_->loadRAMBundle(
|
||||
std::move(registry),
|
||||
std::move(script),
|
||||
@@ -211,7 +208,16 @@ void CatalystInstanceImpl::jniLoadScriptFromFile(const std::string& fileName,
|
||||
const std::string& sourceURL,
|
||||
bool loadSynchronously) {
|
||||
if (Instance::isIndexedRAMBundle(fileName.c_str())) {
|
||||
instance_->loadRAMBundleFromFile(fileName, sourceURL, loadSynchronously);
|
||||
auto bundle = folly::make_unique<JSIndexedRAMBundle>(fileName.c_str());
|
||||
auto script = bundle->getStartupCode();
|
||||
auto registry = jsSegmentsDirectory_.empty()
|
||||
? RAMBundleRegistry::singleBundleRegistry(std::move(bundle))
|
||||
: RAMBundleRegistry::multipleBundlesRegistry(std::move(bundle), JSIndexedRAMBundle::buildFactory(jsSegmentsDirectory_));
|
||||
instance_->loadRAMBundle(
|
||||
std::move(registry),
|
||||
std::move(script),
|
||||
sourceURL,
|
||||
loadSynchronously);
|
||||
} else {
|
||||
std::unique_ptr<const JSBigFileString> script;
|
||||
RecoverableError::runRethrowingAsRecoverable<std::system_error>(
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
#include "JniRAMBundleRegistry.h"
|
||||
|
||||
#include <folly/Conv.h>
|
||||
#include <folly/Memory.h>
|
||||
|
||||
#include "JniJSModulesUnbundle.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
JniRAMBundleRegistry::JniRAMBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle, AAssetManager *assetManager, const std::string& baseDirectoryPath) :
|
||||
RAMBundleRegistry(std::move(mainBundle)),
|
||||
m_assetManager(assetManager),
|
||||
m_baseDirectoryPath(baseDirectoryPath) {}
|
||||
|
||||
std::unique_ptr<JSModulesUnbundle> JniRAMBundleRegistry::bundleById(uint32_t index) const {
|
||||
std::string bundlePathById = m_baseDirectoryPath + folly::to<std::string>(index) + "/js-modules/";
|
||||
return folly::make_unique<JniJSModulesUnbundle>(m_assetManager, bundlePathById);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
#include <android/asset_manager.h>
|
||||
#include <cxxreact/RAMBundleRegistry.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class JniRAMBundleRegistry : public RAMBundleRegistry {
|
||||
public:
|
||||
JniRAMBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle, AAssetManager *assetManager, const std::string& baseDirectoryPath);
|
||||
|
||||
protected:
|
||||
virtual std::unique_ptr<JSModulesUnbundle> bundleById(uint32_t index) const override;
|
||||
private:
|
||||
AAssetManager *m_assetManager = nullptr;
|
||||
std::string m_baseDirectoryPath;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@ LOCAL_SRC_FILES := \
|
||||
JSCTracing.cpp \
|
||||
JSCUtils.cpp \
|
||||
JSIndexedRAMBundle.cpp \
|
||||
JSIndexedRAMBundleRegistry.cpp \
|
||||
MethodCall.cpp \
|
||||
ModuleRegistry.cpp \
|
||||
NativeToJsBridge.cpp \
|
||||
|
||||
@@ -80,7 +80,6 @@ CXXREACT_PUBLIC_HEADERS = [
|
||||
"JSCExecutor.h",
|
||||
"JSCNativeModules.h",
|
||||
"JSIndexedRAMBundle.h",
|
||||
"JSIndexedRAMBundleRegistry.h",
|
||||
"JSModulesUnbundle.h",
|
||||
"MessageQueueThread.h",
|
||||
"MethodCall.h",
|
||||
|
||||
@@ -111,7 +111,7 @@ void Instance::loadRAMBundleFromFile(const std::string& sourcePath,
|
||||
bool loadSynchronously) {
|
||||
auto bundle = folly::make_unique<JSIndexedRAMBundle>(sourcePath.c_str());
|
||||
auto startupScript = bundle->getStartupCode();
|
||||
auto registry = folly::make_unique<RAMBundleRegistry>(std::move(bundle));
|
||||
auto registry = RAMBundleRegistry::singleBundleRegistry(std::move(bundle));
|
||||
loadRAMBundle(
|
||||
std::move(registry),
|
||||
std::move(startupScript),
|
||||
|
||||
@@ -2,11 +2,20 @@
|
||||
|
||||
#include "JSIndexedRAMBundle.h"
|
||||
|
||||
#include <folly/Memory.h>
|
||||
|
||||
#include "oss-compat-util.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
std::function<std::unique_ptr<JSModulesUnbundle>(uint32_t)> JSIndexedRAMBundle::buildFactory(const std::string& baseDirectoryPath) {
|
||||
return [baseDirectoryPath](uint32_t index){
|
||||
std::string bundlePathById = baseDirectoryPath + toString(index) + ".jsbundle";
|
||||
return folly::make_unique<JSIndexedRAMBundle>(bundlePathById.c_str());
|
||||
};
|
||||
}
|
||||
|
||||
JSIndexedRAMBundle::JSIndexedRAMBundle(const char *sourcePath) :
|
||||
m_bundle (sourcePath, std::ios_base::in) {
|
||||
if (!m_bundle) {
|
||||
|
||||
@@ -17,6 +17,8 @@ namespace react {
|
||||
|
||||
class RN_EXPORT JSIndexedRAMBundle : public JSModulesUnbundle {
|
||||
public:
|
||||
static std::function<std::unique_ptr<JSModulesUnbundle>(uint32_t)> buildFactory(const std::string& baseDirectoryPath);
|
||||
|
||||
// Throws std::runtime_error on failure.
|
||||
JSIndexedRAMBundle(const char *sourceURL);
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
#include "JSIndexedRAMBundleRegistry.h"
|
||||
|
||||
#include <cxxreact/JSIndexedRAMBundle.h>
|
||||
#include <folly/Memory.h>
|
||||
|
||||
#include "oss-compat-util.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
JSIndexedRAMBundleRegistry::JSIndexedRAMBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle, const std::string& baseDirectoryPath):
|
||||
RAMBundleRegistry(std::move(mainBundle)), m_baseDirectoryPath(baseDirectoryPath) {}
|
||||
|
||||
std::unique_ptr<JSModulesUnbundle> JSIndexedRAMBundleRegistry::bundleById(uint32_t index) const {
|
||||
std::string bundlePathById = m_baseDirectoryPath + toString(index) + ".jsbundle";
|
||||
return folly::make_unique<JSIndexedRAMBundle>(bundlePathById.c_str());
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@@ -1,25 +0,0 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cxxreact/RAMBundleRegistry.h>
|
||||
|
||||
#ifndef RN_EXPORT
|
||||
#define RN_EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class RN_EXPORT JSIndexedRAMBundleRegistry: public RAMBundleRegistry {
|
||||
public:
|
||||
JSIndexedRAMBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle, const std::string& baseDirectoryPath);
|
||||
|
||||
protected:
|
||||
virtual std::unique_ptr<JSModulesUnbundle> bundleById(uint32_t index) const override;
|
||||
private:
|
||||
std::string m_baseDirectoryPath;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "RAMBundleRegistry.h"
|
||||
|
||||
#include <folly/Memory.h>
|
||||
|
||||
#include <libgen.h>
|
||||
|
||||
namespace facebook {
|
||||
@@ -9,13 +11,26 @@ namespace react {
|
||||
|
||||
constexpr uint32_t RAMBundleRegistry::MAIN_BUNDLE_ID;
|
||||
|
||||
RAMBundleRegistry::RAMBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle) {
|
||||
std::unique_ptr<RAMBundleRegistry> RAMBundleRegistry::singleBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle) {
|
||||
RAMBundleRegistry *registry = new RAMBundleRegistry(std::move(mainBundle));
|
||||
return std::unique_ptr<RAMBundleRegistry>(registry);
|
||||
}
|
||||
|
||||
std::unique_ptr<RAMBundleRegistry> RAMBundleRegistry::multipleBundlesRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle, std::function<std::unique_ptr<JSModulesUnbundle>(uint32_t)> factory) {
|
||||
RAMBundleRegistry *registry = new RAMBundleRegistry(std::move(mainBundle), std::move(factory));
|
||||
return std::unique_ptr<RAMBundleRegistry>(registry);
|
||||
}
|
||||
|
||||
RAMBundleRegistry::RAMBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle, std::function<std::unique_ptr<JSModulesUnbundle>(uint32_t)> factory): m_factory(factory) {
|
||||
m_bundles.emplace(MAIN_BUNDLE_ID, std::move(mainBundle));
|
||||
}
|
||||
|
||||
JSModulesUnbundle::Module RAMBundleRegistry::getModule(uint32_t bundleId, uint32_t moduleId) {
|
||||
if (m_bundles.find(bundleId) == m_bundles.end()) {
|
||||
m_bundles.emplace(bundleId, this->bundleById(bundleId));
|
||||
if (!m_factory) {
|
||||
throw std::runtime_error("You need to register factory function in order to support multiple RAM bundles.");
|
||||
}
|
||||
m_bundles.emplace(bundleId, m_factory(bundleId));
|
||||
}
|
||||
|
||||
return getBundle(bundleId)->getModule(moduleId);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
@@ -19,22 +20,23 @@ namespace react {
|
||||
|
||||
class RN_EXPORT RAMBundleRegistry : noncopyable {
|
||||
public:
|
||||
using unique_ram_bundle = std::unique_ptr<JSModulesUnbundle>;
|
||||
constexpr static uint32_t MAIN_BUNDLE_ID = 0;
|
||||
|
||||
explicit RAMBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle);
|
||||
static std::unique_ptr<RAMBundleRegistry> singleBundleRegistry(unique_ram_bundle mainBundle);
|
||||
static std::unique_ptr<RAMBundleRegistry> multipleBundlesRegistry(unique_ram_bundle mainBundle, std::function<unique_ram_bundle(uint32_t)> factory);
|
||||
|
||||
RAMBundleRegistry(RAMBundleRegistry&&) = default;
|
||||
RAMBundleRegistry& operator=(RAMBundleRegistry&&) = default;
|
||||
|
||||
JSModulesUnbundle::Module getModule(uint32_t bundleId, uint32_t moduleId);
|
||||
virtual ~RAMBundleRegistry() {};
|
||||
protected:
|
||||
virtual std::unique_ptr<JSModulesUnbundle> bundleById(uint32_t index) const {
|
||||
throw std::runtime_error("Please, override this method in a subclass to support multiple RAM bundles.");
|
||||
}
|
||||
private:
|
||||
explicit RAMBundleRegistry(unique_ram_bundle mainBundle, std::function<unique_ram_bundle(uint32_t)> factory = {});
|
||||
JSModulesUnbundle *getBundle(uint32_t bundleId) const;
|
||||
|
||||
std::unordered_map<uint32_t, std::unique_ptr<JSModulesUnbundle>> m_bundles;
|
||||
std::function<unique_ram_bundle(uint32_t)> m_factory;
|
||||
std::unordered_map<uint32_t, unique_ram_bundle> m_bundles;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
|
||||
Reference in New Issue
Block a user