From 62934e555d6c11a99bad38d1102cc41ba7eb0a89 Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Mon, 12 Apr 2021 12:41:15 -0700 Subject: [PATCH] EventEmitter: Cleanup Redundant Internal Types Summary: Cleans up some minor redundant internal types in `_EventEmitter.js`. Changelog: [Internal] Reviewed By: rubennorte Differential Revision: D27712301 fbshipit-source-id: e6affcb7948e0f47a1775b74b12f59ec2a6abddb --- Libraries/vendor/emitter/_EventEmitter.js | 24 +++-------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/Libraries/vendor/emitter/_EventEmitter.js b/Libraries/vendor/emitter/_EventEmitter.js index 4cf99a6971b..998f5cec747 100644 --- a/Libraries/vendor/emitter/_EventEmitter.js +++ b/Libraries/vendor/emitter/_EventEmitter.js @@ -12,25 +12,11 @@ const invariant = require('invariant'); import EmitterSubscription from './_EmitterSubscription'; +import {type EventSubscription} from './EventSubscription'; import EventSubscriptionVendor from './_EventSubscriptionVendor'; const sparseFilterPredicate = () => true; -export interface IEventEmitter { - addListener>( - eventType: K, - listener: (...$ElementType) => mixed, - context: $FlowFixMe, - ): EmitterSubscription; - - removeAllListeners>(eventType: ?K): void; - - emit>( - eventType: K, - ...args: $ElementType - ): void; -} - /** * @class EventEmitter * @description @@ -44,8 +30,7 @@ export interface IEventEmitter { * mechanism on top of which extra functionality can be composed. For example, a * more advanced emitter may use an EventHolder and EventFactory. */ -class EventEmitter - implements IEventEmitter { +class EventEmitter { _subscriber: EventSubscriptionVendor = new EventSubscriptionVendor(); /** @@ -63,9 +48,6 @@ class EventEmitter * emitted. An optional calling context may be provided. The data arguments * emitted will be passed to the listener function. * - * TODO: Annotate the listener arg's type. This is tricky because listeners - * can be invoked with varargs. - * * @param {string} eventType - Name of the event to listen to * @param {function} listener - Function to invoke when the specified event is * emitted @@ -77,7 +59,7 @@ class EventEmitter // FIXME: listeners should return void instead of mixed to prevent issues listener: (...$ElementType) => mixed, context: $FlowFixMe, - ): EmitterSubscription { + ): EventSubscription { return (this._subscriber.addSubscription( eventType, new EmitterSubscription(this, this._subscriber, listener, context),