mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-11 22:40:37 +08:00
Clean up EventEmitter
Summary: As suggested by yungsters in D13138187 Reviewed By: mjesun Differential Revision: D13192765 fbshipit-source-id: 8ab3dc74b3a9aaebf043bc3b5ed4f2590f480d10
This commit is contained in:
committed by
Facebook Github Bot
parent
cfef04e760
commit
1f8b46a2fc
18
Libraries/vendor/emitter/EventEmitter.js
vendored
18
Libraries/vendor/emitter/EventEmitter.js
vendored
@@ -16,8 +16,6 @@ const EventSubscriptionVendor = require('EventSubscriptionVendor');
|
||||
|
||||
const invariant = require('fbjs/lib/invariant');
|
||||
|
||||
const emptyFunctionThatReturnsTrue = () => true;
|
||||
|
||||
/**
|
||||
* @class EventEmitter
|
||||
* @description
|
||||
@@ -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)
|
||||
: [];
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user