refactor(game): unify move handling using typed payloads and remove UI-driven handlers
- Removed onCellClick from TicTacToeGameProps and migrated move sending inside TicTacToeGame
- Updated TicTacToeGame to:
- import TicTacToePayload
- use movePayload() builder
- send moves using handleMove() with matchId + sendMatchData
- remove old matchId destructuring duplication
- Updated BattleshipGame to:
- import BattleshipPayload
- use placePayload() and shootPayload() helpers
- collapse place and shoot handlers into a single handleMove()
- send typed payloads instead of raw objects
- Updated App.tsx:
- Removed handleCellClick and no longer pass onCellClick down
- Created typed ticTacToeProps and battleshipProps without UI callbacks
- Cleaned unused state and simplified board rendering
- Use {...commonProps} to propagate shared game state
- Updated props:
- Removed TicTacToeGameProps.onCellClick
- BattleshipGameProps continues to extend GameProps
- Removed duplicate MatchDataModel definition from interfaces/models
- Fixed imports to use revised models and payload types
This refactor completes the transition from UI-triggered handlers to
typed action payloads per game, significantly improving type safety,
consistency, and separation of concerns.
This commit is contained in:
10
src/App.tsx
10
src/App.tsx
@@ -35,7 +35,6 @@ export default function App() {
|
||||
};
|
||||
const ticTacToeProps: TicTacToeGameProps = {
|
||||
...commonProps,
|
||||
onCellClick: handleCellClick,
|
||||
};
|
||||
const battleshipProps: BattleshipGameProps = {
|
||||
...commonProps,
|
||||
@@ -104,15 +103,6 @@ export default function App() {
|
||||
onMatchData(onMatchDataCallback);
|
||||
}, [onMatchData]);
|
||||
|
||||
// ------------------------------------------
|
||||
// SEND A MOVE
|
||||
// ------------------------------------------
|
||||
function handleCellClick(row: number, col: number) {
|
||||
if (!matchId) return;
|
||||
|
||||
sendMatchData(matchId, 1, { data: { row, col } });
|
||||
}
|
||||
|
||||
// ---------------------------------------------------
|
||||
// UI LAYOUT
|
||||
// ---------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user