@@ -2,6 +2,7 @@ import { Snapshot, FiberRoot } from '../types/backendTypes';
2
2
import componentActionsRecord from '../models/masterState' ;
3
3
import routes from '../models/routes' ;
4
4
import createTree from '../controllers/createTree' ;
5
+ const _ = require ( 'lodash' ) ;
5
6
6
7
// -------------------------UPDATE & SEND TREE SNAP SHOT------------------------
7
8
/**
@@ -13,6 +14,42 @@ import createTree from '../controllers/createTree';
13
14
*/
14
15
// updating tree depending on current mode on the panel (pause, etc)
15
16
export default function updateAndSendSnapShotTree ( fiberRoot : FiberRoot ) : void {
17
+
18
+ // This function compares trees with one another
19
+ function isIdentical ( tree1 , tree2 ) {
20
+ // Check if both are null
21
+ if ( ! tree1 && ! tree2 ) return true ;
22
+
23
+ // Check if either of them is null
24
+ if ( ! tree1 || ! tree2 ) return false ;
25
+
26
+ // Get the keys
27
+ const tree1Keys = Object . keys ( tree1 ) ;
28
+ const tree2Keys = Object . keys ( tree2 ) ;
29
+
30
+ // Check if length of keys is different
31
+ if ( tree1Keys . length !== tree2Keys . length ) return false ;
32
+
33
+ // Check keys and values
34
+ for ( let key of tree1Keys ) {
35
+ const val1 = tree1 [ key ] ;
36
+ const val2 = tree2 [ key ] ;
37
+
38
+ const areObjects = isObject ( val1 ) && isObject ( val2 ) ;
39
+ if (
40
+ ( areObjects && ! isIdentical ( val1 , val2 ) ) ||
41
+ ( ! areObjects && val1 !== val2 )
42
+ ) {
43
+ return false ;
44
+ }
45
+ }
46
+ return true ;
47
+ }
48
+
49
+ function isObject ( object ) {
50
+ return object != null && typeof object === 'object' ;
51
+ }
52
+
16
53
// This is the currently active root fiber(the mutable root of the tree)
17
54
const { current } = fiberRoot ;
18
55
// Clear all of the legacy actions from old fiber tree because we are about to create a new one
@@ -29,7 +66,16 @@ export default function updateAndSendSnapShotTree(fiberRoot: FiberRoot): void {
29
66
// the postMessage action will be received on the content script to later update the tabsObj
30
67
// this will fire off everytime there is a change in test application
31
68
// convert the payload from a fiber tree to an object to avoid a data clone error when postMessage processes the argument
69
+ console . log ( 'This is the payload, baby: ' , payload ) ;
70
+ const clonedDeepPayload = _ . cloneDeep ( payload ) ;
71
+ console . log ( 'cloneDeepPayload tree' , clonedDeepPayload ) ;
72
+ // compare payload and clonedDeepPayload with isIdentical
73
+ // console.log('are they identical?', isIdentical(payload, clonedDeepPayload));
74
+ // console.log('typeof payload', typeof payload);
32
75
const obj = JSON . parse ( JSON . stringify ( payload ) ) ;
76
+ // console.log('righton, this is the obj: ', obj)
77
+ // console.log('typeof obj', typeof obj);
78
+ console . log ( 'passing in obj' ) ;
33
79
window . postMessage (
34
80
{
35
81
action : 'recordSnap' ,
0 commit comments