Skip to content

Commit 396d710

Browse files
committed
Full TS implementation for Diff.tsx
1 parent d37bcbc commit 396d710

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/app/components/Diff.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ import React from 'react';
22
import { diff, formatters } from 'jsondiffpatch';
33
import ReactHtmlParser from 'react-html-parser';
44
import { useStoreContext } from '../store';
5-
import { DiffProps } from '../components/FrontendTypes';
5+
import { DiffProps, StatelessCleanning } from '../components/FrontendTypes';
66

77
/**
88
* Displays tree showing specific two versions of tree
99
* one with specific state changes, the other the whole tree
1010
* @param props props from maincontainer
1111
* @returns a diff tree or a string stating no state changes have happened
1212
*/
13-
function Diff(props: DiffProps) {
13+
function Diff(props: DiffProps): JSX.Element {
1414
const { snapshot, show } = props;
1515
const [mainState] = useStoreContext();
1616
const { currentTab, tabs } = mainState; // k/v pairs of mainstate store object being created
1717
const { snapshots, viewIndex, sliderIndex } = tabs[currentTab];
18-
let previous;
18+
let previous:unknown;
1919

2020
// previous follows viewIndex or sliderIndex
2121
if (viewIndex !== -1) {
@@ -26,13 +26,7 @@ function Diff(props: DiffProps) {
2626
}
2727

2828
// cleaning preview from stateless data
29-
const statelessCleanning = (obj: {
30-
name?: string;
31-
componentData?: Record<string, unknown>;
32-
state?: string | any;
33-
stateSnaphot?: Record<string, unknown>;
34-
children?: any[];
35-
}) => {
29+
const statelessCleanning = (obj: StatelessCleanning) => {
3630
const newObj = { ...obj };
3731
if (newObj.name === 'nameless') {
3832
delete newObj.name;
@@ -63,13 +57,13 @@ function Diff(props: DiffProps) {
6357
};
6458

6559
// displays stateful data
66-
const previousDisplay = statelessCleanning(previous);
60+
const previousDisplay: StatelessCleanning = statelessCleanning(previous);
6761
// diff function returns a comparison of two objects, one has an updated change
6862
// just displays stateful data
69-
const delta = diff(previousDisplay, snapshot);
63+
const delta: StatelessCleanning = diff(previousDisplay, snapshot);
7064
// returns html in string
7165
// just displays stateful data
72-
const html = formatters.html.format(delta, previousDisplay);
66+
const html: StatelessCleanning = formatters.html.format(delta, previousDisplay);
7367
if (show) formatters.html.showUnchanged();
7468
else formatters.html.hideUnchanged();
7569

0 commit comments

Comments
 (0)