return remover function when adding NetInfo listener

Reviewed By: dmmiller

Differential Revision: D2931623

fb-gh-sync-id: d67e986e2b4a503c0966a3f90788e207c452f216
shipit-source-id: d67e986e2b4a503c0966a3f90788e207c452f216
This commit is contained in:
Spencer Ahrens 2016-02-12 18:08:38 -08:00 committed by facebook-github-bot-5
parent 1beced56c8
commit 1c507e6291
1 changed files with 8 additions and 2 deletions

View File

@ -166,7 +166,7 @@ const NetInfo = {
addEventListener(
eventName: ChangeEventName,
handler: Function
): void {
): {remove: () => void} {
const listener = RCTDeviceEventEmitter.addListener(
DEVICE_CONNECTIVITY_EVENT,
(appStateData) => {
@ -174,6 +174,9 @@ const NetInfo = {
}
);
_subscriptions.set(handler, listener);
return {
remove: () => NetInfo.removeEventListener(eventName, handler)
};
},
removeEventListener(
@ -203,7 +206,7 @@ const NetInfo = {
addEventListener(
eventName: ChangeEventName,
handler: Function
): void {
): {remove: () => void} {
const listener = (connection) => {
handler(_isConnected(connection));
};
@ -212,6 +215,9 @@ const NetInfo = {
eventName,
listener
);
return {
remove: () => NetInfo.isConnected.removeEventListener(eventName, handler)
};
},
removeEventListener(