Skip to content

Commit

Permalink
Back out "RN: Adopt Mapped Types in EventEmitter" (facebook#38599)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#38599

Currently, `metro-config` does not have `hermes-parser` enabled by default. This is because `hermes-parser` does not yet support parsing all of TypeScript's syntax nodes.

However, this also means we cannot yet utilize any Flow langauge features that require the use of `hermes-parser` (and are unsupported by Babel). Mapped types falls into this category, so we cannot use them.

This backs out a recent change that tried to adopt Flow mapped types in `EventEmitter`, for now. We can revisit after making the necessary changes to `metro-config`.

Changelog:
[Internal]

Reviewed By: pieterv

Differential Revision: D47729818

fbshipit-source-id: f562d1456490e89f84c40b8f638ffe5eaf94dbc2
  • Loading branch information
yungsters authored and facebook-github-bot committed Jul 24, 2023
1 parent 75f4588 commit 2538442
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions packages/react-native/Libraries/vendor/emitter/EventEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ interface Registration<TArgs> {
+remove: () => void;
}

type Registry<TEventToArgsMap: {...}> = {
[key in keyof TEventToArgsMap]?: Set<Registration<TEventToArgsMap[key]>>,
};
type Registry<TEventToArgsMap: {...}> = $ObjMap<
TEventToArgsMap,
<TArgs>(TArgs) => Set<Registration<TArgs>>,
>;

/**
* EventEmitter manages listeners and publishes events to them.
Expand All @@ -62,7 +63,7 @@ type Registry<TEventToArgsMap: {...}> = {
export default class EventEmitter<TEventToArgsMap: {...}>
implements IEventEmitter<TEventToArgsMap>
{
_registry: Registry<TEventToArgsMap> = emptyRegistry<TEventToArgsMap>();
_registry: Registry<TEventToArgsMap> = {};

/**
* Registers a listener that is called when the supplied event is emitted.
Expand Down Expand Up @@ -121,7 +122,7 @@ export default class EventEmitter<TEventToArgsMap: {...}>
eventType?: ?TEvent,
): void {
if (eventType == null) {
this._registry = emptyRegistry<TEventToArgsMap>();
this._registry = {};
} else {
delete this._registry[eventType];
}
Expand All @@ -136,13 +137,6 @@ export default class EventEmitter<TEventToArgsMap: {...}>
}
}

function emptyRegistry<TEventToArgsMap: {...}>(): Registry<TEventToArgsMap> {
// Flow cannot enforce that `TEventToArgsMap` is an object because, for
// example, Flow permits `empty. We have to ignore this error for now.
// $FlowIgnore[incompatible-return]
return {};
}

function allocate<
TEventToArgsMap: {...},
TEvent: $Keys<TEventToArgsMap>,
Expand Down

0 comments on commit 2538442

Please sign in to comment.