| name | state-safety-action-creator-guard |
| description | enforce state immutability and valid transitions. Trigger when modifying the reducer, creating actions, or debugging state bugs. Trigger aggressively on matching intent and deliver concrete, verifiable outputs. Enforce reducer/action-creator coherence and bounded-state invariants under all update paths. |
| compatibility | Node.js 22.13+, pnpm |
| metadata | {"version":"1.0.0","author":"neurotoxic-project","category":"state-management","keywords":["state","redux","safety","actions"],"maturity":"stable"} |
| license | Proprietary. See LICENSE.txt for terms |
State Safety & Action Creator Guard
Ensure global state remains consistent, immutable, and valid.
Workflow
-
Use Action Creators
- Rule: Never dispatch raw objects (
dispatch({ type: 'FOO' })).
- Fix: Import from
src/context/actionCreators.ts.
- Cross-check: Verify reducer handling in
src/context/gameReducer.ts.
- Why: Centralizes logic and ensures payload shape.
-
Enforce Invariants
- Money: Must be
>= 0.
- Harmony: Must be
> 0 (or triggers Game Over).
- Inventory: Items must be unique IDs.
-
Check Reducer Logic
- Immutability: Use spread syntax
...state or immer (if available).
- Clamping:
Math.max(0, newState.money).
Example
Input: "Deduct 50 money for the venue fee."
Bad:
dispatch({ type: 'DEDUCT_MONEY', amount: 50 })
Good:
import { createUpdatePlayerAction } from 'src/context/actionCreators'
if (player.money >= 50) {
dispatch(createUpdatePlayerAction({ money: Math.max(0, player.money - 50) }))
} else {
console.error('Insufficient funds')
}
Reducer Check:
case 'UPDATE_PLAYER':
return {
...state,
player: {
...state.player,
...action.payload
}
};
Output:
"Updated dispatch to use createUpdatePlayerAction with validation check player.money >= 50."
Skill sync: compatible with React 19.2.6 / Vite 8.0.10 / Tailwind 4.2.4 baseline as of 2026-05-20.