Background of the inquiry:
I am in the process of developing a web assistant for the popular party game Mafia, and my objective is to store each individual game using NGXS. The GitLab repository for this project can be found here.
The game includes the following elements:
- List of players
- List of passed days (ranging from 0 to around 5)
You can view the Player model here.
Each day follows three phases: Night > Day > Vote
You can access the Day model here.
In order to manage this complex day structure and record all player actions, I encountered challenges due to the large number of required actions. As the GameState
grew too big, I attempted to divide it into child states, but faced circular dependency issues.
Although I managed to address the problem by reviewing solutions like this one, utilizing CurrentDayState
and PlayersState
as child states seemed less than ideal because:
- I could only directly access state, while selectors with intricate logic remained out of reach.
- I was storing only the current day and vote, pushing them into the
GameState
's days array, which would complicate going back to previous days if necessary.
I feel that my approach may be cumbersome, and despite efforts, I haven't been able to devise a better solution. While storing all actions in the root GameState
is an option, this would lead to an excessively lengthy .ts file, which doesn't seem optimal.
The query:
Is there a method to modularize NGXS state, allowing each component to access selectors from other parts without encountering circular dependencies? (I'm aware sub-states in NGXS are meant to be autonomous and should not exert control over one another).