Skip to content

Commit 1fc4c92

Browse files
committed
refactor(guess-the-word): use better supported method to remove children elements
1 parent 69d1d96 commit 1fc4c92

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

vanilla/guess-the-word/src/events/handlers/difficulty-complete.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ export function handleDifficultyComplete() {
3333
import("@/ui/insane-countdown-bar").then(({ hideInsaneCountdown }) =>
3434
hideInsaneCountdown(),
3535
);
36-
// TODO: use a while loop
37-
$typing.replaceChildren();
36+
while ($typing.firstChild != null) $typing.removeChild($typing.firstChild);
3837
$typing.classList.add(CLASSES.HIDDEN);
3938

4039
showCompletedDifficultyMessage(difficulty, { allCompleted: gameCompleted });
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { $allHintsList, $correctHintsList } from "./elements";
22

33
export const clearHints = () => {
4-
// TODO: use a while loop
5-
$allHintsList.replaceChildren();
6-
$correctHintsList.replaceChildren();
4+
while ($allHintsList.firstChild != null)
5+
$allHintsList.removeChild($allHintsList.firstChild);
6+
while ($correctHintsList.firstChild != null)
7+
$correctHintsList.removeChild($correctHintsList.firstChild);
78
};

vanilla/guess-the-word/src/ui/typing/letter-fields.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ const $letterFields = [];
1212
/** @param {number} quantity */
1313
export function createLetterFields(quantity) {
1414
$letterFields.length = 0;
15-
// TODO: use a while loop
16-
$typing.replaceChildren();
15+
while ($typing.firstChild != null) $typing.removeChild($typing.firstChild);
1716

1817
for (let idx = 0; idx < quantity; idx++) {
1918
const $letterClone = /** @type {DocumentFragment} */ (

vanilla/guess-the-word/src/ui/word.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ const lettersToUse = [""];
1515

1616
/** @param {string} word */
1717
export const createWordLetters = (word) => {
18-
// TODO: use a while loop
19-
$word.replaceChildren();
18+
while ($word.firstChild != null) $word.removeChild($word.firstChild);
2019
$wordLetters.length = 0;
2120
lettersToUse.length = 0;
2221

0 commit comments

Comments
 (0)