@@ -12,6 +12,7 @@ module.exports = (snap, mode) => {
12
12
// DEV: So that when we are jumping to an old snapshot it wouldn't think we want to create new snapshots
13
13
if ( mode . jumping || mode . paused ) return ;
14
14
const payload = snap . tree . getCopy ( ) ;
15
+ console . log ( payload ) ;
15
16
// console.log('payload', payload);
16
17
window . postMessage ( {
17
18
action : 'recordSnap' ,
@@ -46,31 +47,28 @@ module.exports = (snap, mode) => {
46
47
// Helper function to traverse through the memoized state
47
48
function traverseHooks ( memoizedState ) {
48
49
// Declare variables and assigned to 0th index and an empty object, respectively
49
- let index = 0 ;
50
- let memoizedObj = { } ;
51
- // while memoizedState is truthy, save the value to the object
52
- while ( memoizedState ) {
53
- memoizedObj [ index ] = memoizedState . memoizedState ;
54
- // Reassign memoizedState to its next value
55
- memoizedState = memoizedState . next ;
50
+ let index = 0 ;
51
+ const memoizedObj = { } ;
52
+ // while memoizedState is truthy, save the value to the object
53
+ while ( memoizedState ) {
56
54
// Increment the index by 1
57
- index += 1 ;
55
+ memoizedObj [ `useState${ index += 1 } ` ] = memoizedState . memoizedState ;
56
+ // Reassign memoizedState to its next value
57
+ memoizedState = memoizedState . next ;
58
58
}
59
- return memoizedObj ;
59
+ return memoizedObj ;
60
60
}
61
61
62
62
function createTree ( currentFiber , tree = new Tree ( 'root' ) ) {
63
63
if ( ! currentFiber ) return tree ;
64
64
// We have to figure out which properties to destructure from currentFiber
65
- // To support hooks and Context API
66
- const { sibling, stateNode, child, memoizedState } = currentFiber ;
67
- // TODO: Refactor the conditionals - think about the edge case where a stateful component might have a key called 'baseState' in the state
68
- if ( memoizedState && memoizedState . hasOwnProperty ( 'baseState' ) ) {
69
- // console.log('The hook element is:', currentFiber);
70
- // console.log('The memoizedState is: ', memoizedState);
71
- const result = traverseHooks ( memoizedState ) ;
72
- console . log ( 'This is the result of calling traverseHooks:' , result ) ;
73
- }
65
+ // To support hooks and Context API
66
+ const {
67
+ sibling,
68
+ stateNode,
69
+ child,
70
+ memoizedState,
71
+ } = currentFiber ;
74
72
75
73
let nextTree = tree ;
76
74
// check if stateful component
@@ -80,8 +78,16 @@ module.exports = (snap, mode) => {
80
78
// change setState functionality
81
79
changeSetState ( stateNode ) ;
82
80
}
83
- // Need to check if functional component AND uses hooks
84
-
81
+ // Check if the component uses hooks
82
+ // TODO: Refactor the conditionals - think about the edge case where a stateful
83
+ // component might have a key called 'baseState' in the state
84
+ if ( memoizedState && memoizedState . hasOwnProperty ( 'baseState' ) ) {
85
+ // console.log('The memoizedState is: ', memoizedState);
86
+ const result = traverseHooks ( memoizedState ) ;
87
+ console . log ( 'This is the result of calling traverseHooks:' , result ) ;
88
+ nextTree = tree . appendChild ( result ) ;
89
+ }
90
+
85
91
// iterate through siblings
86
92
createTree ( sibling , tree ) ;
87
93
// iterate through children
@@ -93,7 +99,7 @@ module.exports = (snap, mode) => {
93
99
function updateSnapShotTree ( ) {
94
100
// console.log('fiberRoot', fiberRoot);
95
101
const { current } = fiberRoot ;
96
- // console.log('current', current);
102
+ console . log ( 'current' , current ) ;
97
103
snap . tree = createTree ( current ) ;
98
104
}
99
105
0 commit comments