Replace $ObjMap in EventEmitter with mapped type (#46332)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/46332

Changelog: [Internal]

Reviewed By: gkz

Differential Revision: D62199703

fbshipit-source-id: 24abf39b01d5ba8a90e03ce837a887d4b4f4ade8
This commit is contained in:
Sam Zhou authored and Facebook GitHub Bot committed 2024-09-04 13:52:02 -07:00
1 parent e8646630a4
commit 464a202ba6
1 file changed
+5 -5
@@ -35,11 +35,9 @@ interface Registration<TArgs> {
+remove: () => void;
}
// $FlowFixMe[deprecated-type]
type Registry<TEventToArgsMap: {...}> = $ObjMap<
TEventToArgsMap,
<TArgs>(TArgs) => Set<Registration<TArgs>>,
>;
type Registry<TEventToArgsMap: {...}> = {
[K in keyof TEventToArgsMap]: Set<Registration<TEventToArgsMap[K]>>,
};
/**
* EventEmitter manages listeners and publishes events to them.
@@ -64,6 +62,7 @@ type Registry<TEventToArgsMap: {...}> = $ObjMap<
export default class EventEmitter<TEventToArgsMap: {...}>
implements IEventEmitter<TEventToArgsMap>
{
// $FlowFixMe[incompatible-type]
#registry: Registry<TEventToArgsMap> = {};
/**
@@ -126,6 +125,7 @@ export default class EventEmitter<TEventToArgsMap: {...}>
eventType?: ?TEvent,
): void {
if (eventType == null) {
// $FlowFixMe[incompatible-type]
this.#registry = {};
} else {
delete this.#registry[eventType];