Skip to content

Commit

Permalink
Implement TurboModuleRegistry
Browse files Browse the repository at this point in the history
  • Loading branch information
johnf committed Mar 27, 2023
1 parent bf24fb5 commit 98495ac
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/react-native-web/src/exports/TurboModuleRegistry/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright (c) Nicolas Gallagher.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/

const NativeModules = require('../NativeModules');

import invariant from 'invariant';

function requireModule(name) {
const legacyModule = NativeModules[name];
if (legacyModule != null) {
return legacyModule;
}

return null;
}

function get(name) {
return requireModule(name);
}

function getEnforcing(name) {
const module = requireModule(name);
invariant(
module != null,
`TurboModuleRegistry.getEnforcing(...): '${name}' could not be found. ` +
'Verify that a module by this name is registered in the native binary.',
);
return module;
}

var TurboModuleRegistry = {
get,
getEnforcing,
};

export default TurboModuleRegistry;
1 change: 1 addition & 0 deletions packages/react-native-web/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export { default as processColor } from './exports/processColor';
export { default as render } from './exports/render';
export { default as unmountComponentAtNode } from './exports/unmountComponentAtNode';
export { default as NativeModules } from './exports/NativeModules';
export { default as TurrboModuleRegistry } from './exports/TurboModuleRegistry';

// APIs
export { default as AccessibilityInfo } from './exports/AccessibilityInfo';
Expand Down

0 comments on commit 98495ac

Please # to comment.