mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-06 17:52:57 +08:00
Lazily instantiate native modules
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
This commit is contained in:
committed by
Facebook Github Bot
parent
606fc11487
commit
9ed9bca0bf
@@ -38,17 +38,17 @@ std::vector<std::string> ModuleRegistry::moduleNames() {
|
||||
return names;
|
||||
}
|
||||
|
||||
folly::dynamic ModuleRegistry::getConfig(const std::string& name) {
|
||||
folly::Optional<ModuleConfig> ModuleRegistry::getConfig(const std::string& name) {
|
||||
SystraceSection s("getConfig", "module", name);
|
||||
auto it = modulesByName_.find(name);
|
||||
if (it == modulesByName_.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
CHECK(it->second < modules_.size());
|
||||
|
||||
CHECK(it->second < modules_.size());
|
||||
NativeModule* module = modules_[it->second].get();
|
||||
|
||||
// string name, [object constants,] array methodNames (methodId is index), [array promiseMethodIds], [array syncMethodIds]
|
||||
// string name, object constants, array methodNames (methodId is index), [array promiseMethodIds], [array syncMethodIds]
|
||||
folly::dynamic config = folly::dynamic::array(name);
|
||||
|
||||
{
|
||||
@@ -89,7 +89,7 @@ folly::dynamic ModuleRegistry::getConfig(const std::string& name) {
|
||||
// no constants or methods
|
||||
return nullptr;
|
||||
} else {
|
||||
return config;
|
||||
return ModuleConfig({it->second, config});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user