Skip to content

Commit

Permalink
return remover function when adding NetInfo listener
Browse files Browse the repository at this point in the history
Reviewed By: dmmiller

Differential Revision: D2931623

fb-gh-sync-id: d67e986e2b4a503c0966a3f90788e207c452f216
shipit-source-id: d67e986e2b4a503c0966a3f90788e207c452f216
  • Loading branch information
sahrens authored and facebook-github-bot-5 committed Feb 13, 2016
1 parent 1beced5 commit 1c507e6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Libraries/Network/NetInfo.js
Expand Up @@ -166,14 +166,17 @@ const NetInfo = {
addEventListener(
eventName: ChangeEventName,
handler: Function
): void {
): {remove: () => void} {
const listener = RCTDeviceEventEmitter.addListener(
DEVICE_CONNECTIVITY_EVENT,
(appStateData) => {
handler(appStateData.network_info);
}
);
_subscriptions.set(handler, listener);
return {
remove: () => NetInfo.removeEventListener(eventName, handler)
};
},

removeEventListener(
Expand Down Expand Up @@ -203,7 +206,7 @@ const NetInfo = {
addEventListener(
eventName: ChangeEventName,
handler: Function
): void {
): {remove: () => void} {
const listener = (connection) => {
handler(_isConnected(connection));
};
Expand All @@ -212,6 +215,9 @@ const NetInfo = {
eventName,
listener
);
return {
remove: () => NetInfo.isConnected.removeEventListener(eventName, handler)
};
},

removeEventListener(
Expand Down

0 comments on commit 1c507e6

Please sign in to comment.