Improve constant extraction from RCTNativeModule

Reviewed By: dcaspi

Differential Revision: D4829671

fbshipit-source-id: 6b1cef1d31c7d8981c6f1e304d3742e885f8a83b
This commit is contained in:
Pieter De Baets
2017-04-08 15:14:38 -07:00
committed by Facebook Github Bot
parent f3dfd616f4
commit 2336ac299c
3 changed files with 15 additions and 19 deletions

View File

@@ -42,23 +42,9 @@ std::vector<MethodDescriptor> RCTNativeModule::getMethods() {
}
folly::dynamic RCTNativeModule::getConstants() {
// TODO mhorowitz #10487027: This does unnecessary work since it
// only needs constants. Think about refactoring RCTModuleData or
// NativeModule to make this more natural.
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways,
@"[RCTNativeModule getConstants] moduleData.config", nil);
NSArray *config = m_moduleData.config;
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"");
if (!config || config == (id)kCFNull) {
return nullptr;
}
id constants = config[1];
if (![constants isKindOfClass:[NSDictionary class]]) {
return nullptr;
}
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways,
@"[RCTNativeModule getConstants] convert", nil);
@"[RCTNativeModule getConstants] moduleData.exportedConstants", nil);
NSDictionary *constants = m_moduleData.exportedConstants;
folly::dynamic ret = [RCTConvert folly_dynamic:constants];
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"");
return ret;