Skip to content

Commit

Permalink
Simplify ModuleConfig array format
Browse files Browse the repository at this point in the history
Reviewed By: lexs, mhorowitz

Differential Revision: D3901563

fbshipit-source-id: 70aea19db1b01170be57b74ccfa1a306dfa1f362
  • Loading branch information
javache authored and Facebook Github Bot 8 committed Sep 23, 2016
1 parent acdd08a commit ff79224
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 30 deletions.
22 changes: 4 additions & 18 deletions Libraries/Utilities/MessageQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Utilities/__mocks__/MessageQueueTestConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
*/
'use strict';
var remoteModulesConfig = [
['RemoteModule1',['remoteMethod1','remoteMethod2'],[],[]],
['RemoteModule2',['remoteMethod1','remoteMethod2'],[],[]],
['RemoteModule1',null,['remoteMethod1','remoteMethod2'],[],[]],
['RemoteModule2',null,['remoteMethod1','remoteMethod2'],[],[]],
];

var MessageQueueTestConfig = {
Expand Down
12 changes: 6 additions & 6 deletions React/Base/RCTModuleData.mm
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,12 @@ - (NSArray *)config
}

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;
}
Expand Down
5 changes: 1 addition & 4 deletions ReactCommon/cxxreact/ModuleRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

{
Expand Down

0 comments on commit ff79224

Please sign in to comment.