[priority: high] Bloated state types — GameState (71 fields), CombatState (58), PrestigeState (39) #102
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Severity: High — god-objects make it impossible to reason about state ownership, increase coupling, and cause unnecessary re-renders.
Findings:
GameStatehas 71 fields covering time, mana, elements, spells, skills, equipment, crafting, scheduling, golemancy, achievements, combat, prestige, pacts, logsCombatStatehas 58 fieldsPrestigeStatehas 39 fieldsManaStatehas 24 fields plus 15+ action methodsDisciplineCardPropshas 15 fields — component doing too many thingsAffected files:
src/lib/game/types/game.tssrc/lib/game/stores/combat-state.types.tssrc/lib/game/stores/prestigeStore.tssrc/lib/game/stores/manaStore.tssrc/components/game/tabs/DisciplinesTab.tsxSuggested fix: The modular stores already split these at the store level — align the types. Each store should have its own state type with only domain-relevant fields. Remove the monolithic
GameStatetype. Split wide store interfaces into State and Actions types.Confidence: High
Dimension: design_coherence (score: 58.0%)
Starting work on issue #102: Bloated state types. Will analyze the current state types and split them into domain-specific types aligned with the modular stores.
Analysis Complete
Current State
GameState (71 fields in
types/game.ts): Legacy monolithic type still used bycrafting-actions/utility files. The modular stores already split this at the store level. Usage:crafting-actions/application-actions.ts— usesGameStatefor get/setcrafting-actions/computed-getters.ts— usesGameStatefor getcrafting-actions/crafting-equipment-actions.ts— usesGameStatefor get/setcrafting-actions/design-actions.ts— usesGameStatefor get/setcrafting-actions/disenchant-actions.ts— usesGameStatefor get/setcrafting-actions/equipment-actions.ts— usesGameStatefor get/setutils/combat-utils.ts— usesPick<GameState, ...>for specific field subsetsutils/mana-utils.ts— usesPick<GameState, ...>for specific field subsetsCombatState (58 fields in
stores/combat-state.types.ts): Mixes 16 data fields + 26 action methods in one interface. Used bycombatStore.ts,combat-actions.ts,tick-pipeline.ts,stores/index.ts.PrestigeState (39 fields in
stores/prestigeStore.ts): Mixes 13 data fields + 17 action methods. Used bytick-pipeline.ts,stores/index.ts.ManaState (24 fields + actions in
stores/manaStore.ts): Mixes 4 data fields + 13 action methods. Used bytick-pipeline.ts,stores/index.ts.DisciplineCardProps (15 fields in
DisciplinesTab.tsx): Component props mixing discipline definition data + runtime state + callbacks.Approach
CombatState: Split into
CombatState(data only) +CombatActions. UpdatecombatStore.tsto use combined type. Updatetick-pipeline.tsto import data type only.PrestigeState: Split into
PrestigeState(data only) +PrestigeActions. UpdateprestigeStore.tsandtick-pipeline.ts.ManaState: Split into
ManaState(data only) +ManaActions. UpdatemanaStore.tsandtick-pipeline.ts.GameState: The
crafting-actions/files that useGameStateare legacy utilities. The actual crafting store (craftingStore.ts) already usesCraftingStatefromcraftingStore.types.ts. Update the crafting-actions to useCraftingStateinstead ofGameStatewhere possible, and use more specificPick<>types for utility functions.DisciplineCardProps: Split into
DisciplineDefinition(static data) +DisciplineRuntimeState(runtime data) +DisciplineCardCallbacks(event handlers).Starting implementation now.
Implementation Complete
Changes Made
1. CombatState split (
stores/combat-state.types.ts):CombatState(16 data fields) +CombatActions(25 action methods) +CombatStore(combined type)combatStore.tsto useCombatStoretypecombat-actions.tsto useCombatStorefor get/set2. PrestigeState split (
stores/prestigeStore.ts):PrestigeState(13 data fields) +PrestigeActions(17 action methods) +PrestigeStore(combined type)3. ManaState split (
stores/manaStore.ts):ManaState(4 data fields) +ManaActions(13 action methods) +ManaStore(combined type)4. GameState deprecated (
types/game.ts,types/index.ts,types.ts):GameStatefrom all barrel exportscrafting-actions/files to useCraftingStateinstead ofGameStatecombat-utils.tsandmana-utils.tsto use focused parameter interfaces instead ofPick<GameState, ...>DamageCalcParams,InsightCalcParams,DPSCalcParams,ManaComputeParams,RegenComputeParams5. DisciplineCardProps split (
DisciplinesTab.tsx):DisciplineCardDefinition(10 static data fields)DisciplineCardRuntime(3 runtime state fields)DisciplineCardCallbacks(1 callback)6. Store index updated (
stores/index.ts):Test Results
Issue #102 resolved. All changes committed and pushed to master (commit
8a7ddaa). Bloated state types have been split into focused State + Actions interfaces aligned with the modular stores.