UNPKG

react-native-ui-lib

Version:

<p align="center"> <img src="https://user-images.githubusercontent.com/1780255/105469025-56759000-5ca0-11eb-993d-3568c1fd54f4.png" height="250px" style="display:block"/> </p> <p align="center">UI Toolset & Components Library for React Native</p> <p a

41 lines (33 loc) 956 B
import _ from 'lodash'; export default class EventEmitterManager { handlerCallbacks = {}; constructor() { this.handlerCallbacks = {}; } listenOn(eventName, handlerCallback) { if (!this.handlerCallbacks[eventName]) { this.handlerCallbacks[eventName] = []; } if (_.indexOf(this.handlerCallbacks[eventName], handlerCallback) === -1) { this.handlerCallbacks[eventName].push(handlerCallback); } } emitEvent(eventName, params = {}) { if (this.handlerCallbacks[eventName]) { this.handlerCallbacks[eventName].forEach(callback => callback(params)); } } removeListeners(eventName) { delete this.handlerCallbacks[eventName]; } removeListener(eventName, listener) { const handlers = this.handlerCallbacks[eventName]; if (handlers) { handlers.forEach((handler, index) => { if (handler === listener) { handlers.splice(index, 1); } }); } } }