Skip to content

Commit 1c8da9b

Browse files
committed
ignore
2 parents 36dad23 + 91190f0 commit 1c8da9b

33 files changed

+296
-160
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

assets/readme_logo.png

33.6 KB
Loading

demo2.gif renamed to demo.gif

File renamed without changes.

package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "reacttime-extension",
2+
"name": "reactime-extension",
33
"description": "build web extension bundle.js",
44
"scripts": {
55
"build": "webpack --mode production",
@@ -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/__tests__/linkFiber.test.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable react/jsx-filename-extension */
2-
import React from 'react';
2+
import React, { Component, useState } from 'react';
33
import { render } from 'react-dom';
44

55
const linkFiberRequire = require('../linkFiber');
@@ -8,7 +8,7 @@ let linkFiber;
88
let mode;
99
let snapShot;
1010

11-
class App extends React.Component {
11+
class App extends Component {
1212
constructor(props) {
1313
super(props);
1414
this.state = { foo: 'bar' };
@@ -20,6 +20,17 @@ class App extends React.Component {
2020
}
2121
}
2222

23+
// Need to create a functioanl component instance to test
24+
// Would need to be revised but here's the gist
25+
// const funcComponent = () => {
26+
// const [ number, setNumber ] = useState(0);
27+
// const newNumber = setNumber(1);
28+
29+
// return (
30+
// <div>{newNumber}</div>
31+
// )
32+
// }
33+
2334
describe('unit test for linkFiber', () => {
2435
beforeEach(() => {
2536
snapShot = { tree: null };

package/__tests__/timeJump.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class FiberNode {
1919
}
2020
}
2121

22+
// MVP FEATURE: Additional Testing
23+
// Testing for useState and useContext
24+
25+
2226
describe('unit testing for timeJump.js', () => {
2327
let timeJump;
2428
let snapShot;

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: 65 additions & 16 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,8 +10,10 @@ 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,
@@ -40,10 +43,48 @@ module.exports = (snap, mode) => {
4043
component.setState.linkFiberChanged = true;
4144
}
4245

46+
function changeUseState (component) {
47+
if (component.queue.dispatch.linkFiberChanged) return;
48+
// storing the original dispatch function definition somewhere
49+
const oldDispatch = component.queue.dispatch.bind(component.queue);
50+
// redefining the dispatch function so we can inject our code
51+
component.queue.dispatch = function (fiber, queue, action) {
52+
console.log('mode', mode);
53+
if (mode.locked && !mode.jumping) return;
54+
oldDispatch(fiber, queue, action);
55+
setTimeout(() => {
56+
updateSnapShotTree();
57+
sendSnapshot();
58+
}, 100);
59+
};
60+
component.queue.dispatch.linkFiberChanged = true;
61+
};
62+
63+
// Helper function to traverse through the memoized state
64+
function traverseHooks(memoizedState) {
65+
// Declare variables and assigned to 0th index and an empty object, respectively
66+
let index = 0;
67+
const memoizedObj = {};
68+
// while memoizedState is truthy, save the value to the object
69+
while (memoizedState) {
70+
changeUseState(memoizedState);
71+
// Increment the index by 1
72+
memoizedObj[`state${index += 1}`] = memoizedState.memoizedState;
73+
// Reassign memoizedState to its next value
74+
memoizedState = memoizedState.next;
75+
}
76+
return memoizedObj;
77+
}
78+
4379
function createTree(currentFiber, tree = new Tree('root')) {
4480
if (!currentFiber) return tree;
45-
46-
const { sibling, stateNode, child } = currentFiber;
81+
82+
const {
83+
sibling,
84+
stateNode,
85+
child,
86+
memoizedState,
87+
} = currentFiber;
4788

4889
let nextTree = tree;
4990
// check if stateful component
@@ -53,7 +94,14 @@ module.exports = (snap, mode) => {
5394
// change setState functionality
5495
changeSetState(stateNode);
5596
}
56-
97+
// Check if the component uses hooks
98+
// TODO: Refactor the conditionals - think about the edge case where a stateful
99+
// component might have a key called 'baseState' in the state
100+
if (memoizedState && memoizedState.hasOwnProperty('baseState')) {
101+
console.log("I'm not supposed to run", currentFiber);
102+
memoizedState.traversed = traverseHooks(memoizedState);
103+
nextTree = tree.appendChild(memoizedState);
104+
}
57105
// iterate through siblings
58106
createTree(sibling, tree);
59107
// iterate through children
@@ -67,18 +115,19 @@ module.exports = (snap, mode) => {
67115
snap.tree = createTree(current);
68116
}
69117

70-
return container => {
71-
const {
72-
_reactRootContainer: { _internalRoot },
73-
_reactRootContainer,
74-
} = container;
75-
// only assign internal root if it actually exists
76-
fiberRoot = _internalRoot || _reactRootContainer;
77-
updateSnapShotTree();
78-
79-
// send the initial snapshot once the content script has started up
80-
window.addEventListener('message', ({ data: { action } }) => {
81-
if (action === 'contentScriptStarted') sendSnapshot();
82-
});
118+
return {
119+
_(container) {
120+
const {
121+
_reactRootContainer: { _internalRoot },
122+
_reactRootContainer,
123+
} = container;
124+
// only assign internal root if it actually exists
125+
fiberRoot = _internalRoot || _reactRootContainer;
126+
updateSnapShotTree();
127+
// send the initial snapshot once the content script has started up
128+
window.addEventListener('message', ({ data: { action } }) => {
129+
if (action === 'contentScriptStarted') sendSnapshot();
130+
});
131+
},
83132
};
84133
};

0 commit comments

Comments
 (0)