Skip to content

Commit 0e0afb5

Browse files
davidchai717nusanam
andcommitted
Merged from dev
Co-authored-by: Ruth Anam <[email protected]> Co-authored-by: David Chai <[email protected]>
2 parents bce154c + 42050d8 commit 0e0afb5

File tree

6 files changed

+74
-44
lines changed

6 files changed

+74
-44
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ coverage
88
src/extension/build.zip
99
src/extension/build.crx
1010
src/extension/build/key.pem
11+
package/__tests__

package/linkFiber.js

Lines changed: 19 additions & 12 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
@@ -45,14 +46,15 @@ module.exports = (snap, mode) => {
4546

4647
function changeUseState(component) {
4748
if (component.queue.dispatch.linkFiberChanged) return;
48-
// store the original dispatch function definition
49-
const oldDispatch = component.queue.dispatch.bind(component.queue);;
49+
// store the original dispatch function definition
50+
const oldDispatch = component.queue.dispatch.bind(component.queue);
5051
// redefine the dispatch function so we can inject our code
5152
component.queue.dispatch = (fiber, queue, action) => {
5253
// don't do anything if state is locked
5354
if (mode.locked && !mode.jumping) return;
54-
oldDispatch(fiber, queue, action);
55+
//oldDispatch(fiber, queue, action);
5556
setTimeout(() => {
57+
oldDispatch(fiber, queue, action);
5658
updateSnapShotTree();
5759
sendSnapshot();
5860
}, 100);
@@ -68,9 +70,10 @@ module.exports = (snap, mode) => {
6870
let index = 0;
6971
astHooks = Object.values(astHooks);
7072
// while memoizedState is truthy, save the value to the object
71-
while (memoizedState && astHooks) {
73+
while (memoizedState) {
7274
changeUseState(memoizedState);
73-
memoized[astHooks[index]] = memoizedState.memoizedState;
75+
//memoized[astHooks[index]] = memoizedState.memoizedState;
76+
memoized[astHooks[index]] = memoizedState.memoizedState;
7477
// Reassign memoizedState to its next value
7578
memoizedState = memoizedState.next;
7679
// Increment the index by 2
@@ -98,7 +101,7 @@ module.exports = (snap, mode) => {
98101
changeSetState(stateNode);
99102
}
100103
// Check if the component uses hooks
101-
if (memoizedState && memoizedState.hasOwnProperty('baseState')) {
104+
if (memoizedState && memoizedState.hasOwnProperty('baseState')) {
102105
// Add a traversed property and initialize to the evaluated result
103106
// of invoking traverseHooks, and reassign nextTree
104107
memoizedState.traversed = traverseHooks(memoizedState);
@@ -111,7 +114,8 @@ module.exports = (snap, mode) => {
111114

112115
return tree;
113116
}
114-
117+
// runs when page initially loads
118+
// but skips 1st hook click
115119
function updateSnapShotTree() {
116120
const { current } = fiberRoot;
117121
snap.tree = createTree(current);
@@ -125,9 +129,12 @@ module.exports = (snap, mode) => {
125129
// only assign internal rootp if it actually exists
126130
fiberRoot = _internalRoot || _reactRootContainer;
127131
// If hooks are implemented, traverse through the source code
128-
if (entryFile) astHooks = astParser(entryFile);
129-
130-
updateSnapShotTree();
132+
// Save the getter/setter combo for timeJump
133+
if (entryFile) {
134+
astHooks = astParser(entryFile);
135+
saveState(astHooks);
136+
}
137+
updateSnapShotTree();
131138
// send the initial snapshot once the content script has started up
132139
window.addEventListener('message', ({ data: { action } }) => {
133140
if (action === 'contentScriptStarted') sendSnapshot();

package/masterState.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
return masterState;
11+
},
12+
returnState: () => masterState
13+
};

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 { 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+
// Iterate 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
}

src/app/components/SwitchState.jsx

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
1-
import React from 'react';
2-
import Select from 'react-select';
1+
// import React from 'react';
2+
// import Select from 'react-select';
3+
// import Action from './Action';
4+
// import { useStoreContext } from '../store';
35

4-
// SwitchStateDropdown should display options including all
5-
// and specific states being used
6-
// TODO: Need to get the getter name (for functional components)
7-
// and state name for stateful components
8-
const SwitchStateDropdown = () => {
9-
// Requirements:
10-
// Should be able to filter the Actions by the name of the state being changed
11-
// Should consider how to import the state names being changed
12-
// Should display the "All state", as well as specific state names as the options
13-
// When clicked on "All state" >> should display all Actions
14-
// When clicked on a specific "state" >> should only display Actions corresponding to the state
6+
// // SwitchStateDropdown should display options including all
7+
// // and specific states being used
8+
// // TODO: Need to get the getter name (for functional components)
9+
// // and state name for stateful components
10+
// const SwitchStateDropdown = () => {
11+
// const [{ tabs, currentTab}, dispatch] = useStoreContext();
12+
// const { snapshots } = tabs[currentTab];
13+
// // Requirements:
14+
// // Should be able to filter the Actions by the name of the state being changed
15+
// // Should consider how to import the state names being changed
16+
// // Should display the "All state", as well as specific state names as the options
17+
// // When clicked on "All state" >> should display all Actions
18+
// // When clicked on a specific "state" >> should only display Actions corresponding to the state
1519

16-
const sampleDropdown = [
17-
{label: 'Overview'},
18-
{label: 'setUsername'},
19-
{label: 'setPassword'}
20-
];
20+
// // const sampleDropdown = [
21+
// // {label: 'Overview'},
22+
// // {label: 'setUsername'},
23+
// // {label: 'setPassword'}
24+
// // ];
2125

22-
return (
23-
<Select
24-
className="state-dropdown"
25-
placeholder="Choose your state"
26-
options={sampleDropdown}
27-
/>
28-
)
29-
}
26+
// return (
27+
// <Select
28+
// className="state-dropdown"
29+
// placeholder="Choose your state"
30+
// options={sampleDropdown}
31+
// />
32+
// )
33+
// }
3034

31-
export default SwitchStateDropdown;
35+
// export default SwitchStateDropdown;

src/app/containers/ActionContainer.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable react/no-array-index-key */
22
import React from 'react';
3-
import SwitchStateDropdown from '../components/SwitchState';
3+
//import SwitchStateDropdown from '../components/SwitchState';
44
import Action from '../components/Action';
55

66
import { emptySnapshots } from '../actions/actions';

0 commit comments

Comments
 (0)