Skip to content

Commit 999cd5b

Browse files
committed
fixed timeJump and added helpers to save the state obj
1 parent c82a117 commit 999cd5b

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

package/linkFiber.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
// links component state tree to library
55
// changes the setState method to also update our snapshot
66
const Tree = require('./tree');
7-
const astParser = require('./astParser.js');
7+
const astParser = require('./astParser');
8+
const { saveState } = require('./masterState');
89

910
module.exports = (snap, mode) => {
1011
let fiberRoot = null;
11-
let astHooks;
12+
let astHooks;
1213

1314
function sendSnapshot() {
1415
// don't send messages while jumping or while paused
@@ -61,16 +62,16 @@ module.exports = (snap, mode) => {
6162
}
6263

6364
// Helper function to traverse through the memoized state
64-
// TODO: WE NEED TO CLEAN IT UP A BIT
6565
function traverseHooks(memoizedState) {
6666
// Declare variables and assigned to 0th index and an empty object, respectively
6767
const memoized = {};
6868
let index = 0;
6969
astHooks = Object.values(astHooks);
7070
// while memoizedState is truthy, save the value to the object
71-
while (memoizedState && astHooks) {
71+
while (memoizedState) {
7272
changeUseState(memoizedState);
73-
memoized[astHooks[index]] = memoizedState.memoizedState;
73+
//memoized[astHooks[index]] = memoizedState.memoizedState;
74+
memoized[astHooks[index]] = memoizedState.memoizedState;
7475
// Reassign memoizedState to its next value
7576
memoizedState = memoizedState.next;
7677
// Increment the index by 2
@@ -125,8 +126,11 @@ module.exports = (snap, mode) => {
125126
// only assign internal rootp if it actually exists
126127
fiberRoot = _internalRoot || _reactRootContainer;
127128
// If hooks are implemented, traverse through the source code
128-
if (entryFile) astHooks = astParser(entryFile);
129-
129+
// Save the getter/setter combo for timeJump
130+
if (entryFile) {
131+
astHooks = astParser(entryFile);
132+
saveState(astHooks);
133+
}
130134
updateSnapShotTree();
131135
// send the initial snapshot once the content script has started up
132136
window.addEventListener('message', ({ data: { action } }) => {

package/masterState.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Export two functions that either saves the AST state object into an array
2+
// or returns the array for use
3+
const masterState = [];
4+
5+
module.exports = {
6+
saveState: state => {
7+
for (const key in state) {
8+
masterState.push(state[key]);
9+
}
10+
},
11+
returnState: () => {
12+
return masterState;
13+
},
14+
};

package/timeJump.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* eslint-disable no-param-reassign */
22
// traverses given tree by accessing children through coords array
3+
const { saveState, returnState } = require('./masterState');
4+
35
function traverseTree(tree, coords) {
46
let curr = tree;
57
coords.forEach(coord => {
@@ -21,13 +23,16 @@ module.exports = (origin, mode) => {
2123
});
2224
});
2325
} else {
24-
// if component uses hooks
26+
// if component uses hooks, traverse through the memoize tree
2527
let current = originNode.component;
26-
let index = 1;
27-
// Iterate through the memoized tree
28+
let index = 0;
29+
const hooks = returnState();
30+
// while loop through the memoize tree
2831
while (current) {
29-
current.queue.dispatch(target.state[`state${index++}`]);
32+
current.queue.dispatch(target.state[hooks[index]]);
33+
// Reassign the current value
3034
current = current.next;
35+
index += 2;
3136
}
3237
}
3338
}

0 commit comments

Comments
 (0)