refactor: separate Nakama provider concerns into context, refs, and state modules
- Extracted context contract to `contexts.ts` (NakamaContextType) - Added strongly typed internal provider refs in `refs.ts` - socketRef: React.RefObject<Socket | null> - gameMetadataRef: React.RefObject<GameMetadata | null> - Added `NakamaProviderState` in `states.ts` for React-managed provider state - session, socket, matchId, matchmakerTicket - Refactored NakamaProvider to use new modular structure - Replaced scattered useState/useRef with structured internal state + refs - Updated onMatchData to use MatchDataMessage model - Replaced deprecated MutableRefObject typing with RefObject - Cleaned update patterns using `updateState` helper - Updated imports to use new models and context structure - Improved separation of responsibilities: - models = pure domain types - context = exposed provider API - refs = internal mutable runtime refs - state = provider-managed reactive state - Ensured all Nakama provider functions fully typed and consistent with TS This refactor improves clarity, type safety, and maintainability for the Nakama real-time multiplayer provider.
This commit is contained in:
15
src/games/tictactoe/props.ts
Normal file
15
src/games/tictactoe/props.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import {
|
||||
Board,
|
||||
PlayerModel,
|
||||
} from '../../interfaces/models'
|
||||
|
||||
|
||||
export interface TicTacToeBoardProps {
|
||||
boards: Record<string, Board>;
|
||||
turn: number;
|
||||
winner: string | null;
|
||||
gameOver: boolean | null;
|
||||
players: PlayerModel[];
|
||||
myUserId: string | null;
|
||||
onCellClick: (row: number, col: number) => void;
|
||||
}
|
||||
Reference in New Issue
Block a user