Simplify ModuleConfig array format
Reviewed By: lexs, mhorowitz Differential Revision: D3901563 fbshipit-source-id: 70aea19db1b01170be57b74ccfa1a306dfa1f362
This commit is contained in:
parent
acdd08aef7
commit
ff79224d37
|
@ -330,12 +330,7 @@ class MessageQueue {
|
|||
return null;
|
||||
}
|
||||
|
||||
let moduleName, constants, methods, promiseMethods, syncMethods;
|
||||
if (moduleHasConstants(config)) {
|
||||
[moduleName, constants, methods, promiseMethods, syncMethods] = config;
|
||||
} else {
|
||||
[moduleName, methods, promiseMethods, syncMethods] = (config:any);
|
||||
}
|
||||
const [moduleName, constants, methods, promiseMethods, syncMethods] = config;
|
||||
|
||||
const module = {};
|
||||
methods && methods.forEach((methodName, methodID) => {
|
||||
|
@ -347,7 +342,8 @@ class MessageQueue {
|
|||
});
|
||||
Object.assign(module, constants);
|
||||
|
||||
if (!constants && !methods && !promiseMethods) {
|
||||
if (!constants && !methods) {
|
||||
// Module contents will be filled in lazily later (see NativeModules)
|
||||
module.moduleID = moduleID;
|
||||
}
|
||||
|
||||
|
@ -395,22 +391,12 @@ class MessageQueue {
|
|||
return;
|
||||
}
|
||||
|
||||
let moduleName, methods;
|
||||
if (moduleHasConstants(config)) {
|
||||
[moduleName, , methods] = config;
|
||||
} else {
|
||||
[moduleName, methods] = (config:any);
|
||||
}
|
||||
|
||||
const [moduleName, , methods] = config;
|
||||
this._remoteModuleTable[moduleID] = moduleName;
|
||||
this._remoteMethodTable[moduleID] = methods;
|
||||
}
|
||||
}
|
||||
|
||||
function moduleHasConstants(moduleArray: ModuleConfig): boolean {
|
||||
return !Array.isArray(moduleArray[1]);
|
||||
}
|
||||
|
||||
function arrayContains<T>(array: Array<T>, value: T): boolean {
|
||||
return array.indexOf(value) !== -1;
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
*/
|
||||
'use strict';
|
||||
var remoteModulesConfig = [
|
||||
['RemoteModule1',['remoteMethod1','remoteMethod2'],[],[]],
|
||||
['RemoteModule2',['remoteMethod1','remoteMethod2'],[],[]],
|
||||
['RemoteModule1',null,['remoteMethod1','remoteMethod2'],[],[]],
|
||||
['RemoteModule2',null,['remoteMethod1','remoteMethod2'],[],[]],
|
||||
];
|
||||
|
||||
var MessageQueueTestConfig = {
|
||||
|
|
|
@ -329,12 +329,12 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init);
|
|||
}
|
||||
|
||||
NSArray *config = @[
|
||||
self.name,
|
||||
RCTNullIfNil(constants),
|
||||
RCTNullIfNil(methods),
|
||||
RCTNullIfNil(promiseMethods),
|
||||
RCTNullIfNil(syncMethods)
|
||||
];
|
||||
self.name,
|
||||
RCTNullIfNil(constants),
|
||||
RCTNullIfNil(methods),
|
||||
RCTNullIfNil(promiseMethods),
|
||||
RCTNullIfNil(syncMethods)
|
||||
];
|
||||
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, ([NSString stringWithFormat:@"[RCTModuleData config] %@", _moduleClass]));
|
||||
return config;
|
||||
}
|
||||
|
|
|
@ -53,10 +53,7 @@ folly::dynamic ModuleRegistry::getConfig(const std::string& name) {
|
|||
|
||||
{
|
||||
SystraceSection s("getConstants");
|
||||
folly::dynamic constants = module->getConstants();
|
||||
if (constants.isObject() && constants.size() > 0) {
|
||||
config.push_back(std::move(constants));
|
||||
}
|
||||
config.push_back(module->getConstants());
|
||||
}
|
||||
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue