[ReactNative] Strip prefixes from NativeModules keys

This commit is contained in:
Spencer Ahrens
2015-03-17 22:22:03 -07:00
parent 2991f583e0
commit 9086365faf
46 changed files with 75 additions and 75 deletions

View File

@@ -0,0 +1,24 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule nativeModulePrefixNormalizer
*/
'use strict';
// Dirty hack to support old (RK) and new (RCT) native module name conventions
function nativeModulePrefixNormalizer(modules) {
Object.keys(modules).forEach((moduleName) => {
var strippedName = moduleName.replace(/^(RCT|RK)/, '');
if (modules['RCT' + strippedName] && modules['RK' + strippedName]) {
throw new Error(
'Module cannot be registered as both RCT and RK: ' + moduleName
);
}
if (strippedName !== moduleName) {
modules[strippedName] = modules[moduleName];
delete modules[moduleName];
}
});
}
module.exports = nativeModulePrefixNormalizer;