/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @format * @flow strict * @typecheck */ import invariant from 'fbjs/lib/invariant'; import EmitterSubscription from './_EmitterSubscription'; import EventSubscriptionVendor from './_EventSubscriptionVendor'; declare var sparseFilterPredicate: () => any; 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 * An EventEmitter is responsible for managing a set of listeners and publishing * events to them when it is told that such events happened. In addition to the * data for the given event it also sends a event control object which allows * the listeners/handlers to prevent the default behavior of the given event. * * The emitter is designed to be generic enough to support all the different * contexts in which one might want to emit events. It is a simple multicast * mechanism on top of which extra functionality can be composed. For example, a * more advanced emitter may use an EventHolder and EventFactory. */ declare class EventEmitter implements IEventEmitter { _subscriber: EventSubscriptionVendor, constructor(subscriber: ?EventSubscriptionVendor): any, addListener>(eventType: K, listener: (...$ElementType) => mixed, context: $FlowFixMe): EmitterSubscription, removeAllListeners>(eventType: ?K): void, removeSubscription>(subscription: EmitterSubscription): void, listenerCount>(eventType: K): number, emit>(eventType: K, ...args: $ElementType): void, removeListener>(eventType: K, listener: (...$ElementType) => mixed): void, } export default EventEmitter;