@@ -2,20 +2,20 @@ import React from 'react';
2
2
import { diff , formatters } from 'jsondiffpatch' ;
3
3
import ReactHtmlParser from 'react-html-parser' ;
4
4
import { useStoreContext } from '../store' ;
5
- import { DiffProps } from '../components/FrontendTypes' ;
5
+ import { DiffProps , StatelessCleanning } from '../components/FrontendTypes' ;
6
6
7
7
/**
8
8
* Displays tree showing specific two versions of tree
9
9
* one with specific state changes, the other the whole tree
10
10
* @param props props from maincontainer
11
11
* @returns a diff tree or a string stating no state changes have happened
12
12
*/
13
- function Diff ( props : DiffProps ) {
13
+ function Diff ( props : DiffProps ) : JSX . Element {
14
14
const { snapshot, show } = props ;
15
15
const [ mainState ] = useStoreContext ( ) ;
16
16
const { currentTab, tabs } = mainState ; // k/v pairs of mainstate store object being created
17
17
const { snapshots, viewIndex, sliderIndex } = tabs [ currentTab ] ;
18
- let previous ;
18
+ let previous : unknown ;
19
19
20
20
// previous follows viewIndex or sliderIndex
21
21
if ( viewIndex !== - 1 ) {
@@ -26,13 +26,7 @@ function Diff(props: DiffProps) {
26
26
}
27
27
28
28
// 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 ) => {
36
30
const newObj = { ...obj } ;
37
31
if ( newObj . name === 'nameless' ) {
38
32
delete newObj . name ;
@@ -63,13 +57,13 @@ function Diff(props: DiffProps) {
63
57
} ;
64
58
65
59
// displays stateful data
66
- const previousDisplay = statelessCleanning ( previous ) ;
60
+ const previousDisplay : StatelessCleanning = statelessCleanning ( previous ) ;
67
61
// diff function returns a comparison of two objects, one has an updated change
68
62
// just displays stateful data
69
- const delta = diff ( previousDisplay , snapshot ) ;
63
+ const delta : StatelessCleanning = diff ( previousDisplay , snapshot ) ;
70
64
// returns html in string
71
65
// just displays stateful data
72
- const html = formatters . html . format ( delta , previousDisplay ) ;
66
+ const html : StatelessCleanning = formatters . html . format ( delta , previousDisplay ) ;
73
67
if ( show ) formatters . html . showUnchanged ( ) ;
74
68
else formatters . html . hideUnchanged ( ) ;
75
69
0 commit comments