From ed7d8ac57e2db79e6656ca9c9e6068ca56ec89c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Wed, 2 May 2018 13:37:20 +0200 Subject: [PATCH] [RN] Cleanup subscriptions for the invite module --- react/features/invite/middleware.native.js | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/react/features/invite/middleware.native.js b/react/features/invite/middleware.native.js index 800a725f3..15941b215 100644 --- a/react/features/invite/middleware.native.js +++ b/react/features/invite/middleware.native.js @@ -33,6 +33,9 @@ const { Invite } = NativeModules; */ Invite && MiddlewareRegistry.register(store => next => action => { switch (action.type) { + case _SET_EMITTER_SUBSCRIPTIONS: + return _setEmitterSubscriptions(store, next, action); + case APP_WILL_MOUNT: return _appWillMount(store, next, action); @@ -206,3 +209,29 @@ function _onPerformQuery( translatedResults); }); } + +/** + * Notifies the feature invite that the action + * {@link _SET_EMITTER_SUBSCRIPTIONS} is being dispatched within a specific + * redux {@code store}. + * + * @param {Store} store - The redux store in which the specified {@code action} + * is being dispatched. + * @param {Dispatch} next - The redux dispatch function to dispatch the + * specified {@code action} to the specified {@code store}. + * @param {Action} action - The redux action {@code _SET_EMITTER_SUBSCRIPTIONS} + * which is being dispatched in the specified {@code store}. + * @private + * @returns {*} + */ +function _setEmitterSubscriptions({ getState }, next, action) { + const { emitterSubscriptions } = getState()['features/invite']; + + if (emitterSubscriptions) { + for (const subscription of emitterSubscriptions) { + subscription.remove(); + } + } + + return next(action); +}