From ca33cbd4b95ba3a8d0381bc1740e1feb8a2ff73a Mon Sep 17 00:00:00 2001 From: Eric Vicenti Date: Thu, 11 Jun 2015 13:34:38 -0700 Subject: [PATCH] [ReactNative] PushNotificationIOS listener Map --- .../PushNotificationIOS/PushNotificationIOS.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Libraries/PushNotificationIOS/PushNotificationIOS.js b/Libraries/PushNotificationIOS/PushNotificationIOS.js index fa2be650a..adf8ecf5a 100644 --- a/Libraries/PushNotificationIOS/PushNotificationIOS.js +++ b/Libraries/PushNotificationIOS/PushNotificationIOS.js @@ -11,11 +11,12 @@ */ 'use strict'; +var Map = require('Map'); var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter'); var RCTPushNotificationManager = require('NativeModules').PushNotificationManager; var invariant = require('invariant'); -var _notifHandlers = {}; +var _notifHandlers = new Map(); var _initialNotification = RCTPushNotificationManager && RCTPushNotificationManager.initialNotification; @@ -65,21 +66,23 @@ class PushNotificationIOS { type === 'notification' || type === 'register', 'PushNotificationIOS only supports `notification` and `register` events' ); + var listener; if (type === 'notification') { - _notifHandlers[String(handler)] = RCTDeviceEventEmitter.addListener( + listener = RCTDeviceEventEmitter.addListener( DEVICE_NOTIF_EVENT, (notifData) => { handler(new PushNotificationIOS(notifData)); } ); } else if (type === 'register') { - _notifHandlers[String(handler)] = RCTDeviceEventEmitter.addListener( + listener = RCTDeviceEventEmitter.addListener( NOTIF_REGISTER_EVENT, (registrationInfo) => { handler(registrationInfo.deviceToken); } ); } + _notifHandlers.set(handler, listener); } /** @@ -143,11 +146,12 @@ class PushNotificationIOS { type === 'notification' || type === 'register', 'PushNotificationIOS only supports `notification` and `register` events' ); - if (!_notifHandlers[String(handler)]) { + var listener = _notifHandlers.get(handler); + if (!listener) { return; } - _notifHandlers[String(handler)].remove(); - _notifHandlers[String(handler)] = null; + listener.remove(); + _notifHandlers.delete(handler); }