Skip to content

Commit 9a5c5fe

Browse files
committed
Remove higher order function
1 parent d402d90 commit 9a5c5fe

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

src/lang.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,20 @@ export function getMatchLabel(matchNumber: number, roundNumber: number, roundCou
6262
return matchLabel;
6363
}
6464

65-
// TODO: refactor this, grandFinalName isn't always used... no need to pass it in the first place...
66-
6765
/**
6866
* Returns the label of a match in final.
6967
*
7068
* @param finalType Type of the final.
71-
* @param grandFinalName Name of the final.
7269
* @param roundNumber Number of the round.
70+
* @param roundCount Count of rounds.
7371
*/
74-
export function getFinalMatchLabel(finalType: FinalType, grandFinalName: (roundNumber: number) => string, roundNumber: number): string {
75-
return finalType === 'consolation_final' ? 'Consolation Final' : grandFinalName(roundNumber);
72+
export function getFinalMatchLabel(finalType: FinalType, roundNumber: number, roundCount: number): string {
73+
// Single elimination.
74+
if (finalType === 'consolation_final')
75+
return 'Consolation Final';
76+
77+
// Double elimination.
78+
return getGrandFinalName(roundNumber, roundCount);
7679
}
7780

7881
/**
@@ -110,12 +113,16 @@ export function getMatchStatus(status: Status): string {
110113
}
111114

112115
/**
113-
* Returns the name of a grand final phase.
116+
* Returns the name of a grand final round.
114117
*
118+
* @param roundNumber Number of the round.
115119
* @param roundCount Count of final rounds.
116120
*/
117-
export function getGrandFinalName(roundCount: number): (roundNumber: number) => string {
118-
return roundCount === 1 ? () => 'Grand Final' : (roundNumber: number) => `GF Round ${roundNumber}`;
121+
export function getGrandFinalName(roundNumber: number, roundCount: number): string {
122+
if (roundCount === 1)
123+
return 'Grand Final';
124+
125+
return `GF Round ${roundNumber}`;
119126
}
120127

121128
/**

src/main.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,16 @@ export class BracketsViewer {
165165
const upperBracket = document.querySelector('.bracket');
166166
if (!upperBracket) throw Error('Upper bracket not found.');
167167

168-
const grandFinalName = lang.getGrandFinalName(matches.length);
169-
170168
const winnerWb = matches[0].opponent1;
171169
const finalsToDisplay = (winnerWb && winnerWb.id != null && winnerWb.result != "win") ? 2 : 1;
172-
173170
const finalMatches = matches.slice(0, finalsToDisplay);
174171

172+
const roundCount = matches.length;
173+
175174
for (let i = 0; i < finalMatches.length; i++) {
176175
const roundNumber = i + 1;
177-
const roundContainer = dom.createRoundContainer(lang.getFinalMatchLabel(finalType, grandFinalName, roundNumber));
178-
roundContainer.append(this.createFinalMatch(finalType, grandFinalName, finalMatches, roundNumber));
176+
const roundContainer = dom.createRoundContainer(lang.getFinalMatchLabel(finalType, roundNumber, roundCount));
177+
roundContainer.append(this.createFinalMatch(finalType, finalMatches, roundNumber, roundCount));
179178
upperBracket.append(roundContainer);
180179
}
181180
}
@@ -245,14 +244,14 @@ export class BracketsViewer {
245244
* Creates a match in a final.
246245
*
247246
* @param type Type of the final.
248-
* @param grandFinalName A function giving a grand final phase's name based on the round number.
249247
* @param matches Matches of the final.
250248
* @param roundNumber Number of the round.
249+
* @param roundCount Count of rounds.
251250
*/
252-
private createFinalMatch(type: FinalType, grandFinalName: (roundNumber: number) => string, matches: Match[], roundNumber: number): HTMLElement {
251+
private createFinalMatch(type: FinalType, matches: Match[], roundNumber: number, roundCount: number): HTMLElement {
253252
const roundIndex = roundNumber - 1;
254253
const connection = dom.getFinalConnection(type, roundNumber, matches.length);
255-
const matchLabel = lang.getFinalMatchLabel(type, grandFinalName, roundNumber);
254+
const matchLabel = lang.getFinalMatchLabel(type, roundNumber, roundCount);
256255
const matchHint = lang.getFinalMatchHint(type, roundNumber);
257256
return this.createMatch(matches[roundIndex], connection, matchLabel, matchHint);
258257
}
@@ -319,6 +318,7 @@ export class BracketsViewer {
319318
/**
320319
* Renders a participant.
321320
*
321+
* @param teamContainer The team container.
322322
* @param nameContainer The name container.
323323
* @param resultContainer The result container.
324324
* @param team The participant result.

0 commit comments

Comments
 (0)