mirror of
https://github.com/status-im/react-native.git
synced 2025-02-24 15:18:10 +00:00
cxxreact/RAMBundleRegistry: nit fixes
Reviewed By: mhorowitz Differential Revision: D7587411 fbshipit-source-id: 516753247af585914381308248de9652f18a6cf5
This commit is contained in:
parent
c9094e952b
commit
281ed9f4ce
@ -12,33 +12,46 @@ namespace react {
|
||||
|
||||
constexpr uint32_t RAMBundleRegistry::MAIN_BUNDLE_ID;
|
||||
|
||||
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::singleBundleRegistry(
|
||||
std::unique_ptr<JSModulesUnbundle> mainBundle) {
|
||||
return folly::make_unique<RAMBundleRegistry>(std::move(mainBundle));
|
||||
}
|
||||
|
||||
std::unique_ptr<RAMBundleRegistry> RAMBundleRegistry::multipleBundlesRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle, std::function<std::unique_ptr<JSModulesUnbundle>(std::string)> factory) {
|
||||
RAMBundleRegistry *registry = new RAMBundleRegistry(std::move(mainBundle), std::move(factory));
|
||||
return std::unique_ptr<RAMBundleRegistry>(registry);
|
||||
std::unique_ptr<RAMBundleRegistry> RAMBundleRegistry::multipleBundlesRegistry(
|
||||
std::unique_ptr<JSModulesUnbundle> mainBundle,
|
||||
std::function<std::unique_ptr<JSModulesUnbundle>(std::string)> factory) {
|
||||
return folly::make_unique<RAMBundleRegistry>(
|
||||
std::move(mainBundle), std::move(factory));
|
||||
}
|
||||
|
||||
RAMBundleRegistry::RAMBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle, std::function<std::unique_ptr<JSModulesUnbundle>(std::string)> factory): m_factory(factory) {
|
||||
RAMBundleRegistry::RAMBundleRegistry(
|
||||
std::unique_ptr<JSModulesUnbundle> mainBundle,
|
||||
std::function<std::unique_ptr<JSModulesUnbundle>(std::string)> factory):
|
||||
m_factory(std::move(factory)) {
|
||||
m_bundles.emplace(MAIN_BUNDLE_ID, std::move(mainBundle));
|
||||
}
|
||||
|
||||
void RAMBundleRegistry::registerBundle(uint32_t bundleId, std::string bundlePath) {
|
||||
m_bundlePaths.emplace(bundleId, bundlePath);
|
||||
void RAMBundleRegistry::registerBundle(
|
||||
uint32_t bundleId, std::string bundlePath) {
|
||||
m_bundlePaths.emplace(bundleId, std::move(bundlePath));
|
||||
}
|
||||
|
||||
JSModulesUnbundle::Module RAMBundleRegistry::getModule(uint32_t bundleId, uint32_t moduleId) {
|
||||
JSModulesUnbundle::Module RAMBundleRegistry::getModule(
|
||||
uint32_t bundleId, uint32_t moduleId) {
|
||||
if (m_bundles.find(bundleId) == m_bundles.end()) {
|
||||
if (!m_factory) {
|
||||
throw std::runtime_error("You need to register factory function in order to support multiple RAM bundles.");
|
||||
throw std::runtime_error(
|
||||
"You need to register factory function in order to "
|
||||
"support multiple RAM bundles."
|
||||
);
|
||||
}
|
||||
|
||||
auto bundlePath = m_bundlePaths.find(bundleId);
|
||||
if (bundlePath == m_bundlePaths.end()) {
|
||||
throw std::runtime_error("In order to fetch RAM bundle from the registry, its file path needs to be registered first.");
|
||||
throw std::runtime_error(
|
||||
"In order to fetch RAM bundle from the registry, its file "
|
||||
"path needs to be registered first."
|
||||
);
|
||||
}
|
||||
m_bundles.emplace(bundleId, m_factory(bundlePath->second));
|
||||
}
|
||||
@ -53,7 +66,7 @@ JSModulesUnbundle::Module RAMBundleRegistry::getModule(uint32_t bundleId, uint32
|
||||
};
|
||||
}
|
||||
|
||||
JSModulesUnbundle *RAMBundleRegistry::getBundle(uint32_t bundleId) const {
|
||||
JSModulesUnbundle* RAMBundleRegistry::getBundle(uint32_t bundleId) const {
|
||||
return m_bundles.at(bundleId).get();
|
||||
}
|
||||
|
||||
|
@ -20,26 +20,31 @@ namespace react {
|
||||
|
||||
class RN_EXPORT RAMBundleRegistry : noncopyable {
|
||||
public:
|
||||
using unique_ram_bundle = std::unique_ptr<JSModulesUnbundle>;
|
||||
using bundle_path = std::string;
|
||||
constexpr static uint32_t MAIN_BUNDLE_ID = 0;
|
||||
|
||||
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(bundle_path)> factory);
|
||||
static std::unique_ptr<RAMBundleRegistry> singleBundleRegistry(
|
||||
std::unique_ptr<JSModulesUnbundle> mainBundle);
|
||||
static std::unique_ptr<RAMBundleRegistry> multipleBundlesRegistry(
|
||||
std::unique_ptr<JSModulesUnbundle> mainBundle,
|
||||
std::function<std::unique_ptr<JSModulesUnbundle>(std::string)> factory);
|
||||
|
||||
explicit RAMBundleRegistry(
|
||||
std::unique_ptr<JSModulesUnbundle> mainBundle,
|
||||
std::function<
|
||||
std::unique_ptr<JSModulesUnbundle>(std::string)> factory = nullptr);
|
||||
|
||||
RAMBundleRegistry(RAMBundleRegistry&&) = default;
|
||||
RAMBundleRegistry& operator=(RAMBundleRegistry&&) = default;
|
||||
|
||||
void registerBundle(uint32_t bundleId, bundle_path bundlePath);
|
||||
void registerBundle(uint32_t bundleId, std::string bundlePath);
|
||||
JSModulesUnbundle::Module getModule(uint32_t bundleId, uint32_t moduleId);
|
||||
virtual ~RAMBundleRegistry() {};
|
||||
private:
|
||||
explicit RAMBundleRegistry(unique_ram_bundle mainBundle, std::function<unique_ram_bundle(bundle_path)> factory = {});
|
||||
JSModulesUnbundle *getBundle(uint32_t bundleId) const;
|
||||
JSModulesUnbundle* getBundle(uint32_t bundleId) const;
|
||||
|
||||
std::function<unique_ram_bundle(bundle_path)> m_factory;
|
||||
std::unordered_map<uint32_t, bundle_path> m_bundlePaths;
|
||||
std::unordered_map<uint32_t, unique_ram_bundle> m_bundles;
|
||||
std::function<std::unique_ptr<JSModulesUnbundle>(std::string)> m_factory;
|
||||
std::unordered_map<uint32_t, std::string> m_bundlePaths;
|
||||
std::unordered_map<uint32_t, std::unique_ptr<JSModulesUnbundle>> m_bundles;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
|
Loading…
x
Reference in New Issue
Block a user