Simplify ModuleConfig array format

Reviewed By: lexs, mhorowitz

Differential Revision: D3901563

fbshipit-source-id: 70aea19db1b01170be57b74ccfa1a306dfa1f362
This commit is contained in:
Pieter De Baets 2016-09-23 11:12:53 -07:00 committed by Facebook Github Bot 8
parent acdd08aef7
commit ff79224d37
4 changed files with 13 additions and 30 deletions

View File

@ -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;
}

View File

@ -10,8 +10,8 @@
*/
'use strict';
var remoteModulesConfig = [
['RemoteModule1',['remoteMethod1','remoteMethod2'],[],[]],
['RemoteModule2',['remoteMethod1','remoteMethod2'],[],[]],
['RemoteModule1',null,['remoteMethod1','remoteMethod2'],[],[]],
['RemoteModule2',null,['remoteMethod1','remoteMethod2'],[],[]],
];
var MessageQueueTestConfig = {

View File

@ -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;
}

View File

@ -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());
}
{