Only call __turboModuleProxy when it exists

Summary: `__turboModuleProxy` doesn't exist if you're not in the TurboModules QE. If such is the case, then we should just return null when `TurboModuleRegistry.get` is called.

Reviewed By: fkgozali

Differential Revision: D13937143

fbshipit-source-id: d3f11c52b7cbecaefba675d714f0d67236071389
This commit is contained in:
Ramanpreet Nara 2019-02-04 11:04:32 -08:00 committed by Facebook Github Bot
parent 0e1d4ecbb7
commit e1451caddd
1 changed files with 8 additions and 3 deletions

View File

@ -15,7 +15,8 @@ const NativeModules = require('NativeModules');
import type {TurboModule} from 'RCTExport';
import invariant from 'invariant';
// TODO
const turboModuleProxy = global.__turboModuleProxy;
function get<T: TurboModule>(name: string): ?T {
// Backward compatibility layer during migration.
const legacyModule = NativeModules[name];
@ -23,8 +24,12 @@ function get<T: TurboModule>(name: string): ?T {
return ((legacyModule: any): T);
}
const module: ?T = global.__turboModuleProxy(name);
return module;
if (turboModuleProxy != null) {
const module: ?T = turboModuleProxy(name);
return module;
}
return null;
}
function getEnforcing<T: TurboModule>(name: string): T {