Enforce State Safety and Action Creators
Key Files
- •
src/context/actionCreators.js— canonical action creators (use these, not raw dispatch) - •
src/context/gameReducer.js— reducer with balance clamps and state transitions - •
src/context/initialState.js— default state shape and initial values - •
src/context/GameState.jsx— context provider anduseGameStatehook - •
src/utils/eventEngine.js—processEffectandapplyResultproduce state deltas - •
src/utils/economyEngine.js— economy calculations that feed into state - •
src/utils/gameStateUtils.js— state utility helpers - •
tests/actionCreators.test.js— action creator tests - •
tests/gameReducer.test.js— reducer tests including clamp assertions
Workflow
- •Grep for raw
dispatch({type:calls — these should use action creators fromactionCreators.jsinstead. - •Review
gameReducer.jsfor everycasethat modifiesplayer.moneyorband.harmony— confirm clamps at 0. - •Check
eventEngine.jsprocessEffectfor stat effects that could produce invalid state. - •Verify
initialState.jsdefaults are valid (money >= 0, harmony > 0). - •Add/adjust unit tests in
tests/gameReducer.test.jsandtests/actionCreators.test.jsto cover negative-value clamps.
Output
- •Provide a short list of violations and fixes.
- •Update tests for any behavior change.
Related Skills
- •
game-balancing-assistant— for tuning the values that state safety guards - •
refactor-with-safety— when restructuring state management code