ref(base/conference): simplify code

Simplify parts of the logic introduced in
11b7144ad0.

Specificaly, using all the state change avoiding functions doesn't give us much
since we need to copy the state for sure.
This commit is contained in:
Saúl Ibarra Corretgé 2018-05-29 12:31:27 +02:00 committed by Lyubo Marinov
parent ead62a5dde
commit bbf505c076
1 changed files with 7 additions and 25 deletions

View File

@ -60,10 +60,7 @@ ReducerRegistry.register('features/base/conference', (state = {}, action) => {
return _setDesktopSharingEnabled(state, action); return _setDesktopSharingEnabled(state, action);
case SET_FOLLOW_ME: case SET_FOLLOW_ME:
return { return set(state, 'followMeEnabled', action.enabled);
...state,
followMeEnabled: action.enabled
};
case SET_PASSWORD: case SET_PASSWORD:
return _setPassword(state, action); return _setPassword(state, action);
@ -206,7 +203,7 @@ function _conferenceJoined(state, { conference }) {
* reduction of the specified action. * reduction of the specified action.
*/ */
function _conferenceLeftOrWillLeave(state, { conference, type }) { function _conferenceLeftOrWillLeave(state, { conference, type }) {
let nextState = state; const nextState = { ...state };
// The redux action CONFERENCE_LEFT is the last time that we should be // The redux action CONFERENCE_LEFT is the last time that we should be
// hearing from a JitsiConference instance. // 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 // 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. // longer the focus of the attention of the user and, consequently, the app.
for (const p in state) { for (const p in state) {
if (p !== 'leaving' && state[p] === conference) { if (state[p] === conference) {
nextState = set(nextState, p, undefined); nextState[p] = undefined;
switch (p) { switch (p) {
case 'conference': case 'conference':
// XXX Clear/unset locked & password for a conference which has
// been LOCKED_LOCALLY.
delete nextState.locked;
delete nextState.password;
break;
case 'passwordRequired': case 'passwordRequired':
// XXX Clear/unset locked & password for a conference which has // XXX Clear/unset locked & password for a conference which has
// been LOCKED_REMOTELY. // been LOCKED_LOCALLY or LOCKED_REMOTELY.
delete nextState.locked; delete nextState.locked;
delete nextState.password; delete nextState.password;
break; break;
@ -238,15 +229,7 @@ function _conferenceLeftOrWillLeave(state, { conference, type }) {
} }
} }
// leaving if (type === CONFERENCE_WILL_LEAVE) {
switch (type) {
case CONFERENCE_LEFT:
if (state.leaving === conference) {
nextState = set(nextState, 'leaving', undefined);
}
break;
case CONFERENCE_WILL_LEAVE:
// A CONFERENCE_WILL_LEAVE is of further consequence only if it is // A CONFERENCE_WILL_LEAVE is of further consequence only if it is
// expected i.e. if the specified conference is joining or joined. // expected i.e. if the specified conference is joining or joined.
if (conference === state.joining || conference === state.conference) { if (conference === state.joining || conference === state.conference) {
@ -256,9 +239,8 @@ function _conferenceLeftOrWillLeave(state, { conference, type }) {
* *
* @type {JitsiConference} * @type {JitsiConference}
*/ */
nextState = set(nextState, 'leaving', conference); nextState.leaving = conference;
} }
break;
} }
return nextState; return nextState;