mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Backwards-compatible implementation for registerCallableModule
Summary: We currently use `BatchedBridge.registerCallableModule` to call JS from platform code in a bunch of places (e.g. `RCTDeviceEventEmitter.emit()`), including some pretty essential ones - for example, Networking relies on `RCTDeviceEventEmitter` to emit events to JS for network requests and errors. In order to make the migration to bridgeless mode as easy as possible, it'd be best if we didn't have to update all the callsites in JS and platform code, at least for core JS modules like `RCTDeviceEventEmitter`. So we'd like to implement this callable module pattern for bridgeless mode as well. In this diff, I'm installing a global variable, `RN$registerCallableModule`, which will store the JS module name and factory function in C++. This can then be called from platform code (Java/Obj-C) to invoke a JS function on a module using the existing APIs (`context.getJSModule()` on Android, `enqueueJSCall()` or similar on iOS). Changelog: [Internal] Reviewed By: PeteTheHeat Differential Revision: D18798852 fbshipit-source-id: fbe9eaecaf6f5cab5173beec999d3a933b13375d
This commit is contained in:
committed by
Facebook Github Bot
parent
85529fe356
commit
37ff892e24
@@ -10,52 +10,37 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* We don't set up the batched bridge in bridgeless mode. Once we've migrated
|
||||
* everything over to bridgeless we can just delete this file.
|
||||
*/
|
||||
if (!global.RN$Bridgeless) {
|
||||
/**
|
||||
* Set up the BatchedBridge. This must be done after the other steps in
|
||||
* InitializeCore to ensure that the JS environment has been initialized.
|
||||
* You can use this module directly, or just require InitializeCore.
|
||||
*/
|
||||
let registerModule;
|
||||
if (global.RN$Bridgeless && global.RN$registerCallableModule) {
|
||||
registerModule = global.RN$registerCallableModule;
|
||||
} else {
|
||||
const BatchedBridge = require('../BatchedBridge/BatchedBridge');
|
||||
BatchedBridge.registerLazyCallableModule('Systrace', () =>
|
||||
require('../Performance/Systrace'),
|
||||
);
|
||||
BatchedBridge.registerLazyCallableModule('JSTimers', () =>
|
||||
require('./Timers/JSTimers'),
|
||||
);
|
||||
BatchedBridge.registerLazyCallableModule('HeapCapture', () =>
|
||||
require('../HeapCapture/HeapCapture'),
|
||||
);
|
||||
BatchedBridge.registerLazyCallableModule('SamplingProfiler', () =>
|
||||
require('../Performance/SamplingProfiler'),
|
||||
);
|
||||
BatchedBridge.registerLazyCallableModule('RCTLog', () =>
|
||||
require('../Utilities/RCTLog'),
|
||||
);
|
||||
BatchedBridge.registerLazyCallableModule('RCTDeviceEventEmitter', () =>
|
||||
require('../EventEmitter/RCTDeviceEventEmitter'),
|
||||
);
|
||||
BatchedBridge.registerLazyCallableModule('RCTNativeAppEventEmitter', () =>
|
||||
require('../EventEmitter/RCTNativeAppEventEmitter'),
|
||||
);
|
||||
BatchedBridge.registerLazyCallableModule('GlobalPerformanceLogger', () =>
|
||||
require('../Utilities/GlobalPerformanceLogger'),
|
||||
);
|
||||
BatchedBridge.registerLazyCallableModule('JSDevSupportModule', () =>
|
||||
require('../Utilities/JSDevSupportModule'),
|
||||
);
|
||||
registerModule = (moduleName, factory) =>
|
||||
BatchedBridge.registerLazyCallableModule(moduleName, factory);
|
||||
}
|
||||
|
||||
if (__DEV__ && !global.__RCTProfileIsProfiling) {
|
||||
BatchedBridge.registerLazyCallableModule('HMRClient', () =>
|
||||
require('../Utilities/HMRClient'),
|
||||
);
|
||||
} else {
|
||||
BatchedBridge.registerLazyCallableModule('HMRClient', () =>
|
||||
require('../Utilities/HMRClientProdShim'),
|
||||
);
|
||||
}
|
||||
registerModule('Systrace', () => require('../Performance/Systrace'));
|
||||
registerModule('JSTimers', () => require('./Timers/JSTimers'));
|
||||
registerModule('HeapCapture', () => require('../HeapCapture/HeapCapture'));
|
||||
registerModule('SamplingProfiler', () =>
|
||||
require('../Performance/SamplingProfiler'),
|
||||
);
|
||||
registerModule('RCTLog', () => require('../Utilities/RCTLog'));
|
||||
registerModule('RCTDeviceEventEmitter', () =>
|
||||
require('../EventEmitter/RCTDeviceEventEmitter'),
|
||||
);
|
||||
registerModule('RCTNativeAppEventEmitter', () =>
|
||||
require('../EventEmitter/RCTNativeAppEventEmitter'),
|
||||
);
|
||||
registerModule('GlobalPerformanceLogger', () =>
|
||||
require('../Utilities/GlobalPerformanceLogger'),
|
||||
);
|
||||
registerModule('JSDevSupportModule', () =>
|
||||
require('../Utilities/JSDevSupportModule'),
|
||||
);
|
||||
|
||||
if (__DEV__ && !global.__RCTProfileIsProfiling) {
|
||||
registerModule('HMRClient', () => require('../Utilities/HMRClient'));
|
||||
} else {
|
||||
registerModule('HMRClient', () => require('../Utilities/HMRClientProdShim'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user