b8ne / react-native-pusher-push-notifications

Manage pusher interest subscriptions and notification events in Javascript.
MIT License
96 stars 85 forks source link

Return listeners on `.on()` calls for later cleanup #78

Closed codynguyen closed 2 years ago

codynguyen commented 2 years ago

Hi,

This small change returns the listener created by the RNPusherPushNotifications.on() call, so that we can clean it up if we want to. This is helpful in logout - re-login flow where the listeners from a previous login keeps lingering and listening to new events.

// On login
const registerListener = RNPusherPushNotifications.on('registered', () => {});
const notificationListener = RNPusherPushNotifications.on('notification', () => {});

// On logout
registerListener.remove();
notificationListener.remove();

Hoping for this to be merged to upstream. Thanks!

Humni commented 2 years ago

@codynguyen this looks good to me, thanks for the updated documentation too!