Skip to content

Commit 7edbd95

Browse files
authored
fix: remove function getFunctionsFromActiveFunboxes because it does not work (@fehmer) (monkeytypegame#6288)
1 parent 4aec384 commit 7edbd95

File tree

8 files changed

+37
-60
lines changed

8 files changed

+37
-60
lines changed

frontend/src/ts/controllers/account-controller.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import { navigate } from "./route-controller";
4848
import { FirebaseError } from "firebase/app";
4949
import * as PSA from "../elements/psa";
5050
import defaultResultFilters from "../constants/default-result-filters";
51-
import { getFunctionsFromActiveFunboxes } from "../test/funbox/list";
51+
import { getActiveFunboxesWithFunction } from "../test/funbox/list";
5252

5353
export const gmailProvider = new GoogleAuthProvider();
5454
export const githubProvider = new GithubAuthProvider();
@@ -174,10 +174,8 @@ async function getDataAndInit(): Promise<boolean> {
174174
UpdateConfig.saveFullConfigToLocalStorage(true);
175175

176176
//funboxes might be different and they wont activate on the account page
177-
for (const applyGlobalCSS of getFunctionsFromActiveFunboxes(
178-
"applyGlobalCSS"
179-
)) {
180-
applyGlobalCSS();
177+
for (const fb of getActiveFunboxesWithFunction("applyGlobalCSS")) {
178+
fb.functions.applyGlobalCSS();
181179
}
182180
}
183181
AccountButton.loading(false);

frontend/src/ts/controllers/input-controller.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import * as Loader from "../elements/loader";
3737
import * as KeyConverter from "../utils/key-converter";
3838
import {
3939
findSingleActiveFunboxWithFunction,
40-
getFunctionsFromActiveFunboxes,
40+
getActiveFunboxesWithFunction,
4141
isFunboxActiveWithProperty,
4242
} from "../test/funbox/list";
4343

@@ -198,8 +198,8 @@ async function handleSpace(): Promise<void> {
198198

199199
const currentWord: string = TestWords.words.getCurrent();
200200

201-
for (const handleSpace of getFunctionsFromActiveFunboxes("handleSpace")) {
202-
handleSpace();
201+
for (const fb of getActiveFunboxesWithFunction("handleSpace")) {
202+
fb.functions.handleSpace();
203203
}
204204

205205
dontInsertSpace = true;
@@ -494,8 +494,8 @@ function handleChar(
494494

495495
const isCharKorean: boolean = TestInput.input.getKoreanStatus();
496496

497-
for (const handleChar of getFunctionsFromActiveFunboxes("handleChar")) {
498-
char = handleChar(char);
497+
for (const fb of getActiveFunboxesWithFunction("handleChar")) {
498+
char = fb.functions.handleChar(char);
499499
}
500500

501501
const nospace = isFunboxActiveWithProperty("nospace");
@@ -902,8 +902,8 @@ $(document).on("keydown", async (event) => {
902902
return;
903903
}
904904

905-
for (const handleKeydown of getFunctionsFromActiveFunboxes("handleKeydown")) {
906-
void handleKeydown(event);
905+
for (const fb of getActiveFunboxesWithFunction("handleKeydown")) {
906+
void fb.functions.handleKeydown(event);
907907
}
908908

909909
//autofocus
@@ -1153,11 +1153,9 @@ $(document).on("keydown", async (event) => {
11531153
}
11541154
}
11551155

1156-
for (const preventDefaultEvent of getFunctionsFromActiveFunboxes(
1157-
"preventDefaultEvent"
1158-
)) {
1156+
for (const fb of getActiveFunboxesWithFunction("preventDefaultEvent")) {
11591157
if (
1160-
await preventDefaultEvent(
1158+
await fb.functions.preventDefaultEvent(
11611159
//i cant figure this type out, but it works fine
11621160
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
11631161
event as JQuery.KeyDownEvent

frontend/src/ts/ready.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as AccountButton from "./elements/account-button";
77
//@ts-expect-error
88
import Konami from "konami";
99
import * as ServerConfiguration from "./ape/server-configuration";
10-
import { getFunctionsFromActiveFunboxes } from "./test/funbox/list";
10+
import { getActiveFunboxesWithFunction } from "./test/funbox/list";
1111
import { loadPromise } from "./config";
1212

1313
$(async (): Promise<void> => {
@@ -19,10 +19,8 @@ $(async (): Promise<void> => {
1919
$("body").css("transition", "background .25s, transform .05s");
2020
MerchBanner.showIfNotClosedBefore();
2121

22-
for (const applyGlobalCSS of getFunctionsFromActiveFunboxes(
23-
"applyGlobalCSS"
24-
)) {
25-
applyGlobalCSS();
22+
for (const fb of getActiveFunboxesWithFunction("applyGlobalCSS")) {
23+
fb.functions.applyGlobalCSS();
2624
}
2725

2826
$("#app")

frontend/src/ts/test/funbox/funbox.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
getActiveFunboxes,
1414
getActiveFunboxNames,
1515
get,
16-
getFunctionsFromActiveFunboxes,
16+
getActiveFunboxesWithFunction,
1717
isFunboxActiveWithProperty,
1818
getActiveFunboxesWithProperty,
1919
} from "./list";
@@ -22,15 +22,15 @@ import { checkForcedConfig } from "./funbox-validation";
2222
export function toggleScript(...params: string[]): void {
2323
if (Config.funbox === "none") return;
2424

25-
for (const toggleScript of getFunctionsFromActiveFunboxes("toggleScript")) {
26-
toggleScript(params);
25+
for (const fb of getActiveFunboxesWithFunction("toggleScript")) {
26+
fb.functions.toggleScript(params);
2727
}
2828
}
2929

3030
export function setFunbox(funbox: string): boolean {
3131
if (funbox === "none") {
32-
for (const clearGlobal of getFunctionsFromActiveFunboxes("clearGlobal")) {
33-
clearGlobal();
32+
for (const fb of getActiveFunboxesWithFunction("clearGlobal")) {
33+
fb.functions.clearGlobal();
3434
}
3535
}
3636
FunboxMemory.load();
@@ -199,18 +199,16 @@ export async function activate(funbox?: string): Promise<boolean | undefined> {
199199
}
200200

201201
ManualRestart.set();
202-
for (const applyConfig of getFunctionsFromActiveFunboxes("applyConfig")) {
203-
applyConfig();
202+
for (const fb of getActiveFunboxesWithFunction("applyConfig")) {
203+
fb.functions.applyConfig();
204204
}
205205
// ModesNotice.update();
206206
return true;
207207
}
208208

209209
export async function rememberSettings(): Promise<void> {
210-
for (const rememberSettings of getFunctionsFromActiveFunboxes(
211-
"rememberSettings"
212-
)) {
213-
rememberSettings();
210+
for (const fb of getActiveFunboxesWithFunction("rememberSettings")) {
211+
fb.functions.rememberSettings();
214212
}
215213
}
216214

frontend/src/ts/test/funbox/list.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,6 @@ export function getActiveFunboxesWithFunction<F extends keyof FunboxFunctions>(
118118
) as FunboxWithFunction<F>[];
119119
}
120120

121-
/**
122-
* Get requested, implemented functions from all active funboxes
123-
* @param functionName name of the function
124-
* @returns array of each implemented requested function of all active funboxes
125-
*/
126-
export function getFunctionsFromActiveFunboxes<F extends keyof FunboxFunctions>(
127-
functionName: F
128-
): MandatoryFunboxFunction<F>[] {
129-
return getActiveFunboxesWithFunction(functionName).map(
130-
(it) => it.functions[functionName]
131-
);
132-
}
133-
134121
/**
135122
* Check if there is an active funbox implemenging the given function
136123
* @param functionName function name

frontend/src/ts/test/test-logic.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ import * as XPBar from "../elements/xp-bar";
6767
import {
6868
findSingleActiveFunboxWithFunction,
6969
getActiveFunboxes,
70-
getFunctionsFromActiveFunboxes,
70+
getActiveFunboxesWithFunction,
7171
} from "./funbox/list";
7272
import { getFunboxesFromString } from "@monkeytype/funbox";
7373
import * as CompositionState from "../states/composition";
@@ -112,8 +112,8 @@ export function startTest(now: number): boolean {
112112
TestTimer.clear();
113113
Monkey.show();
114114

115-
for (const start of getFunctionsFromActiveFunboxes("start")) {
116-
start();
115+
for (const fb of getActiveFunboxesWithFunction("start")) {
116+
fb.functions.start();
117117
}
118118

119119
try {
@@ -335,8 +335,8 @@ export function restart(options = {} as RestartOptions): void {
335335
await init();
336336
await PaceCaret.init();
337337

338-
for (const restart of getFunctionsFromActiveFunboxes("restart")) {
339-
restart();
338+
for (const fb of getActiveFunboxesWithFunction("restart")) {
339+
fb.functions.restart();
340340
}
341341

342342
if (Config.showAverage !== "off") {

frontend/src/ts/test/test-ui.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
import { convertRemToPixels } from "../utils/numbers";
3333
import {
3434
findSingleActiveFunboxWithFunction,
35-
getFunctionsFromActiveFunboxes,
35+
getActiveFunboxesWithFunction,
3636
} from "./funbox/list";
3737
import * as TestState from "./test-state";
3838

@@ -656,10 +656,8 @@ export async function screenshot(): Promise<void> {
656656
}
657657
(document.querySelector("html") as HTMLElement).style.scrollBehavior =
658658
"smooth";
659-
for (const applyGlobalCSS of getFunctionsFromActiveFunboxes(
660-
"applyGlobalCSS"
661-
)) {
662-
applyGlobalCSS();
659+
for (const fb of getActiveFunboxesWithFunction("applyGlobalCSS")) {
660+
fb.functions.applyGlobalCSS();
663661
}
664662
}
665663

@@ -700,8 +698,8 @@ export async function screenshot(): Promise<void> {
700698
$(".highlightContainer").addClass("hidden");
701699
if (revertCookie) $("#cookiesModal").addClass("hidden");
702700

703-
for (const clearGlobal of getFunctionsFromActiveFunboxes("clearGlobal")) {
704-
clearGlobal();
701+
for (const fb of getActiveFunboxesWithFunction("clearGlobal")) {
702+
fb.functions.clearGlobal();
705703
}
706704

707705
(document.querySelector("html") as HTMLElement).style.scrollBehavior = "auto";

frontend/src/ts/test/words-generator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { FunboxWordOrder, LanguageObject } from "../utils/json-data";
1919
import {
2020
findSingleActiveFunboxWithFunction,
2121
getActiveFunboxes,
22-
getFunctionsFromActiveFunboxes,
22+
getActiveFunboxesWithFunction,
2323
isFunboxActiveWithFunction,
2424
} from "./funbox/list";
2525

@@ -353,8 +353,8 @@ function applyFunboxesToWord(
353353
wordIndex: number,
354354
wordsBound: number
355355
): string {
356-
for (const alterText of getFunctionsFromActiveFunboxes("alterText")) {
357-
word = alterText(word, wordIndex, wordsBound);
356+
for (const fb of getActiveFunboxesWithFunction("alterText")) {
357+
word = fb.functions.alterText(word, wordIndex, wordsBound);
358358
}
359359
return word;
360360
}

0 commit comments

Comments
 (0)