Skip to content

Commit

Permalink
Revert "refactoring attempt"
Browse files Browse the repository at this point in the history
This reverts commit 45b11f9.
  • Loading branch information
davidfan168 authored and Aeolun committed May 23, 2024
1 parent de957c3 commit 6a9789b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 34 deletions.
55 changes: 22 additions & 33 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,28 @@ class DiffViewer extends React.Component<
};
};

private calculateColSpans = (hideLineNumbers : boolean) => {
public render = (): ReactElement => {
const {
oldValue,
newValue,
useDarkTheme,
leftTitle,
rightTitle,
splitView,
compareMethod,
hideLineNumbers,
nonce,
} = this.props;

if (typeof(compareMethod) === 'string' && compareMethod !== DiffMethod.JSON) {
if (typeof oldValue !== 'string' || typeof newValue !== 'string') {
throw Error('"oldValue" and "newValue" should be strings');
}
}

this.styles = this.computeStyles(this.props.styles, useDarkTheme, nonce);
const nodes = this.renderDiff();

let colSpanOnSplitView = 3;
let colSpanOnInlineView = 4;

Expand All @@ -603,10 +624,6 @@ class DiffViewer extends React.Component<
colSpanOnInlineView += 1;
}

return [colSpanOnSplitView, colSpanOnInlineView]
}

private calculateChanges = (nodes) => {
let deletions = 0, additions = 0
nodes.lineInformation.forEach((l) => {
if (l.left.type === DiffType.ADDED) {
Expand All @@ -622,34 +639,6 @@ class DiffViewer extends React.Component<
deletions++
}
})
return [deletions, additions]
}

public render = (): ReactElement => {
const {
oldValue,
newValue,
useDarkTheme,
leftTitle,
rightTitle,
splitView,
compareMethod,
hideLineNumbers,
nonce,
} = this.props;

if (typeof(compareMethod) === 'string' && compareMethod !== DiffMethod.JSON) {
if (typeof oldValue !== 'string' || typeof newValue !== 'string') {
throw Error('"oldValue" and "newValue" should be strings');
}
}

this.styles = this.computeStyles(this.props.styles, useDarkTheme, nonce);
const nodes = this.renderDiff();

const [colSpanOnSplitView, colSpanOnInlineView] = this.calculateColSpans(hideLineNumbers)

const [deletions, additions] = this.calculateChanges(nodes)
const totalChanges = deletions + additions

const percentageAddition = Math.round((additions / totalChanges) * 100)
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"experimentalDecorators": true,
"jsx": "react-jsx",
"module": "commonjs",
"strict": true,
"moduleResolution": "node",
"noImplicitAny": true,
"esModuleInterop": true,
Expand Down

0 comments on commit 6a9789b

Please sign in to comment.