mirror of
https://github.com/status-im/react-native.git
synced 2025-01-10 01:25:39 +00:00
9ed9bca0bf
Summary: Instead of sending a list of modules over to JS on startup (and actually blocking script execution) instead provide a proxy object that constructs each of these lazily. Reviewed By: lexs Differential Revision: D3936979 fbshipit-source-id: 71bde822f01eb17a29f56c5e60e95e98e207d74d
52 lines
1.4 KiB
C++
52 lines
1.4 KiB
C++
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
#include <folly/dynamic.h>
|
|
#include <folly/Optional.h>
|
|
|
|
#include "ExecutorToken.h"
|
|
#include "NativeModule.h"
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
class NativeModule;
|
|
|
|
struct ModuleConfig {
|
|
size_t index;
|
|
folly::dynamic config;
|
|
};
|
|
|
|
class ModuleRegistry {
|
|
public:
|
|
// not implemented:
|
|
// onBatchComplete: see https://our.intern.facebook.com/intern/tasks/?t=5279396
|
|
// getModule: only used by views
|
|
// getAllModules: only used for cleanup; use RAII instead
|
|
// notifyCatalystInstanceInitialized: this is really only used by view-related code
|
|
// notifyCatalystInstanceDestroy: use RAII instead
|
|
|
|
ModuleRegistry(std::vector<std::unique_ptr<NativeModule>> modules);
|
|
std::vector<std::string> moduleNames();
|
|
|
|
folly::Optional<ModuleConfig> getConfig(const std::string& name);
|
|
|
|
void callNativeMethod(ExecutorToken token, unsigned int moduleId, unsigned int methodId,
|
|
folly::dynamic&& params, int callId);
|
|
MethodCallResult callSerializableNativeHook(ExecutorToken token, unsigned int moduleId, unsigned int methodId, folly::dynamic&& args);
|
|
|
|
private:
|
|
// This is always populated
|
|
std::vector<std::unique_ptr<NativeModule>> modules_;
|
|
|
|
// This is only populated if moduleNames() is called. Values are indices into modules_.
|
|
std::unordered_map<std::string, size_t> modulesByName_;
|
|
};
|
|
|
|
}
|
|
}
|