From 6a9789b0af0221bf32be11d1af9d4db3337008f4 Mon Sep 17 00:00:00 2001 From: davidfan168 Date: Fri, 3 May 2024 23:20:26 -0700 Subject: [PATCH] Revert "refactoring attempt" This reverts commit 45b11f996e1a527a9faf252eca731be96939d816. --- src/index.tsx | 55 +++++++++++++++++++++------------------------------ tsconfig.json | 1 - 2 files changed, 22 insertions(+), 34 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 9e70e64..90f8435 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -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; @@ -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) { @@ -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) diff --git a/tsconfig.json b/tsconfig.json index 2b6e19b..beaac22 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,6 @@ "experimentalDecorators": true, "jsx": "react-jsx", "module": "commonjs", - "strict": true, "moduleResolution": "node", "noImplicitAny": true, "esModuleInterop": true,