From bbf505c0762549c817dab1714a864d2a28b7cdd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Tue, 29 May 2018 12:31:27 +0200 Subject: [PATCH] ref(base/conference): simplify code Simplify parts of the logic introduced in 11b7144ad004118a3fa8904458733b3c6c317448. Specificaly, using all the state change avoiding functions doesn't give us much since we need to copy the state for sure. --- react/features/base/conference/reducer.js | 32 +++++------------------ 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/react/features/base/conference/reducer.js b/react/features/base/conference/reducer.js index 0266bb8db..e0b9ad745 100644 --- a/react/features/base/conference/reducer.js +++ b/react/features/base/conference/reducer.js @@ -60,10 +60,7 @@ ReducerRegistry.register('features/base/conference', (state = {}, action) => { return _setDesktopSharingEnabled(state, action); case SET_FOLLOW_ME: - return { - ...state, - followMeEnabled: action.enabled - }; + return set(state, 'followMeEnabled', action.enabled); case SET_PASSWORD: return _setPassword(state, action); @@ -206,7 +203,7 @@ function _conferenceJoined(state, { conference }) { * reduction of the specified action. */ function _conferenceLeftOrWillLeave(state, { conference, type }) { - let nextState = state; + const nextState = { ...state }; // The redux action CONFERENCE_LEFT is the last time that we should be // hearing from a JitsiConference instance. @@ -217,20 +214,14 @@ function _conferenceLeftOrWillLeave(state, { conference, type }) { // due clean-up like leaving the associated room, but the instance is no // longer the focus of the attention of the user and, consequently, the app. for (const p in state) { - if (p !== 'leaving' && state[p] === conference) { - nextState = set(nextState, p, undefined); + if (state[p] === conference) { + nextState[p] = undefined; switch (p) { case 'conference': - // XXX Clear/unset locked & password for a conference which has - // been LOCKED_LOCALLY. - delete nextState.locked; - delete nextState.password; - break; - case 'passwordRequired': // XXX Clear/unset locked & password for a conference which has - // been LOCKED_REMOTELY. + // been LOCKED_LOCALLY or LOCKED_REMOTELY. delete nextState.locked; delete nextState.password; break; @@ -238,15 +229,7 @@ function _conferenceLeftOrWillLeave(state, { conference, type }) { } } - // leaving - switch (type) { - case CONFERENCE_LEFT: - if (state.leaving === conference) { - nextState = set(nextState, 'leaving', undefined); - } - break; - - case CONFERENCE_WILL_LEAVE: + if (type === CONFERENCE_WILL_LEAVE) { // A CONFERENCE_WILL_LEAVE is of further consequence only if it is // expected i.e. if the specified conference is joining or joined. if (conference === state.joining || conference === state.conference) { @@ -256,9 +239,8 @@ function _conferenceLeftOrWillLeave(state, { conference, type }) { * * @type {JitsiConference} */ - nextState = set(nextState, 'leaving', conference); + nextState.leaving = conference; } - break; } return nextState;