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; return null;
} }
let moduleName, constants, methods, promiseMethods, syncMethods; const [moduleName, constants, methods, promiseMethods, syncMethods] = config;
if (moduleHasConstants(config)) {
[moduleName, constants, methods, promiseMethods, syncMethods] = config;
} else {
[moduleName, methods, promiseMethods, syncMethods] = (config:any);
}
const module = {}; const module = {};
methods && methods.forEach((methodName, methodID) => { methods && methods.forEach((methodName, methodID) => {
@ -347,7 +342,8 @@ class MessageQueue {
}); });
Object.assign(module, constants); Object.assign(module, constants);
if (!constants && !methods && !promiseMethods) { if (!constants && !methods) {
// Module contents will be filled in lazily later (see NativeModules)
module.moduleID = moduleID; module.moduleID = moduleID;
} }
@ -395,22 +391,12 @@ class MessageQueue {
return; return;
} }
let moduleName, methods; const [moduleName, , methods] = config;
if (moduleHasConstants(config)) {
[moduleName, , methods] = config;
} else {
[moduleName, methods] = (config:any);
}
this._remoteModuleTable[moduleID] = moduleName; this._remoteModuleTable[moduleID] = moduleName;
this._remoteMethodTable[moduleID] = methods; this._remoteMethodTable[moduleID] = methods;
} }
} }
function moduleHasConstants(moduleArray: ModuleConfig): boolean {
return !Array.isArray(moduleArray[1]);
}
function arrayContains<T>(array: Array<T>, value: T): boolean { function arrayContains<T>(array: Array<T>, value: T): boolean {
return array.indexOf(value) !== -1; return array.indexOf(value) !== -1;
} }

View File

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

View File

@ -329,12 +329,12 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init);
} }
NSArray *config = @[ NSArray *config = @[
self.name, self.name,
RCTNullIfNil(constants), RCTNullIfNil(constants),
RCTNullIfNil(methods), RCTNullIfNil(methods),
RCTNullIfNil(promiseMethods), RCTNullIfNil(promiseMethods),
RCTNullIfNil(syncMethods) RCTNullIfNil(syncMethods)
]; ];
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, ([NSString stringWithFormat:@"[RCTModuleData config] %@", _moduleClass])); RCT_PROFILE_END_EVENT(RCTProfileTagAlways, ([NSString stringWithFormat:@"[RCTModuleData config] %@", _moduleClass]));
return config; return config;
} }

View File

@ -53,10 +53,7 @@ folly::dynamic ModuleRegistry::getConfig(const std::string& name) {
{ {
SystraceSection s("getConstants"); SystraceSection s("getConstants");
folly::dynamic constants = module->getConstants(); config.push_back(module->getConstants());
if (constants.isObject() && constants.size() > 0) {
config.push_back(std::move(constants));
}
} }
{ {