mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-11 22:32:38 +08:00
[ReactNative] Strip prefixes from NativeModules keys
This commit is contained in:
24
Libraries/Utilities/nativeModulePrefixNormalizer.js
Normal file
24
Libraries/Utilities/nativeModulePrefixNormalizer.js
Normal 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;
|
||||
Reference in New Issue
Block a user