File tree Expand file tree Collapse file tree 5 files changed +14
-7
lines changed
vanilla/guess-the-word/src Expand file tree Collapse file tree 5 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { difficulty } from "@/state/difficulty";
33import { AvailableWords } from "@/state/words" ;
44import { MasterDifficulty } from "@/utils/difficulty/master" ;
55import { InsaneDifficulty } from "@/utils/difficulty/insane" ;
6+ import { clearChildren } from "@/utils/dom" ;
67import { createWordLetters } from "@/ui/word" ;
78import { $triesContainer } from "@/ui/tries" ;
89import { $mistakesContainer } from "@/ui/mistakes" ;
@@ -33,7 +34,7 @@ export function handleDifficultyComplete() {
3334 import ( "@/ui/insane-countdown-bar" ) . then ( ( { hideInsaneCountdown } ) =>
3435 hideInsaneCountdown ( ) ,
3536 ) ;
36- while ( $typing . firstChild != null ) $typing . removeChild ( $typing . firstChild ) ;
37+ clearChildren ( $typing ) ;
3738 $typing . classList . add ( CLASSES . HIDDEN ) ;
3839
3940 showCompletedDifficultyMessage ( difficulty , { allCompleted : gameCompleted } ) ;
Original file line number Diff line number Diff line change 1+ import { clearChildren } from "@/utils/dom" ;
12import { $allHintsList , $correctHintsList } from "./elements" ;
23
34export const clearHints = ( ) => {
4- while ( $allHintsList . firstChild != null )
5- $allHintsList . removeChild ( $allHintsList . firstChild ) ;
6- while ( $correctHintsList . firstChild != null )
7- $correctHintsList . removeChild ( $correctHintsList . firstChild ) ;
5+ clearChildren ( $allHintsList , $correctHintsList ) ;
86} ;
Original file line number Diff line number Diff line change 11import { getElementById , getElementBySelector } from "@lib/dom" ;
22import { TypingLetterIndex } from "@/state/typing-letter" ;
3+ import { clearChildren } from "@/utils/dom" ;
34import { createLetterLabel } from "./letter-label" ;
45import { $typing } from "./elements" ;
56import { CLASSES } from "@/consts/css-classes" ;
@@ -12,7 +13,7 @@ const $letterFields = [];
1213/** @param {number } quantity */
1314export function createLetterFields ( quantity ) {
1415 $letterFields . length = 0 ;
15- while ( $typing . firstChild != null ) $typing . removeChild ( $typing . firstChild ) ;
16+ clearChildren ( $typing ) ;
1617
1718 for ( let idx = 0 ; idx < quantity ; idx ++ ) {
1819 const $letterClone = /** @type {DocumentFragment } */ (
Original file line number Diff line number Diff line change 11import { getElementById } from "@lib/dom" ;
22import { currentWord } from "@/state/current-word" ;
3+ import { clearChildren } from "@/utils/dom" ;
34
45const ATTRIBUTRES = Object . freeze ( {
56 LETTER : Object . freeze ( {
@@ -15,7 +16,7 @@ const lettersToUse = [""];
1516
1617/** @param {string } word */
1718export const createWordLetters = ( word ) => {
18- while ( $word . firstChild != null ) $word . removeChild ( $word . firstChild ) ;
19+ clearChildren ( $word ) ;
1920 $wordLetters . length = 0 ;
2021 lettersToUse . length = 0 ;
2122
Original file line number Diff line number Diff line change 1+ /** @param {HTMLElement[] } $elements */
2+ export const clearChildren = ( ...$elements ) => {
3+ for ( const $element of $elements )
4+ while ( $element . firstChild != null )
5+ $element . removeChild ( $element . firstChild ) ;
6+ } ;
You can’t perform that action at this time.
0 commit comments