mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-26 05:15:49 +08:00
[ReactNative] s/RK/RCT in OSS
This commit is contained in:
25
Libraries/Utilities/nativeModulePrefixDuplicator.js
Normal file
25
Libraries/Utilities/nativeModulePrefixDuplicator.js
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Copyright 2004-present Facebook. All Rights Reserved.
|
||||
*
|
||||
* @providesModule nativeModulePrefixDuplicator
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
// Dirty hack to support old (RK) and new (RCT) native module name conventions
|
||||
function nativeModulePrefixDuplicator(modules) {
|
||||
Object.keys(modules).forEach((moduleName) => {
|
||||
var rkModuleName = moduleName.replace(/^RCT/, 'RK');
|
||||
var rctModuleName = moduleName.replace(/^RK/, 'RCT');
|
||||
if (rkModuleName !== rctModuleName) {
|
||||
if (modules[rkModuleName] && modules[rctModuleName]) {
|
||||
throw new Error(
|
||||
'Module cannot be registered as both RCT and RK: ' + moduleName
|
||||
);
|
||||
}
|
||||
modules[rkModuleName] = modules[moduleName];
|
||||
modules[rctModuleName] = modules[moduleName];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = nativeModulePrefixDuplicator;
|
||||
Reference in New Issue
Block a user