2019-01-05 03:14:38 +03:00
|
|
|
/**
|
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*
|
|
|
|
* @flow
|
|
|
|
* @format
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2019-05-08 18:44:25 +03:00
|
|
|
const NativeModules = require('../BatchedBridge/NativeModules');
|
2019-02-02 04:39:50 +03:00
|
|
|
|
2019-05-08 18:44:25 +03:00
|
|
|
import type {TurboModule} from './RCTExport';
|
2019-01-05 03:14:38 +03:00
|
|
|
import invariant from 'invariant';
|
|
|
|
|
2019-02-04 22:04:32 +03:00
|
|
|
const turboModuleProxy = global.__turboModuleProxy;
|
|
|
|
|
2019-01-05 03:14:38 +03:00
|
|
|
function get<T: TurboModule>(name: string): ?T {
|
|
|
|
// Backward compatibility layer during migration.
|
2019-02-01 03:54:37 +03:00
|
|
|
const legacyModule = NativeModules[name];
|
|
|
|
if (legacyModule != null) {
|
|
|
|
return ((legacyModule: any): T);
|
2019-01-05 03:14:38 +03:00
|
|
|
}
|
|
|
|
|
2019-02-04 22:04:32 +03:00
|
|
|
if (turboModuleProxy != null) {
|
|
|
|
const module: ?T = turboModuleProxy(name);
|
|
|
|
return module;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2019-01-05 03:14:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getEnforcing<T: TurboModule>(name: string): T {
|
|
|
|
const module = get(name);
|
|
|
|
invariant(module != null, `${name} is not available in this app.`);
|
|
|
|
return module;
|
|
|
|
}
|
|
|
|
|
|
|
|
export {get};
|
|
|
|
export {getEnforcing};
|