mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-29 18:27:33 +08:00
refactor: extract code so that it can be used in other places
This commit is contained in:
parent
2e78d9f066
commit
eab8eefd4b
1 changed files with 16 additions and 10 deletions
|
|
@ -508,16 +508,8 @@ export async function init(): Promise<void> {
|
|||
);
|
||||
}
|
||||
|
||||
//add word during the test
|
||||
export async function addWord(): Promise<void> {
|
||||
let bound = 100; // how many extra words to aim for AFTER the current word
|
||||
const funboxToPush = FunboxList.get(Config.funbox)
|
||||
.find((f) => f.properties?.find((fp) => fp.startsWith("toPush")))
|
||||
?.properties?.find((fp) => fp.startsWith("toPush:"));
|
||||
const toPushCount = funboxToPush?.split(":")[1];
|
||||
if (toPushCount !== undefined) bound = +toPushCount - 1;
|
||||
if (
|
||||
TestWords.words.length - TestInput.input.history.length > bound ||
|
||||
export function areAllTestWordsGenerated(): boolean {
|
||||
return (
|
||||
(Config.mode === "words" &&
|
||||
TestWords.words.length >= Config.words &&
|
||||
Config.words > 0) ||
|
||||
|
|
@ -533,6 +525,20 @@ export async function addWord(): Promise<void> {
|
|||
WordsGenerator.sectionIndex >= CustomText.getLimitValue() &&
|
||||
WordsGenerator.currentSection.length === 0 &&
|
||||
CustomText.getLimitValue() !== 0)
|
||||
);
|
||||
}
|
||||
|
||||
//add word during the test
|
||||
export async function addWord(): Promise<void> {
|
||||
let bound = 100; // how many extra words to aim for AFTER the current word
|
||||
const funboxToPush = FunboxList.get(Config.funbox)
|
||||
.find((f) => f.properties?.find((fp) => fp.startsWith("toPush")))
|
||||
?.properties?.find((fp) => fp.startsWith("toPush:"));
|
||||
const toPushCount = funboxToPush?.split(":")[1];
|
||||
if (toPushCount !== undefined) bound = +toPushCount - 1;
|
||||
if (
|
||||
TestWords.words.length - TestInput.input.history.length > bound ||
|
||||
areAllTestWordsGenerated()
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue