Skip to content

Commit

Permalink
Add systrace for event type when calling RCTDeviceEventEmitter (#39085)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #39085

Adding arguments in systrace for event emitter event types. This is helpful to understand why sometimes JS render is triggered from native side.

Changelog:
[Internal] - Add event type information from native to js event emitter calls

Reviewed By: rshest

Differential Revision: D48448904

fbshipit-source-id: cbb4b86e781384d56205fec23931cd773e4a58a8
  • Loading branch information
Xin Chen authored and facebook-github-bot committed Aug 21, 2023
1 parent 606a92f commit 80685d5
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import type {IEventEmitter} from '../vendor/emitter/EventEmitter';

import {beginEvent, endEvent} from '../Performance/Systrace';
import EventEmitter from '../vendor/emitter/EventEmitter';

// FIXME: use typed events
Expand All @@ -21,12 +22,22 @@ type RCTDeviceEventDefinitions = $FlowFixMe;
*
* NativeModules that emit events should instead subclass `NativeEventEmitter`.
*/
const RCTDeviceEventEmitter: IEventEmitter<RCTDeviceEventDefinitions> =
new EventEmitter();
class RCTDeviceEventEmitter extends EventEmitter<RCTDeviceEventDefinitions> {
// Add systrace to RCTDeviceEventEmitter.emit method for debugging
emit<TEvent: $Keys<RCTDeviceEventDefinitions>>(
eventType: TEvent,
...args: RCTDeviceEventDefinitions[TEvent]
): void {
beginEvent(() => `RCTDeviceEventEmitter.emit#${eventType}`);
super.emit(eventType, ...args);
endEvent();
}
}
const instance = new RCTDeviceEventEmitter();

Object.defineProperty(global, '__rctDeviceEventEmitter', {
configurable: true,
value: RCTDeviceEventEmitter,
value: instance,
});

export default (RCTDeviceEventEmitter: IEventEmitter<RCTDeviceEventDefinitions>);
export default (instance: IEventEmitter<RCTDeviceEventDefinitions>);

0 comments on commit 80685d5

Please sign in to comment.