Skip to content

Commit

Permalink
Shortcut emitDeviceEvent in bridgeless (facebook#44574)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#44574

`emitDeviceEvent` is frequently used for perf-critical operations such as sending network responses from native to JS. We don't need to go through JavaScriptModule Proxy (which is missing caching in bridgeless) and instead can immediately invoke the callable JS module.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D57329165

fbshipit-source-id: 6506a7afb522b672a1f3dc7d348c9b80e6734225
  • Loading branch information
javache authored and facebook-github-bot committed May 15, 2024
1 parent 95f7a5c commit d0bb396
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ public <T extends JavaScriptModule> T getJSModule(Class<T> jsInterface) {
&& mInteropModuleRegistry.shouldReturnInteropModule(jsInterface)) {
return mInteropModuleRegistry.getInteropModule(jsInterface);
}

// TODO T189052462: ReactContext caches JavaScriptModule instances
JavaScriptModule interfaceProxy =
(JavaScriptModule)
Proxy.newProxyInstance(
Expand All @@ -143,6 +145,13 @@ public <T extends JavaScriptModule> T getJSModule(Class<T> jsInterface) {
return (T) interfaceProxy;
}

/** Shortcut RCTDeviceEventEmitter.emit since it's frequently used */
@Override
public void emitDeviceEvent(String eventName, @Nullable Object args) {
mReactHost.callFunctionOnModule(
"RCTDeviceEventEmitter", "emit", Arguments.fromJavaArgs(new Object[] {args}));
}

@Override
public <T extends NativeModule> boolean hasNativeModule(Class<T> nativeModuleInterface) {
return mReactHost.hasNativeModule(nativeModuleInterface);
Expand Down

0 comments on commit d0bb396

Please sign in to comment.