mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-02 09:21:44 +08:00
Allow lazy Cxx modules to not initialize
Reviewed By: mhorowitz Differential Revision: D4851596 fbshipit-source-id: cf5f5c51b9aaa0da96f7ab6fba1277b72c988400
This commit is contained in:
committed by
Facebook Github Bot
parent
e67b8fe761
commit
f3dfd616f4
@@ -64,6 +64,10 @@ std::vector<MethodDescriptor> CxxNativeModule::getMethods() {
|
||||
folly::dynamic CxxNativeModule::getConstants() {
|
||||
lazyInit();
|
||||
|
||||
if (!module_) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
folly::dynamic constants = folly::dynamic::object();
|
||||
for (auto& pair : module_->getConstants()) {
|
||||
constants.insert(std::move(pair.first), std::move(pair.second));
|
||||
@@ -161,13 +165,17 @@ MethodCallResult CxxNativeModule::callSerializableNativeHook(
|
||||
}
|
||||
|
||||
void CxxNativeModule::lazyInit() {
|
||||
if (module_) {
|
||||
if (module_ || !provider_) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO 17216751: providers should never return null modules
|
||||
module_ = provider_();
|
||||
methods_ = module_->getMethods();
|
||||
module_->setInstance(instance_);
|
||||
provider_ = nullptr;
|
||||
if (module_) {
|
||||
methods_ = module_->getMethods();
|
||||
module_->setInstance(instance_);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user