1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @format
8 */
9
10import EventEmitter, {
11  EmitterSubscription,
12} from '../vendor/emitter/EventEmitter';
13
14/**
15 * The React Native implementation of the IOS RCTEventEmitter which is required when creating
16 * a module that communicates with IOS
17 */
18type NativeModule = {
19  /**
20   * Add the provided eventType as an active listener
21   * @param eventType name of the event for which we are registering listener
22   */
23  addListener: (eventType: string) => void;
24
25  /**
26   * Remove a specified number of events.  There are no eventTypes in this case, as
27   * the native side doesn't remove the name, but only manages a counter of total
28   * listeners
29   * @param count number of listeners to remove (of any type)
30   */
31  removeListeners: (count: number) => void;
32};
33
34/**
35 * Abstract base class for implementing event-emitting modules. This implements
36 * a subset of the standard EventEmitter node module API.
37 */
38declare class NativeEventEmitter extends EventEmitter {
39  /**
40   * @param nativeModule the NativeModule implementation.  This is required on IOS and will throw
41   *      an invariant error if undefined.
42   */
43  constructor(nativeModule?: NativeModule);
44
45  /**
46   * Add the specified listener, this call passes through to the NativeModule
47   * addListener
48   *
49   * @param eventType name of the event for which we are registering listener
50   * @param listener the listener function
51   * @param context context of the listener
52   */
53  addListener(
54    eventType: string,
55    listener: (event: any) => void,
56    context?: Object,
57  ): EmitterSubscription;
58
59  /**
60   * @param eventType  name of the event whose registered listeners to remove
61   */
62  removeAllListeners(eventType: string): void;
63
64  /**
65   * Removes a subscription created by the addListener, the EventSubscription#remove()
66   * function actually calls through to this.
67   */
68  removeSubscription(subscription: EmitterSubscription): void;
69}
70