diff --git a/Libraries/Utilities/MessageQueue.js b/Libraries/Utilities/MessageQueue.js index d34bda8b9..d37881d91 100644 --- a/Libraries/Utilities/MessageQueue.js +++ b/Libraries/Utilities/MessageQueue.js @@ -186,7 +186,7 @@ class MessageQueue { let moduleNames = Object.keys(localModules); for (var i = 0, l = moduleNames.length; i < l; i++) { let moduleName = moduleNames[i]; - let methods = localModules[moduleName].methods; + let methods = localModules[moduleName].methods || {}; let moduleID = localModules[moduleName].moduleID; moduleTable[moduleID] = moduleName; methodTable[moduleID] = {}; @@ -210,12 +210,16 @@ class MessageQueue { } _genModule(module, moduleConfig) { - let methodNames = Object.keys(moduleConfig.methods); + let methods = moduleConfig.methods || {}; + let methodNames = Object.keys(methods); for (var i = 0, l = methodNames.length; i < l; i++) { let methodName = methodNames[i]; - let methodConfig = moduleConfig.methods[methodName]; + let methodConfig = methods[methodName]; module[methodName] = this._genMethod( - moduleConfig.moduleID, methodConfig.methodID, methodConfig.type); + moduleConfig.moduleID, + methodConfig.methodID, + methodConfig.type || MethodTypes.remote + ); } Object.assign(module, moduleConfig.constants); return module; @@ -260,7 +264,7 @@ class MessageQueue { } -function createErrorFromErrorData(errorData: ErrorData): Error { +function createErrorFromErrorData(errorData: {message: string}): Error { var { message, ...extraErrorInfo, diff --git a/React/Base/RCTBatchedBridge.m b/React/Base/RCTBatchedBridge.m index aedb23008..3906a5bdc 100644 --- a/React/Base/RCTBatchedBridge.m +++ b/React/Base/RCTBatchedBridge.m @@ -310,7 +310,10 @@ RCT_EXTERN NSArray *RCTGetModuleClasses(void); { NSMutableDictionary *config = [NSMutableDictionary new]; for (RCTModuleData *moduleData in _moduleDataByID) { - config[moduleData.name] = moduleData.config; + NSDictionary *moduleConfig = moduleData.config; + if (moduleConfig) { + config[moduleData.name] = moduleConfig; + } if ([moduleData.instance conformsToProtocol:@protocol(RCTFrameUpdateObserver)]) { [_frameUpdateObservers addObject:moduleData]; diff --git a/React/Base/RCTModuleData.m b/React/Base/RCTModuleData.m index 23f46cb79..a95d79dd6 100644 --- a/React/Base/RCTModuleData.m +++ b/React/Base/RCTModuleData.m @@ -81,6 +81,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init); - (NSDictionary *)config { + if (_constants.count == 0 && self.methods.count == 0) { + return nil; // Nothing to export + } + NSMutableDictionary *config = [NSMutableDictionary new]; config[@"moduleID"] = _moduleID; @@ -90,12 +94,20 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init); NSMutableDictionary *methodconfig = [NSMutableDictionary new]; [self.methods enumerateObjectsUsingBlock:^(id method, NSUInteger idx, __unused BOOL *stop) { - methodconfig[method.JSMethodName] = @{ - @"methodID": @(idx), - @"type": method.functionType == RCTFunctionTypePromise ? @"remoteAsync" : @"remote", - }; + if (method.functionType == RCTFunctionTypePromise) { + methodconfig[method.JSMethodName] = @{ + @"methodID": @(idx), + @"type": @"remoteAsync", + }; + } else { + methodconfig[method.JSMethodName] = @{ + @"methodID": @(idx), + }; + } }]; - config[@"methods"] = [methodconfig copy]; + if (methodconfig.count) { + config[@"methods"] = [methodconfig copy]; + } return [config copy]; }