import { fromJS } from 'immutable';
import {
SET_LIVE_DATA,
RESET_LIVE_DATA,
SET_BLINK,
} from '.';
/**
* @namespace reducer/liveReducer
*/
const initialState = fromJS({
liveCountdown: '',
previousSecond: 0,
liveDecrement: 0,
scores: null,
blink: null,
setupLive: false,
});
/**
* @memberof reducer/liveReducer
* @param {object} state Contain initial and final state of data
* @param {object} action Return the action object
*
* @property {number|string} [liveCountdown='']
* @property {number} [previousSecond=0] Indicate previous second when scores data is calculated
* @property {number} [liveDecrement=0] Indicate number of seconds decremented in one real second
* @property {Array} [scores=null]
* @property {Array} [blink=null]
* @property {boolean} [setupLive=false]
*
* @returns {state}
*/
function liveReducer(state = initialState, action) { // NOSONAR
switch (action.type) {
/**
* [Received Data]
* This action is use to setup live data
*
* @memberof reducer/liveReducer
* @function reducer/liveReducer~SET_LIVE_DATA
*/
case SET_LIVE_DATA: {
return state
.set('blink', fromJS(action.payload.blink))
.set('scores', fromJS(action.payload.scores))
.set('liveCountdown', action.payload.liveCountdown)
.set('liveDecrement', action.payload.liveDecrement)
.set('previousSecond', action.payload.previousSecond)
.set('setupLive', action.payload.setupLive);
}
/**
* [Action Creator]
* This action is use to reset live data
*
* @memberof reducer/liveReducer
* @example resetLiveData(payload)
* @function reducer/liveReducer~SET_LIVE_DATA
*/
case RESET_LIVE_DATA: {
return state
.set('blink', null)
.set('scores', null)
.set('liveCountdown', '')
.set('liveDecrement', 0)
.set('previousSecond', 0)
.set('setupLive', false);
}
/**
* [Received Data]
* This action is use to reset blink animation
*
* @memberof reducer/liveReducer
* @function reducer/liveReducer~SET_BLINK
*/
case SET_BLINK: {
return state
.set('blink', fromJS(action.payload.blink));
}
default:
return state;
}
}
export default liveReducer;