Skip to content

Commit

Permalink
Refactor LineAccumulator (#501)
Browse files Browse the repository at this point in the history
* move isInLineGroup to class scope

* move showMeter to class scope

* use showMeter class attribute

* move showIpa to class scope
  • Loading branch information
fsimonjetz authored Jul 31, 2024
1 parent fbecfb1 commit a45b08f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 25 deletions.
5 changes: 1 addition & 4 deletions src/transliteration/domain/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ export function lineAccFromColumns({
acc.addColumnToken(
token,
index,
isInLineGroup,
showMeter,
showIpa,
updatePhoneticPropsContext(column.content, index, phoneticProps),
_.isEmpty(_.intersection(token.uniqueLemma, highlightLemmas))
? []
Expand All @@ -72,7 +69,7 @@ export function lineAccFromColumns({
acc
)
return acc
}, new LineAccumulator())
}, new LineAccumulator(isInLineGroup, showMeter, showIpa))
}

export function numberOfColumns(columns: readonly TextLineColumn[]): number {
Expand Down
31 changes: 13 additions & 18 deletions src/transliteration/ui/LineAccumulator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,17 @@ export class LineAccumulator {
private enclosureOpened = false
private protocol: Protocol | null = null
private isFirstWord = true
private isInLineGroup = false
private showMeter = false
private showIpa = false
lemmas: string[] = []

constructor(isInLineGroup?: boolean, showMeter?: boolean, showIpa?: boolean) {
this.isInLineGroup = isInLineGroup || false
this.showMeter = showMeter || false
this.showIpa = showIpa || false
}

getColumns(maxColumns: number): React.ReactNode[] {
return this.columns.map((column: ColumnData, index: number) => (
<td key={index} colSpan={column.span ?? maxColumns}>
Expand Down Expand Up @@ -87,9 +96,6 @@ export class LineAccumulator {
pushToken(
token: Token,
index: number,
isInLineGroup = false,
showMeter = false,
showIpa = false,
phoneticProps?: PhoneticProps,
bemModifiers: string[] = []
): void {
Expand All @@ -100,7 +106,7 @@ export class LineAccumulator {
this.pushSeparator()
}

const DisplayTokenComponent = isInLineGroup
const DisplayTokenComponent = this.isInLineGroup
? DisplayLineGroupToken
: DisplayToken

Expand All @@ -110,8 +116,8 @@ export class LineAccumulator {
token={token}
bemModifiers={[...this.bemModifiers, ...bemModifiers]}
Wrapper={this.inGloss && !isEnclosure(token) ? GlossWrapper : undefined}
showMeter={showMeter}
showIpa={showIpa}
showMeter={this.showMeter}
showIpa={this.showIpa}
phoneticProps={phoneticProps}
/>
)
Expand Down Expand Up @@ -139,9 +145,6 @@ export class LineAccumulator {
addColumnToken(
token: Token,
index: number,
isInLineGroup?: boolean,
showMeter?: boolean,
showIpa?: boolean,
phoneticProps?: PhoneticProps,
bemModifiers: string[] = []
): void {
Expand All @@ -158,15 +161,7 @@ export class LineAccumulator {
case 'Column':
throw new Error('Unexpected column token.')
default:
this.pushToken(
token,
index,
isInLineGroup,
showMeter,
showIpa,
phoneticProps,
bemModifiers
)
this.pushToken(token, index, phoneticProps, bemModifiers)
this.pushLemma(token.uniqueLemma)
this.isFirstWord = false
}
Expand Down
3 changes: 0 additions & 3 deletions src/transliteration/ui/line-tokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ export function LineTokens({
acc.addColumnToken(
token,
index,
false,
false,
false,
{},
highlightTokens.includes(index) ? ['highlight'] : []
)
Expand Down

0 comments on commit a45b08f

Please sign in to comment.