Skip to content

Commit 6870edd

Browse files
committed
useState showing on the tree
1 parent c3d0126 commit 6870edd

File tree

2 files changed

+52
-16
lines changed

2 files changed

+52
-16
lines changed

package/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const mode = {
77
};
88

99
const linkFiber = require('./linkFiber')(snapShot, mode);
10+
1011
const timeJump = require('./timeJump')(snapShot, mode);
1112

1213
window.addEventListener('message', ({ data: { action, payload } }) => {

package/linkFiber.js

Lines changed: 51 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
@@ -12,7 +13,6 @@ module.exports = (snap, mode) => {
1213
// DEV: So that when we are jumping to an old snapshot it wouldn't think we want to create new snapshots
1314
if (mode.jumping || mode.paused) return;
1415
const payload = snap.tree.getCopy();
15-
console.log(payload);
1616
// console.log('payload', payload);
1717
window.postMessage({
1818
action: 'recordSnap',
@@ -103,20 +103,55 @@ module.exports = (snap, mode) => {
103103
snap.tree = createTree(current);
104104
}
105105

106-
return container => {
107-
// console.log('Container', container);
108-
const {
109-
_reactRootContainer: { _internalRoot },
110-
_reactRootContainer,
111-
} = container;
112-
// console.log('Root container', _reactRootContainer);
113-
// only assign internal root if it actually exists
114-
fiberRoot = _internalRoot || _reactRootContainer;
115-
updateSnapShotTree();
106+
// return container => {
107+
// // console.log('Container', container);
108+
// const {
109+
// _reactRootContainer: { _internalRoot },
110+
// _reactRootContainer,
111+
// } = container;
112+
// // console.log('Root container', _reactRootContainer);
113+
// // only assign internal root if it actually exists
114+
// fiberRoot = _internalRoot || _reactRootContainer;
115+
// updateSnapShotTree();
116116

117-
// send the initial snapshot once the content script has started up
118-
window.addEventListener('message', ({ data: { action } }) => {
119-
if (action === 'contentScriptStarted') sendSnapshot();
120-
});
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+
// };
122+
123+
return {
124+
main(container) {
125+
// console.log('Container', container);
126+
const {
127+
_reactRootContainer: { _internalRoot },
128+
_reactRootContainer,
129+
} = container;
130+
// console.log('Root container', _reactRootContainer);
131+
// only assign internal root if it actually exists
132+
fiberRoot = _internalRoot || _reactRootContainer;
133+
updateSnapShotTree();
134+
135+
// send the initial snapshot once the content script has started up
136+
window.addEventListener('message', ({ data: { action } }) => {
137+
if (action === 'contentScriptStarted') sendSnapshot();
138+
});
139+
},
140+
changeUseState(useState) {
141+
return function (initial) {
142+
// running the original useState and storing its result (state and dispatch function)
143+
const toReturn = useState(initial);
144+
console.log(toReturn);
145+
// storing the original dispatch function definition somewhere
146+
const oldDispatch = toReturn[1];
147+
// redefining the dispatch function so we can inject our code
148+
toReturn[1] = function (callback) {
149+
oldDispatch(callback);
150+
updateSnapShotTree();
151+
sendSnapshot();
152+
};
153+
return toReturn;
154+
};
155+
},
121156
};
122-
};
157+
};

0 commit comments

Comments
 (0)