Skip to content

Commit

Permalink
Clean up EventEmitter
Browse files Browse the repository at this point in the history
Summary: As suggested by yungsters in D13138187

Reviewed By: mjesun

Differential Revision: D13192765

fbshipit-source-id: 8ab3dc74b3a9aaebf043bc3b5ed4f2590f480d10
  • Loading branch information
cpojer authored and facebook-github-bot committed Nov 26, 2018
1 parent cfef04e commit 1f8b46a
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions Libraries/vendor/emitter/EventEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ const EventSubscriptionVendor = require('EventSubscriptionVendor');

const invariant = require('fbjs/lib/invariant');

const emptyFunctionThatReturnsTrue = () => true;

/**
* @class EventEmitter
* @description
Expand Down Expand Up @@ -151,13 +149,9 @@ class EventEmitter {
* @returns {array}
*/
listeners(eventType: string): [EmitterSubscription] {
const subscriptions: ?[
EmitterSubscription,
] = (this._subscriber.getSubscriptionsForType(eventType): any);
const subscriptions = this._subscriber.getSubscriptionsForType(eventType);
return subscriptions
? subscriptions
.filter(emptyFunctionThatReturnsTrue)
.map(subscription => subscription.listener)
? subscriptions.map(subscription => subscription.listener)
: [];
}

Expand All @@ -176,9 +170,7 @@ class EventEmitter {
* emitter.emit('someEvent', 'abc'); // logs 'abc'
*/
emit(eventType: string) {
const subscriptions: ?[
EmitterSubscription,
] = (this._subscriber.getSubscriptionsForType(eventType): any);
const subscriptions = this._subscriber.getSubscriptionsForType(eventType);
if (subscriptions) {
for (let i = 0, l = subscriptions.length; i < l; i++) {
const subscription = subscriptions[i];
Expand Down Expand Up @@ -210,9 +202,7 @@ class EventEmitter {
*
*/
removeListener(eventType: String, listener) {
const subscriptions: ?[
EmitterSubscription,
] = (this._subscriber.getSubscriptionsForType(eventType): any);
const subscriptions = this._subscriber.getSubscriptionsForType(eventType);
if (subscriptions) {
for (let i = 0, l = subscriptions.length; i < l; i++) {
const subscription = subscriptions[i];
Expand Down

0 comments on commit 1f8b46a

Please sign in to comment.