Regression: game.js still holds eight jobs in one 1,862-line scope

Offen
#171 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Anfängerfreundlichkeit
35/100
Issue-Typ
Refactoring
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
javascript
Bereich
backend

Rechercherichtung

Read js/game.js alongside js/notation.js, js/saved-game.js, and js/rules.js; start with the proposed playersFromPGN and replayUndoStack extractions and add direct unit tests for them. Then review statusForOutcome, describeMove, and the material count, using tests/helpers/load-game.js and npm test as described. Done means steps 1–4 are extracted, each extraction is committed separately, and the full suite passes after each.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

severity: medium tech-debt

Summary

#89 split some UI code out (game-ui.js), but js/game.js is still one 1,862-line script. It shares about 30 mutable top-level lets across eight jobs and is the most-changed file in the repo (74 of the last 200 commits). Several functions in it are pure, or close to pure, and can move out with little risk.

Where

  • js/game.js:6-56: live state, about 30 lets
  • js/game.js:357-595: review and autoplay
  • js/game.js:1101-1215: clock
  • js/game.js:1345-1430: persistence and replay
  • js/game.js:1599-1764: PGN/FEN export and import
  • js/game.js:1766-1862: exports, including 15 getters only tests use

Details

The file's own section comments list its jobs: move flow, review and autoplay, ending a game without a move, the computer opponent, the clock, hints, persistence and replay, past games, view models, and PGN/FEN import and export.

Functions here that are pure or nearly pure:

  • replayUndoStack(start, moves, saved), around line 1400
  • playersFromPGN(text), around line 1720
  • statusForOutcome, around line 717
  • the material count in updateCapturedDisplay, around lines 1496-1501
  • isThreefoldRepetition, around line 1293

Impact

Every recent feature (Redo, the Play button, random side, rebuilding the undo stack on load) had to edit this file and keep all of its globals in mind. Pure logic in it can only be tested by loading the whole page in jsdom (tests/helpers/load-game.js).

Suggested fix

Extract in small PRs, pure code first. Keep the old global name as a one-line alias until its callers move, so every PR leaves the page working.

  1. Move playersFromPGN to notation.js.
  2. Move replayUndoStack to saved-game.js or rules.js, as rebuildUndoStack(start, moves, savedKey).
  3. Move statusForOutcome and the move sentence of describeMove into a small text module, or into review.js.
  4. Move the material count into rules.js as materialBalance(board).
  5. Only then consider extracting the clock section behind an object that game.js owns.

Acceptance criteria

  • Before starting: unit tests that call replayUndoStack and playersFromPGN directly, and characterization tests for the describeMove text of castling, en passant, promotion and check.
  • Each extraction is its own commit, and the full suite passes after each one.
  • game.js loses steps 1-4.

Getting started

  • Relevant files: js/game.js, js/notation.js, js/saved-game.js, js/rules.js, tests/helpers/load-game.js
  • How to run tests: npm test

Regression of #89.


Filed by repo-audit/full-audit at 01c6a35. Severity: medium. Effort: L. audit-key: tech-debt|js/game.js|module-structure

Vorherrschende Sprache
JavaScript
Sterne
4
Forks
2
Ø Merge
22 Std. 16 Min.
Gemergte PRs (30 T.)
9

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus TMHSDigital/Static_Chess

Alle Issues in TMHSDigital/Static_Chess

Ähnliche Issues

Weitere Issues zu JavaScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.