Skip to content

Commit 8c7ee8b

Browse files
committed
refactor: make some input and corrected props private
also remove methods for public props
1 parent fd6bf18 commit 8c7ee8b

File tree

8 files changed

+38
-60
lines changed

8 files changed

+38
-60
lines changed

frontend/src/ts/commandline/lists/result-screen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ const commands: Command[] = [
112112
exec: (): void => {
113113
const words = (
114114
Config.mode === "zen"
115-
? TestInput.input.history
116-
: TestWords.words.list.slice(0, TestInput.input.history.length)
115+
? TestInput.input.getHistory()
116+
: TestWords.words.list.slice(0, TestInput.input.getHistory().length)
117117
).join(" ");
118118

119119
navigator.clipboard.writeText(words).then(

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ function backspaceToPrevious(): void {
115115
if (!TestState.isActive) return;
116116

117117
if (
118-
TestInput.input.history.length === 0 ||
118+
TestInput.input.getHistory().length === 0 ||
119119
TestUI.activeWordElementIndex === 0
120120
) {
121121
return;
122122
}
123123

124124
const wordElements = document.querySelectorAll("#words > .word");
125125
if (
126-
(TestInput.input.history[TestState.activeWordIndex - 1] ==
126+
(TestInput.input.getHistory(TestState.activeWordIndex - 1) ==
127127
TestWords.words.get(TestState.activeWordIndex - 1) &&
128128
!Config.freedomMode) ||
129129
wordElements[TestState.activeWordIndex - 1]?.classList.contains("hidden")
@@ -1061,7 +1061,7 @@ $(document).on("keydown", async (event) => {
10611061
TestInput.input.current.slice(-1),
10621062
TestInput.input.current.length - 1
10631063
) &&
1064-
(TestInput.input.history[TestState.activeWordIndex - 1] !=
1064+
(TestInput.input.getHistory(TestState.activeWordIndex - 1) !=
10651065
TestWords.words.get(TestState.activeWordIndex - 1) ||
10661066
Config.freedomMode)
10671067
) {

frontend/src/ts/test/funbox/funbox-functions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ async function readAheadHandleKeydown(
6363
event.key == "Backspace" &&
6464
!isCorrect &&
6565
(TestInput.input.current != "" ||
66-
TestInput.input.history[TestState.activeWordIndex - 1] !=
66+
TestInput.input.getHistory(TestState.activeWordIndex - 1) !=
6767
TestWords.words.get(TestState.activeWordIndex - 1) ||
6868
Config.freedomMode)
6969
) {
@@ -348,7 +348,7 @@ const list: Partial<Record<FunboxName, FunboxFunctions>> = {
348348
const outOf: number = TestWords.words.length;
349349
const wordsPerLayout = Math.floor(outOf / layouts.length);
350350
const index = Math.floor(
351-
(TestInput.input.history.length + 1) / wordsPerLayout
351+
(TestInput.input.getHistory().length + 1) / wordsPerLayout
352352
);
353353
const mod =
354354
wordsPerLayout - ((TestState.activeWordIndex + 1) % wordsPerLayout);

frontend/src/ts/test/test-input.ts

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ type ErrorHistoryObject = {
9696

9797
class Input {
9898
current: string;
99-
history: string[];
99+
private history: string[];
100100
koreanStatus: boolean;
101101
constructor() {
102102
this.current = "";
@@ -113,33 +113,17 @@ class Input {
113113
this.history = [];
114114
}
115115

116-
setCurrent(val: string): void {
117-
this.current = val;
118-
}
119-
120116
setKoreanStatus(val: boolean): void {
121117
this.koreanStatus = val;
122118
}
123119

124-
appendCurrent(val: string): void {
125-
this.current += val;
126-
}
127-
128-
resetCurrent(): void {
129-
this.current = "";
130-
}
131-
132-
getCurrent(): string {
133-
return this.current;
134-
}
135-
136120
getKoreanStatus(): boolean {
137121
return this.koreanStatus;
138122
}
139123

140124
pushHistory(): void {
141125
this.history.push(this.current);
142-
this.resetCurrent();
126+
this.current = "";
143127
}
144128

145129
popHistory(): string {
@@ -164,30 +148,15 @@ class Input {
164148

165149
class Corrected {
166150
current: string;
167-
history: string[];
151+
private history: string[];
168152
constructor() {
169153
this.current = "";
170154
this.history = [];
171155
}
172-
setCurrent(val: string): void {
173-
this.current = val;
174-
}
175-
176-
appendCurrent(val: string): void {
177-
this.current += val;
178-
}
179-
180-
resetCurrent(): void {
181-
this.current = "";
182-
}
183-
184-
resetHistory(): void {
185-
this.history = [];
186-
}
187156

188157
reset(): void {
189-
this.resetCurrent();
190-
this.resetHistory();
158+
this.history = [];
159+
this.current = "";
191160
}
192161

193162
getHistory(i: number): string | undefined {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ export async function init(): Promise<void> {
396396
TestState.setActiveWordIndex(0);
397397
TestUI.setActiveWordElementIndex(0);
398398
TestInput.input.resetHistory();
399-
TestInput.input.resetCurrent();
399+
TestInput.input.current = "";
400400

401401
let language;
402402
try {
@@ -550,7 +550,7 @@ export async function addWord(): Promise<void> {
550550
const toPushCount = funboxToPush?.split(":")[1];
551551
if (toPushCount !== undefined) bound = +toPushCount - 1;
552552

553-
if (TestWords.words.length - TestInput.input.history.length > bound) {
553+
if (TestWords.words.length - TestInput.input.getHistory().length > bound) {
554554
console.debug("Not adding word, enough words already");
555555
return;
556556
}
@@ -843,7 +843,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
843843
if (TestInput.input.current.length !== 0) {
844844
TestInput.input.pushHistory();
845845
TestInput.corrected.pushHistory();
846-
Replay.replayGetWordsList(TestInput.input.history);
846+
Replay.replayGetWordsList(TestInput.input.getHistory());
847847
}
848848

849849
TestInput.forceKeyup(now); //this ensures that the last keypress(es) are registered
@@ -1018,7 +1018,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
10181018
// Let's update the custom text progress
10191019
if (
10201020
TestState.bailedOut ||
1021-
TestInput.input.history.length < TestWords.words.length
1021+
TestInput.input.getHistory().length < TestWords.words.length
10221022
) {
10231023
// They bailed out
10241024

frontend/src/ts/test/test-stats.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ export function getStats(): unknown {
6666
accuracy: TestInput.accuracy,
6767
keypressTimings: TestInput.keypressTimings,
6868
keyOverlap: TestInput.keyOverlap,
69-
wordsHistory: TestWords.words.list.slice(0, TestInput.input.history.length),
70-
inputHistory: TestInput.input.history,
69+
wordsHistory: TestWords.words.list.slice(
70+
0,
71+
TestInput.input.getHistory().length
72+
),
73+
inputHistory: TestInput.input.getHistory(),
7174
};
7275

7376
try {
@@ -243,7 +246,7 @@ export function removeAfkData(): void {
243246
function getInputWords(): string[] {
244247
const containsKorean = TestInput.input.getKoreanStatus();
245248

246-
let inputWords = [...TestInput.input.history];
249+
let inputWords = [...TestInput.input.getHistory()];
247250

248251
if (TestState.isActive) {
249252
inputWords.push(TestInput.input.current);
@@ -260,7 +263,9 @@ function getTargetWords(): string[] {
260263
const containsKorean = TestInput.input.getKoreanStatus();
261264

262265
let targetWords = [
263-
...(Config.mode === "zen" ? TestInput.input.history : TestWords.words.list),
266+
...(Config.mode === "zen"
267+
? TestInput.input.getHistory()
268+
: TestWords.words.list),
264269
];
265270

266271
if (TestState.isActive) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ export function setLigatures(isEnabled: boolean): void {
11611161
async function loadWordsHistory(): Promise<boolean> {
11621162
$("#resultWordsHistory .words").empty();
11631163
let wordsHTML = "";
1164-
for (let i = 0; i < TestInput.input.history.length + 2; i++) {
1164+
for (let i = 0; i < TestInput.input.getHistory().length + 2; i++) {
11651165
const input = TestInput.input.getHistory(i);
11661166
const corrected = TestInput.corrected.getHistory(i);
11671167
const word = TestWords.words.get(i);
@@ -1544,11 +1544,11 @@ $(".pageTest").on("click", "#saveScreenshotButton", () => {
15441544
$(".pageTest #copyWordsListButton").on("click", async () => {
15451545
let words;
15461546
if (Config.mode === "zen") {
1547-
words = TestInput.input.history.join(" ");
1547+
words = TestInput.input.getHistory().join(" ");
15481548
} else {
15491549
words = TestWords.words
15501550
.get()
1551-
.slice(0, TestInput.input.history.length)
1551+
.slice(0, TestInput.input.getHistory().length)
15521552
.join(" ");
15531553
}
15541554
await copyToClipboard(words);
@@ -1557,7 +1557,7 @@ $(".pageTest #copyWordsListButton").on("click", async () => {
15571557
$(".pageTest #copyMissedWordsListButton").on("click", async () => {
15581558
let words;
15591559
if (Config.mode === "zen") {
1560-
words = TestInput.input.history.join(" ");
1560+
words = TestInput.input.getHistory().join(" ");
15611561
} else {
15621562
words = Object.keys(TestInput.missedWords ?? {}).join(" ");
15631563
}

frontend/src/ts/test/timer-progress.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function getCurrentCount(): number {
9494
1
9595
);
9696
} else {
97-
return TestInput.input.history.length;
97+
return TestInput.input.getHistory().length;
9898
}
9999
}
100100

@@ -163,7 +163,7 @@ export function update(): void {
163163
if (outof === 0) {
164164
if (timerNumberElement !== null) {
165165
timerNumberElement.innerHTML =
166-
"<div>" + `${TestInput.input.history.length}` + "</div>";
166+
"<div>" + `${TestInput.input.getHistory().length}` + "</div>";
167167
}
168168
} else {
169169
if (timerNumberElement !== null) {
@@ -174,7 +174,9 @@ export function update(): void {
174174
} else if (Config.timerStyle === "mini") {
175175
if (outof === 0) {
176176
if (miniTimerNumberElement !== null) {
177-
miniTimerNumberElement.innerHTML = `${TestInput.input.history.length}`;
177+
miniTimerNumberElement.innerHTML = `${
178+
TestInput.input.getHistory().length
179+
}`;
178180
}
179181
} else {
180182
if (miniTimerNumberElement !== null) {
@@ -186,11 +188,13 @@ export function update(): void {
186188
if (Config.timerStyle === "text") {
187189
if (timerNumberElement !== null) {
188190
timerNumberElement.innerHTML =
189-
"<div>" + `${TestInput.input.history.length}` + "</div>";
191+
"<div>" + `${TestInput.input.getHistory().length}` + "</div>";
190192
}
191193
} else {
192194
if (miniTimerNumberElement !== null) {
193-
miniTimerNumberElement.innerHTML = `${TestInput.input.history.length}`;
195+
miniTimerNumberElement.innerHTML = `${
196+
TestInput.input.getHistory().length
197+
}`;
194198
}
195199
}
196200
}

0 commit comments

Comments
 (0)