Permalink
Browse files

Rewrite unit info reducer to update current Unit model

  • Loading branch information...
markerikson committed Dec 30, 2017
1 parent b08a248 commit 2a6592be28075980c9c92524cb1bee577e893267
Showing with 22 additions and 23 deletions.
  1. +1 −1 src/app/reducers/rootReducer.js
  2. +21 −22 src/features/unitInfo/unitInfoReducer.js
@@ -18,7 +18,6 @@ import editingFeatureReducer from "features/editing/editingReducer";
const combinedReducer = combineReducers({
entities : entitiesReducer,
editingEntities : editingEntitiesReducer,
unitInfo : unitInfoReducer,
pilots : pilotsReducer,
mechs : mechsReducer,
tabs : tabReducer,
@@ -31,6 +30,7 @@ const rootReducer = reduceReducers(
combinedReducer,
entityCrudReducer,
editingFeatureReducer,
unitInfoReducer,
);
export default rootReducer;
@@ -1,41 +1,40 @@
import {createReducer} from "common/utils/reducerUtils";
import orm from "app/schema";
import {createConditionalSliceReducer} from "common/utils/reducerUtils";
import {DATA_LOADED} from "features/tools/toolConstants";
import {
UNIT_INFO_UPDATE,
UNIT_INFO_SET_COLOR,
} from "./unitInfoConstants";
const initialState = {
name : "N/A",
affiliation : "",
color : "blue"
};
function dataLoaded(state, payload) {
const {unit} = payload;
function updateUnitInfo(state, payload) {
const session = orm.session(state);
const {Unit} = session;
return unit;
}
const currentUnit = Unit.all().first();
function updateUnitInfo(state, payload) {
return {
...state,
...payload,
};
if(currentUnit) {
currentUnit.update(payload);
}
return session.state;
}
function setUnitColor(state, payload) {
const {color} = payload;
const session = orm.session(state);
const {Unit} = session;
const currentUnit = Unit.all().first();
if(currentUnit) {
currentUnit.color = color;
}
return {
...state,
color
};
return session.state;
}
export default createReducer(initialState, {
[DATA_LOADED] : dataLoaded,
export default createConditionalSliceReducer("entities", {
[UNIT_INFO_UPDATE] : updateUnitInfo,
[UNIT_INFO_SET_COLOR] : setUnitColor,
});

0 comments on commit 2a6592b

Please sign in to comment.