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