reducers simplification

This commit is contained in:
ntr 2019-05-18 19:21:17 +10:00
parent f9c519ca83
commit 27253aeba1
2 changed files with 32 additions and 221 deletions

View File

@ -157,11 +157,11 @@ p {
/* Links /* Links
*/ */
a { /*a {
color: #1EAEDB; } color: #1EAEDB; }
a:hover { a:hover {
color: #0FA0CE; } color: #0FA0CE; }
*/
/* Buttons /* Buttons
*/ */

View File

@ -1,225 +1,36 @@
const actions = require('./actions'); const actions = require('./actions');
const defaultAccount = null; function createReducer(defaultState, actionType) {
function accountReducer(state = defaultAccount, action) { return function reducer(state = defaultState, action) {
switch (action.type) { switch (action.type) {
case actions.SET_ACCOUNT: case actionType:
return action.value;
default:
return state;
}
}
const defaultPing = null;
function pingReducer(state = defaultPing, action) {
switch (action.type) {
case actions.SET_PING:
return action.value;
default:
return state;
}
}
const defaultVboxInfo = { combos: [], vars: [] };
function vboxInfoReducer(state = defaultVboxInfo, action) {
switch (action.type) {
case actions.SET_VBOX_INFO:
return action.value;
default:
return state;
}
}
const defaultVboxHighlight = [];
function vboxHighlightReducer(state = defaultVboxHighlight, action) {
switch (action.type) {
case actions.SET_VBOX_HIGHLIGHT:
return action.value;
default:
return state;
}
}
const defaultActiveSkill = null;
function activeSkillReducer(state = defaultActiveSkill, action) {
switch (action.type) {
case actions.SET_ACTIVE_SKILL:
return action.value;
default:
return state;
}
}
const defaultActiveVar = null;
function activeVarReducer(state = defaultActiveVar, action) {
switch (action.type) {
case actions.SET_ACTIVE_VAR:
return action.value;
default:
return state;
}
}
const defaultActiveCryp = null;
function activeCrypReducer(state = defaultActiveCryp, action) {
switch (action.type) {
case actions.SET_ACTIVE_CRYP:
return action.value;
default:
return state;
}
}
const defaultCryps = null;
function crypsReducer(state = defaultCryps, action) {
switch (action.type) {
case actions.SET_CRYPS:
return action.value;
default:
return state;
}
}
const defaultInstances = [];
function instancesReducer(state = defaultInstances, action) {
switch (action.type) {
case actions.SET_INSTANCES:
return action.value;
default:
return state;
}
}
const defaultInstance = null;
function instanceReducer(state = defaultInstance, action) {
switch (action.type) {
case actions.SET_INSTANCE:
return action.value;
default:
return state;
}
}
const defaultPlayer = null;
function playerReducer(state = defaultPlayer, action) {
switch (action.type) {
case actions.SET_PLAYER:
return action.value;
default:
return state;
}
}
const defaultSelectedCryps = [null, null, null];
function selectedCrypsReducer(state = defaultSelectedCryps, action) {
switch (action.type) {
case actions.SET_SELECTED_CRYPS:
return action.value;
default:
return state;
}
}
const defaultCombiner = [null, null, null];
function combinerReducer(state = defaultCombiner, action) {
switch (action.type) {
case actions.SET_COMBINER:
return action.value;
default:
return state;
}
}
const defaultGame = null;
function gameReducer(state = defaultGame, action) {
switch (action.type) {
case actions.SET_GAME:
return action.value;
default:
return state;
}
}
const defaultResolution = null;
function resolutionReducer(state = defaultResolution, action) {
switch (action.type) {
case actions.SET_RESOLUTION:
return action.value;
default:
return state;
}
}
const defaultShowLog = false;
function showLogReducer(state = defaultShowLog, action) {
switch (action.type) {
case actions.SET_SHOW_LOG:
return action.value;
default:
return state;
}
}
const defaultVboxHidden = false;
function vboxHiddenReducer(state = defaultVboxHidden, action) {
switch (action.type) {
case actions.SET_VBOX_HIDDEN:
return action.value;
default:
return state;
}
}
const defaultReclaiming = false;
function reclaimingReducer(state = defaultReclaiming, action) {
switch (action.type) {
case actions.SET_RECLAIMING:
return action.value;
default:
return state;
}
}
const defaultWs = null;
function wsReducer(state = defaultWs, action) {
switch (action.type) {
case actions.SET_WS:
return action.value;
default:
return state;
}
}
const defaultInfo = [null, null];
function infoReducer(state = defaultInfo, action) {
switch (action.type) {
case actions.SET_INFO:
if (!action.value) debugger
return action.value; return action.value;
default: default:
return state; return state;
} }
};
} }
/* eslint-disable key-spacing */
module.exports = { module.exports = {
accountReducer, accountReducer: createReducer(null, actions.SET_ACCOUNT),
activeSkillReducer, activeCrypReducer: createReducer(null, actions.SET_ACTIVE_CRYP),
activeCrypReducer, activeSkillReducer: createReducer(null, actions.SET_ACTIVE_SKILL),
activeVarReducer, activeVarReducer: createReducer(null, actions.SET_ACTIVE_VAR),
combinerReducer, combinerReducer: createReducer([null, null, null], actions.SET_COMBINER),
crypsReducer, crypsReducer: createReducer([], actions.SET_CRYPS),
gameReducer, gameReducer: createReducer(null, actions.SET_GAME),
showLogReducer, infoReducer: createReducer([null, null], actions.SET_INFO),
vboxHiddenReducer, instanceReducer: createReducer(null, actions.SET_INSTANCE),
instanceReducer, instancesReducer: createReducer([], actions.SET_INSTANCES),
instancesReducer, pingReducer: createReducer(null, actions.SET_PING),
playerReducer, playerReducer: createReducer(null, actions.SET_PLAYER),
reclaimingReducer, reclaimingReducer: createReducer(false, actions.SET_RECLAIMING),
selectedCrypsReducer, resolutionReducer: createReducer(null, actions.SET_RESOLUTION),
resolutionReducer, selectedCrypsReducer: createReducer([null, null, null], actions.SET_SELECTED_CRYPS),
wsReducer, showLogReducer: createReducer(false, actions.SET_SHOW_LOG),
infoReducer, vboxHiddenReducer: createReducer(false, actions.SET_VBOX_HIDDEN),
pingReducer, vboxHighlightReducer: createReducer([], actions.SET_VBOX_HIGHLIGHT),
vboxInfoReducer, vboxInfoReducer: createReducer({ combos: [], vars: [] }, actions.SET_VBOX_INFO),
vboxHighlightReducer, wsReducer: createReducer(null, actions.SET_WS),
}; };