{"ast":null,"code":"import _defineProperty from \"@babel/runtime/helpers/defineProperty\";\nimport _classCallCheck from \"@babel/runtime/helpers/classCallCheck\";\nimport _createClass from \"@babel/runtime/helpers/createClass\";\nimport invariant from 'invariant';\nimport NativeEventEmitter from \"react-native-web/dist/exports/NativeEventEmitter\";\nimport Platform from \"react-native-web/dist/exports/Platform\";\nvar nativeEmitterSubscriptionKey = '@@nativeEmitterSubscription@@';\nexport var EventEmitter = function () {\n  function EventEmitter(nativeModule) {\n    _classCallCheck(this, EventEmitter);\n\n    this._listenerCount = 0;\n    this._nativeModule = nativeModule;\n    this._eventEmitter = new NativeEventEmitter(nativeModule);\n  }\n\n  _createClass(EventEmitter, [{\n    key: \"addListener\",\n    value: function addListener(eventName, listener) {\n      var _this = this,\n          _subscription;\n\n      if (!this._listenerCount && Platform.OS !== 'ios' && this._nativeModule.startObserving) {\n        this._nativeModule.startObserving();\n      }\n\n      this._listenerCount++;\n\n      var nativeEmitterSubscription = this._eventEmitter.addListener(eventName, listener);\n\n      var subscription = (_subscription = {}, _defineProperty(_subscription, nativeEmitterSubscriptionKey, nativeEmitterSubscription), _defineProperty(_subscription, \"remove\", function remove() {\n        _this.removeSubscription(subscription);\n      }), _subscription);\n      return subscription;\n    }\n  }, {\n    key: \"removeAllListeners\",\n    value: function removeAllListeners(eventName) {\n      var removedListenerCount = this._eventEmitter.listeners(eventName).length;\n\n      this._eventEmitter.removeAllListeners(eventName);\n\n      this._listenerCount -= removedListenerCount;\n      invariant(this._listenerCount >= 0, \"EventEmitter must have a non-negative number of listeners\");\n\n      if (!this._listenerCount && Platform.OS !== 'ios' && this._nativeModule.stopObserving) {\n        this._nativeModule.stopObserving();\n      }\n    }\n  }, {\n    key: \"removeSubscription\",\n    value: function removeSubscription(subscription) {\n      var nativeEmitterSubscription = subscription[nativeEmitterSubscriptionKey];\n\n      if (!nativeEmitterSubscription) {\n        return;\n      }\n\n      this._eventEmitter.removeSubscription(nativeEmitterSubscription);\n\n      this._listenerCount--;\n      delete subscription[nativeEmitterSubscriptionKey];\n\n      subscription.remove = function () {};\n\n      if (!this._listenerCount && Platform.OS !== 'ios' && this._nativeModule.stopObserving) {\n        this._nativeModule.stopObserving();\n      }\n    }\n  }, {\n    key: \"emit\",\n    value: function emit(eventName) {\n      var _this$_eventEmitter;\n\n      for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {\n        params[_key - 1] = arguments[_key];\n      }\n\n      (_this$_eventEmitter = this._eventEmitter).emit.apply(_this$_eventEmitter, [eventName].concat(params));\n    }\n  }]);\n\n  return EventEmitter;\n}();","map":{"version":3,"sources":["../src/EventEmitter.ts"],"names":[],"mappings":";;;AAAA,OAAO,SAAP,MAAsB,WAAtB;;;AAGA,IAAM,4BAA4B,GAAG,+BAArC;AAaA,WAAa,YAAb;AAKE,wBAAY,YAAZ,EAAsC;AAAA;;AAJtC,SAAA,cAAA,GAAiB,CAAjB;AAKE,SAAK,aAAL,GAAqB,YAArB;AACA,SAAK,aAAL,GAAqB,IAAI,kBAAJ,CAAuB,YAAvB,CAArB;AACD;;AARH;AAAA;AAAA,WAUE,qBAAe,SAAf,EAAkC,QAAlC,EAA8D;AAAA;AAAA;;AAC5D,UAAI,CAAC,KAAK,cAAN,IAAwB,QAAQ,CAAC,EAAT,KAAgB,KAAxC,IAAiD,KAAK,aAAL,CAAmB,cAAxE,EAAwF;AACtF,aAAK,aAAL,CAAmB,cAAnB;AACD;;AAED,WAAK,cAAL;;AACA,UAAM,yBAAyB,GAAG,KAAK,aAAL,CAAmB,WAAnB,CAA+B,SAA/B,EAA0C,QAA1C,CAAlC;;AACA,UAAM,YAAY,uDACf,4BADe,EACgB,yBADhB,4CAER,kBAAK;AACX,QAAA,KAAI,CAAC,kBAAL,CAAwB,YAAxB;AACD,OAJe,iBAAlB;AAMA,aAAO,YAAP;AACD;AAxBH;AAAA;AAAA,WA0BE,4BAAmB,SAAnB,EAAoC;AAClC,UAAM,oBAAoB,GAAG,KAAK,aAAL,CAAmB,SAAnB,CAA6B,SAA7B,EAAwC,MAArE;;AACA,WAAK,aAAL,CAAmB,kBAAnB,CAAsC,SAAtC;;AACA,WAAK,cAAL,IAAuB,oBAAvB;AACA,MAAA,SAAS,CACP,KAAK,cAAL,IAAuB,CADhB,8DAAT;;AAKA,UAAI,CAAC,KAAK,cAAN,IAAwB,QAAQ,CAAC,EAAT,KAAgB,KAAxC,IAAiD,KAAK,aAAL,CAAmB,aAAxE,EAAuF;AACrF,aAAK,aAAL,CAAmB,aAAnB;AACD;AACF;AAtCH;AAAA;AAAA,WAwCE,4BAAmB,YAAnB,EAA6C;AAC3C,UAAM,yBAAyB,GAAG,YAAY,CAAC,4BAAD,CAA9C;;AACA,UAAI,CAAC,yBAAL,EAAgC;AAC9B;AACD;;AAED,WAAK,aAAL,CAAmB,kBAAnB,CAAsC,yBAAtC;;AACA,WAAK,cAAL;AAIA,aAAO,YAAY,CAAC,4BAAD,CAAnB;;AAGA,MAAA,YAAY,CAAC,MAAb,GAAsB,YAAK,CAAG,CAA9B;;AAEA,UAAI,CAAC,KAAK,cAAN,IAAwB,QAAQ,CAAC,EAAT,KAAgB,KAAxC,IAAiD,KAAK,aAAL,CAAmB,aAAxE,EAAuF;AACrF,aAAK,aAAL,CAAmB,aAAnB;AACD;AACF;AA3DH;AAAA;AAAA,WA6DE,cAAK,SAAL,EAAwC;AAAA;;AAAA,wCAAb,MAAa;AAAb,QAAA,MAAa;AAAA;;AACtC,kCAAK,aAAL,EAAmB,IAAnB,6BAAwB,SAAxB,SAAsC,MAAtC;AACD;AA/DH;;AAAA;AAAA","sourcesContent":["import invariant from 'invariant';\nimport { NativeEventEmitter, Platform } from 'react-native';\n\nconst nativeEmitterSubscriptionKey = '@@nativeEmitterSubscription@@';\n\ntype NativeModule = {\n  startObserving?: () => void;\n  stopObserving?: () => void;\n  addListener: (eventName: string) => void;\n  removeListeners: (count: number) => void;\n};\n\nexport type Subscription = {\n  remove: () => void;\n};\n\nexport class EventEmitter {\n  _listenerCount = 0;\n  _nativeModule: NativeModule;\n  _eventEmitter: NativeEventEmitter;\n\n  constructor(nativeModule: NativeModule) {\n    this._nativeModule = nativeModule;\n    this._eventEmitter = new NativeEventEmitter(nativeModule as any);\n  }\n\n  addListener<T>(eventName: string, listener: (event: T) => void): Subscription {\n    if (!this._listenerCount && Platform.OS !== 'ios' && this._nativeModule.startObserving) {\n      this._nativeModule.startObserving();\n    }\n\n    this._listenerCount++;\n    const nativeEmitterSubscription = this._eventEmitter.addListener(eventName, listener);\n    const subscription = {\n      [nativeEmitterSubscriptionKey]: nativeEmitterSubscription,\n      remove: () => {\n        this.removeSubscription(subscription);\n      },\n    };\n    return subscription;\n  }\n\n  removeAllListeners(eventName: string): void {\n    const removedListenerCount = this._eventEmitter.listeners(eventName).length;\n    this._eventEmitter.removeAllListeners(eventName);\n    this._listenerCount -= removedListenerCount;\n    invariant(\n      this._listenerCount >= 0,\n      `EventEmitter must have a non-negative number of listeners`\n    );\n\n    if (!this._listenerCount && Platform.OS !== 'ios' && this._nativeModule.stopObserving) {\n      this._nativeModule.stopObserving();\n    }\n  }\n\n  removeSubscription(subscription: Subscription): void {\n    const nativeEmitterSubscription = subscription[nativeEmitterSubscriptionKey];\n    if (!nativeEmitterSubscription) {\n      return;\n    }\n\n    this._eventEmitter.removeSubscription(nativeEmitterSubscription!);\n    this._listenerCount--;\n\n    // Ensure that the emitter's internal state remains correct even if `removeSubscription` is\n    // called again with the same subscription\n    delete subscription[nativeEmitterSubscriptionKey];\n\n    // Release closed-over references to the emitter\n    subscription.remove = () => {};\n\n    if (!this._listenerCount && Platform.OS !== 'ios' && this._nativeModule.stopObserving) {\n      this._nativeModule.stopObserving();\n    }\n  }\n\n  emit(eventName: string, ...params: any[]): void {\n    this._eventEmitter.emit(eventName, ...params);\n  }\n}\n"],"sourceRoot":""},"metadata":{},"sourceType":"module"}