diff --git a/Libraries/EventEmitter/NativeEventEmitter.js b/Libraries/EventEmitter/NativeEventEmitter.js index 23557f71a4b9d0..e04bc5f95d06c5 100644 --- a/Libraries/EventEmitter/NativeEventEmitter.js +++ b/Libraries/EventEmitter/NativeEventEmitter.js @@ -50,7 +50,7 @@ export default class NativeEventEmitter extends EventEmitter { removeAllListeners(eventType: string) { invariant(eventType, 'eventType argument is required.'); - const count = this.listeners(eventType).length; + const count = this.listenerCount(eventType); if (this._nativeModule != null) { this._nativeModule.removeListeners(count); } diff --git a/Libraries/vendor/emitter/_EventEmitter.js b/Libraries/vendor/emitter/_EventEmitter.js index 8ec88d27d02246..150c2538916698 100644 --- a/Libraries/vendor/emitter/_EventEmitter.js +++ b/Libraries/vendor/emitter/_EventEmitter.js @@ -93,23 +93,21 @@ class EventEmitter { } /** - * Returns an array of listeners that are currently registered for the given + * Returns the number of listeners that are currently registered for the given * event. * * @param {string} eventType - Name of the event to query - * @returns {array} + * @returns {number} */ - listeners(eventType: string): [EmitterSubscription] { + listenerCount(eventType: string): number { const subscriptions = this._subscriber.getSubscriptionsForType(eventType); return subscriptions - ? subscriptions - // We filter out missing entries because the array is sparse. - // "callbackfn is called only for elements of the array which actually - // exist; it is not called for missing elements of the array." - // https://www.ecma-international.org/ecma-262/9.0/index.html#sec-array.prototype.filter - .filter(sparseFilterPredicate) - .map(subscription => subscription.listener) - : []; + ? // We filter out missing entries because the array is sparse. + // "callbackfn is called only for elements of the array which actually + // exist; it is not called for missing elements of the array." + // https://www.ecma-international.org/ecma-262/9.0/index.html#sec-array.prototype.filter + subscriptions.filter(sparseFilterPredicate).length + : 0; } /**