mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-05 13:27:49 +08:00
Merge pull request #646 from typerqeo/optimize
Optimize appending to the dom
This commit is contained in:
commit
c98565b202
2 changed files with 12 additions and 8 deletions
|
@ -2023,14 +2023,15 @@ function updateSuggestedCommands() {
|
|||
|
||||
function displayFoundCommands() {
|
||||
$("#commandLine .suggestions").empty();
|
||||
let commandsHTML = "";
|
||||
let list = currentCommands[currentCommands.length - 1];
|
||||
$.each(list.list, (index, obj) => {
|
||||
if (obj.found && (obj.available !== undefined ? obj.available() : true)) {
|
||||
$("#commandLine .suggestions").append(
|
||||
'<div class="entry" command="' + obj.id + '">' + obj.display + "</div>"
|
||||
);
|
||||
commandsHTML +=
|
||||
'<div class="entry" command="' + obj.id + '">' + obj.display + "</div>";
|
||||
}
|
||||
});
|
||||
$("#commandLine .suggestions").html(commandsHTML);
|
||||
if ($("#commandLine .suggestions .entry").length == 0) {
|
||||
$("#commandLine .separator").css({ height: 0, margin: 0 });
|
||||
} else {
|
||||
|
|
|
@ -857,14 +857,15 @@ function addWord() {
|
|||
function showWords() {
|
||||
$("#words").empty();
|
||||
|
||||
let wordsHTML = "";
|
||||
for (let i = 0; i < wordsList.length; i++) {
|
||||
let w = "<div class='word'>";
|
||||
wordsHTML += "<div class='word'>";
|
||||
for (let c = 0; c < wordsList[i].length; c++) {
|
||||
w += "<letter>" + wordsList[i].charAt(c) + "</letter>";
|
||||
wordsHTML += "<letter>" + wordsList[i].charAt(c) + "</letter>";
|
||||
}
|
||||
w += "</div>";
|
||||
$("#words").append(w);
|
||||
wordsHTML += "</div>";
|
||||
}
|
||||
$("#words").html(wordsHTML);
|
||||
|
||||
$("#wordsWrapper").removeClass("hidden");
|
||||
const wordHeight = $(document.querySelector(".word")).outerHeight(true);
|
||||
|
@ -3119,6 +3120,7 @@ function toggleResultWordsDisplay() {
|
|||
|
||||
async function loadWordsHistory() {
|
||||
$("#resultWordsHistory .words").empty();
|
||||
let wordsHTML = "";
|
||||
for (let i = 0; i < inputHistory.length + 2; i++) {
|
||||
let input = inputHistory[i];
|
||||
let wordEl = "";
|
||||
|
@ -3229,8 +3231,9 @@ async function loadWordsHistory() {
|
|||
wordEl += "</div>";
|
||||
} catch (e) {}
|
||||
}
|
||||
$("#resultWordsHistory .words").append(wordEl);
|
||||
wordsHTML += wordEl;
|
||||
}
|
||||
$("#resultWordsHistory .words").html(wordsHTML);
|
||||
$("#showWordHistoryButton").addClass("loaded");
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue