mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Forward NativeModule schema to __turboModuleProxy
Summary: `babel-plugin-codegen` will run the NativeModules codegen on each NativeModule spec, and inline the generated schema into the spec's `TurboModuleRegistry.get(Enforcing)?` call. This diff will forward that schema to `__turboModuleProxy` function (i.e: the TurboModule C++ infra). **Note:** Both this and D2280384 can't be landed until D22743294 (https://github.com/facebook/react-native/commit/650c0f64f1262d26a31b61d2a7576c485f3efa13) hits production (1-2 weeks). Changelog: [Internal] Reviewed By: fkgozali Differential Revision: D22832730 fbshipit-source-id: aecaf9943f9b01be805ff6b90249a6cbc6abdd20
This commit is contained in:
committed by
Facebook GitHub Bot
parent
111aab590e
commit
3df6f5fb2c
@@ -16,7 +16,7 @@ import invariant from 'invariant';
|
||||
|
||||
const turboModuleProxy = global.__turboModuleProxy;
|
||||
|
||||
export function get<T: TurboModule>(name: string): ?T {
|
||||
function requireModule<T: TurboModule>(name: string, schema?: ?$FlowFixMe): ?T {
|
||||
// Bridgeless mode requires TurboModules
|
||||
if (!global.RN$Bridgeless) {
|
||||
// Backward compatibility layer during migration.
|
||||
@@ -27,15 +27,35 @@ export function get<T: TurboModule>(name: string): ?T {
|
||||
}
|
||||
|
||||
if (turboModuleProxy != null) {
|
||||
const module: ?T = turboModuleProxy(name);
|
||||
const module: ?T = turboModuleProxy(name, schema);
|
||||
return module;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function get<T: TurboModule>(name: string): ?T {
|
||||
/**
|
||||
* What is Schema?
|
||||
*
|
||||
* @react-native/babel-plugin-codegen will parse the NativeModule
|
||||
* spec, and pass in the generated schema as the second argument
|
||||
* to this function
|
||||
*/
|
||||
const schema = arguments.length === 2 ? arguments[1] : undefined;
|
||||
return requireModule<T>(name, schema);
|
||||
}
|
||||
|
||||
export function getEnforcing<T: TurboModule>(name: string): T {
|
||||
const module = get(name);
|
||||
/**
|
||||
* What is Schema?
|
||||
*
|
||||
* @react-native/babel-plugin-codegen will parse the NativeModule
|
||||
* spec, and pass in the generated schema as the second argument
|
||||
* to this function
|
||||
*/
|
||||
const schema = arguments.length === 2 ? arguments[1] : undefined;
|
||||
const module = requireModule<T>(name, schema);
|
||||
invariant(
|
||||
module != null,
|
||||
`TurboModuleRegistry.getEnforcing(...): '${name}' could not be found. ` +
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow strict-local
|
||||
* @flow strict
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
Reference in New Issue
Block a user