Massive refactor complete

This commit is contained in:
2019-05-31 13:44:01 +10:00
parent b97d8fc184
commit 4a2bfb3db9
47 changed files with 1223 additions and 991 deletions
@@ -1,4 +1,4 @@
import { LOGIN, LOGOUT, SESSIONCHANGE } from "../actions/accounts.js";
import { LOGIN, LOGOUT, SESSION_CHANGE } from "../actions/account.js";
const initialStore = {
id: 0,
@@ -7,7 +7,7 @@ const initialStore = {
token: 0
};
export function accountReducer(store = initialStore, action) {
export const accountReducer = (store = initialStore, action) => {
switch(action.type) {
case LOGIN: {
let newStore = JSON.parse(JSON.stringify(initialStore));
@@ -23,7 +23,7 @@ export function accountReducer(store = initialStore, action) {
case LOGOUT:
return initialStore;
case SESSIONCHANGE: {
case SESSION_CHANGE: {
let newStore = JSON.parse(JSON.stringify(store));
newStore.token = action.token;
@@ -33,6 +33,6 @@ export function accountReducer(store = initialStore, action) {
default:
return store;
}
};
}
-18
View File
@@ -1,18 +0,0 @@
import { SET_ATTACK_DISABLED } from '../actions/combat.js';
const initialStore = {
attackDisabled: false
};
export function combatReducer(store = initialStore, action) {
switch(action.type) {
case SET_ATTACK_DISABLED: {
let newStore = JSON.parse(JSON.stringify(initialStore));
newStore.attackDisabled = action.disabled;
return newStore;
}
default:
return store;
}
}
+59
View File
@@ -0,0 +1,59 @@
import {
STORE_PROFILE,
STORE_USERNAME,
STORE_GOLD,
STORE_RECRUITS,
STORE_SOLDIERS,
STORE_SPIES,
STORE_SCIENTISTS
} from '../actions/profile.js';
const initialStore = {
username: '',
gold: 0,
recruits: 0,
soldiers: 0,
spies: 0,
scientists: 0
};
export const profileReducer = (store = initialStore, action) => {
let newStore = JSON.parse(JSON.stringify(store));
switch(action.type) {
case STORE_PROFILE:
newStore.username = action.username;
newStore.gold = action.gold;
newStore.recruits = action.recruits;
newStore.soldiers = action.soldiers;
newStore.spies = action.spies;
newStore.scientists = action.scientists;
break;
case STORE_USERNAME:
newStore.username = action.username;
break;
case STORE_GOLD:
newStore.gold = action.gold;
break;
case STORE_RECRUITS:
newStore.recruits = action.recruits;
break;
case STORE_SOLDIERS:
newStore.soldiers = action.soldiers;
break;
case STORE_SPIES:
newStore.spies = action.spies;
break;
case STORE_SCIENTISTS:
newStore.scientists = action.scientists;
break;
};
return newStore;
}
+3 -3
View File
@@ -1,10 +1,10 @@
import { combineReducers } from 'redux';
import { accountReducer } from './accounts.js';
import { combatReducer } from './combat.js';
import { accountReducer } from './account.js';
import { profileReducer } from './profile.js';
//compile all reducers together
export default combineReducers({
account: accountReducer,
/* combat: combatReducer */
profile: profileReducer
});