Skip to content

Commit c685cd5

Browse files
committed
current dev
2 parents ed36f2c + 520b0bc commit c685cd5

20 files changed

+235
-149
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ tictactoe
66
parents
77
coverage
88
src/extension/build.zip
9+
src/extension/build.crx
10+
src/extension/build/key.pem

.travis.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,3 @@ services:
22
- docker
33
script:
44
- docker-compose up --abort-on-container-exit
5-
deploy:
6-
provider: script
7-
skip_cleanup: true
8-
on:
9-
branches:
10-
only:
11-
- dev
12-
- master

demo2.gif

-3.54 MB
Binary file not shown.

package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,20 @@
2020
"type": "git",
2121
"url": "https://github.com/oslabs-beta/reactime"
2222
},
23-
"author": "Bryan Lee, Josh Kim, Ryan Dang, Sierra Swaby",
23+
"contributors": [
24+
"Andy Wong",
25+
"Bryan Lee",
26+
"David Chai",
27+
"Josh Kim",
28+
"Ruthba Anam",
29+
"Ryan Dang",
30+
"Sierra Swaby",
31+
"Yujin Kang"
32+
],
2433
"license": "ISC",
2534
"devDependencies": {
2635
"@babel/core": "^7.5.5",
36+
"@babel/plugin-proposal-class-properties": "^7.5.5",
2737
"@babel/plugin-proposal-decorators": "^7.4.4",
2838
"@babel/preset-env": "^7.5.5",
2939
"@babel/preset-react": "^7.0.0",

package/demo.gif

-114 KB
Loading

package/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ window.addEventListener('message', ({ data: { action, payload } }) => {
2525
}
2626
});
2727

28-
module.exports = linkFiber;
28+
module.exports = linkFiber;

package/linkFiber.js

Lines changed: 101 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable func-names */
12
/* eslint-disable no-use-before-define */
23
/* eslint-disable no-param-reassign */
34
// links component state tree to library
@@ -9,14 +10,19 @@ module.exports = (snap, mode) => {
910

1011
function sendSnapshot() {
1112
// don't send messages while jumping or while paused
13+
// DEV: So that when we are jumping to an old snapshot it wouldn't think we want to create new snapshots
1214
if (mode.jumping || mode.paused) return;
1315
const payload = snap.tree.getCopy();
16+
// console.log('payload', payload);
1417
window.postMessage({
1518
action: 'recordSnap',
1619
payload,
1720
});
1821
}
1922

23+
// DEV: This is how we know when a change has happened
24+
// (by injecting an event listener to every component's setState functionality).
25+
// Will need to create a separate one for useState components
2026
function changeSetState(component) {
2127
// check that setState hasn't been changed yet
2228
if (component.setState.linkFiberChanged) return;
@@ -40,11 +46,32 @@ module.exports = (snap, mode) => {
4046
component.setState.linkFiberChanged = true;
4147
}
4248

49+
// Helper function to
50+
51+
// Helper function to traverse through the memoized state
52+
function traverseHooks(memoizedState) {
53+
// Declare variables and assigned to 0th index and an empty object, respectively
54+
let index = 0;
55+
const memoizedObj = {};
56+
// while memoizedState is truthy, save the value to the object
57+
while (memoizedState) {
58+
// Increment the index by 1
59+
memoizedObj[`state${index += 1}`] = memoizedState.memoizedState;
60+
// Reassign memoizedState to its next value
61+
memoizedState = memoizedState.next;
62+
}
63+
return memoizedObj;
64+
}
65+
4366
function createTree(currentFiber, tree = new Tree('root')) {
4467
if (!currentFiber) return tree;
45-
// We have to figure out which properties to destructure from currentFiber
46-
// To support hooks and Context API
47-
const { sibling, stateNode, child } = currentFiber;
68+
69+
const {
70+
sibling,
71+
stateNode,
72+
child,
73+
memoizedState,
74+
} = currentFiber;
4875

4976
let nextTree = tree;
5077
// check if stateful component
@@ -54,8 +81,16 @@ module.exports = (snap, mode) => {
5481
// change setState functionality
5582
changeSetState(stateNode);
5683
}
57-
// Need to check if functional component AND uses hooks
58-
84+
// Check if the component uses hooks
85+
// TODO: Refactor the conditionals - think about the edge case where a stateful
86+
// component might have a key called 'baseState' in the state
87+
if (memoizedState && memoizedState.hasOwnProperty('baseState')) {
88+
// console.log('The memoizedState is: ', memoizedState)
89+
90+
const traversed = traverseHooks(memoizedState);
91+
nextTree = tree.appendChild(traversed);
92+
}
93+
5994
// iterate through siblings
6095
createTree(sibling, tree);
6196
// iterate through children
@@ -68,19 +103,67 @@ module.exports = (snap, mode) => {
68103
const { current } = fiberRoot;
69104
snap.tree = createTree(current);
70105
}
106+
// return container => {
107+
// console.log('this is the container', container)
108+
// const {
109+
// _reactRootContainer: { _internalRoot },
110+
// _reactRootContainer,
111+
// } = container;
112+
// // only assign internal root if it actually exists
113+
// fiberRoot = _internalRoot || _reactRootContainer;
114+
// console.log('fiberRoot', fiberRoot);
115+
// updateSnapShotTree();
71116

72-
return container => {
73-
const {
74-
_reactRootContainer: { _internalRoot },
75-
_reactRootContainer,
76-
} = container;
77-
// only assign internal root if it actually exists
78-
fiberRoot = _internalRoot || _reactRootContainer;
79-
updateSnapShotTree();
117+
// // send the initial snapshot once the content script has started up
118+
// window.addEventListener('message', ({ data: { action } }) => {
119+
// if (action === 'contentScriptStarted') sendSnapshot();
120+
// });
121+
// };
80122

81-
// send the initial snapshot once the content script has started up
82-
window.addEventListener('message', ({ data: { action } }) => {
83-
if (action === 'contentScriptStarted') sendSnapshot();
84-
});
123+
return {
124+
_(container) {
125+
const {
126+
_reactRootContainer: { _internalRoot },
127+
_reactRootContainer,
128+
} = container;
129+
// only assign internal root if it actually exists
130+
fiberRoot = _internalRoot || _reactRootContainer;
131+
updateSnapShotTree();
132+
// send the initial snapshot once the content script has started up
133+
window.addEventListener('message', ({ data: { action } }) => {
134+
if (action === 'contentScriptStarted') sendSnapshot();
135+
});
136+
},
137+
testUseState(useState) {
138+
return function(initial) {
139+
// running the original useState and storing its result (state and dispatch function)
140+
const toReturn = useState(initial);
141+
// storing the original dispatch function definition somewhere
142+
const oldDispatch = toReturn[1];
143+
// redefining the dispatch function so we can inject our code
144+
toReturn[1] = function(newVal) {
145+
oldDispatch(newVal);
146+
updateSnapShotTree();
147+
sendSnapshot();
148+
};
149+
return toReturn;
150+
};
151+
},
152+
testUseReducer(useReducer) {
153+
return function(reducer, initialState, init) {
154+
// Declare a constant and initialize to the built-in useReducer method
155+
// Which returns an array with the state and dispatch
156+
const reduced = useReducer(reducer, initialState, init);
157+
// Save the dispatch method
158+
const oldDispatch = reduced[1];
159+
// reassign the dispatch method with the additional methods
160+
reduced[1] = function(type) {
161+
oldDispatch(type);
162+
updateSnapShotTree();
163+
sendSnapshot();
164+
}
165+
return reduced;
166+
}
167+
},
85168
};
86-
};
169+
};

package/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package/package.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "reactime",
3-
"version": "2.0.1",
3+
"version": "2.0.3",
44
"description": "A library that helps debug React by memorizing the state of components with every render.",
55
"main": "index.js",
66
"repository": {
@@ -21,6 +21,16 @@
2121
"reactime",
2222
"react devtool"
2323
],
24-
"author": "Bryan Lee, Josh Kim, Ryan Dang, Sierra Swaby",
25-
"license": "MIT"
24+
"contributors": [
25+
"Andy Wong",
26+
"Bryan Lee",
27+
"David Chai",
28+
"Josh Kim",
29+
"Ruthba Anam",
30+
"Ryan Dang",
31+
"Sierra Swaby",
32+
"Yujin Kang"
33+
],
34+
"license": "MIT",
35+
"dependencies": {}
2636
}

package/react-time-travel-1.0.1.tgz

-49.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)