Skip to content

Commit f1a5e38

Browse files
committed
Hooks now will not create new snapshots while time jumping
1 parent 8bd3648 commit f1a5e38

File tree

2 files changed

+6
-43
lines changed

2 files changed

+6
-43
lines changed

package/linkFiber.js

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,8 @@ module.exports = (snap, mode) => {
4545

4646
function changeUseState (component) {
4747
if (component.queue.dispatch.linkFiberChanged) return;
48-
// running the original useState and storing its result (state and dispatch function)
49-
const oldDispatch = component.queue.dispatch.bind(component.queue);
5048
// storing the original dispatch function definition somewhere
51-
console.log('inside changeusestate', oldDispatch);
52-
49+
const oldDispatch = component.queue.dispatch.bind(component.queue);
5350
// redefining the dispatch function so we can inject our code
5451
component.queue.dispatch = function (fiber, queue, action) {
5552
console.log('mode', mode);
@@ -102,6 +99,7 @@ module.exports = (snap, mode) => {
10299
// TODO: Refactor the conditionals - think about the edge case where a stateful
103100
// component might have a key called 'baseState' in the state
104101
if (memoizedState && memoizedState.hasOwnProperty('baseState')) {
102+
console.log("I'm not supposed to run", currentFiber);
105103
memoizedState.traversed = traverseHooks(memoizedState);
106104
nextTree = tree.appendChild(memoizedState);
107105
}
@@ -115,6 +113,7 @@ module.exports = (snap, mode) => {
115113

116114
function updateSnapShotTree() {
117115
const { current } = fiberRoot;
116+
console.log('current', current);
118117
snap.tree = createTree(current);
119118
}
120119

@@ -132,41 +131,5 @@ module.exports = (snap, mode) => {
132131
if (action === 'contentScriptStarted') sendSnapshot();
133132
});
134133
},
135-
// testHooks(react) {
136-
// return {
137-
// useState: initialState => {
138-
// // running the original useState and storing its result (state and dispatch function)
139-
// const toReturn = react.useState(initialState);
140-
// // storing the original dispatch function definition somewhere
141-
// const oldDispatch = toReturn[1];
142-
// console.log('old dispatch', oldDispatch)
143-
// // redefining the dispatch function so we can inject our code
144-
// toReturn[1] = function (newVal) {
145-
// oldDispatch(newVal);
146-
// setTimeout(() => {
147-
// updateSnapShotTree();
148-
// sendSnapshot();
149-
// }, 100);
150-
// };
151-
// return toReturn;
152-
// },
153-
// useReducer: (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 = react.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-
// setTimeout(() => {
163-
// updateSnapShotTree();
164-
// sendSnapshot();
165-
// }, 100);
166-
// };
167-
// return reduced;
168-
// },
169-
// };
170-
// },
171134
};
172135
};

package/timeJump.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ module.exports = (origin, mode) => {
1212
// recursively change state of tree
1313
function jump(target, coords = []) {
1414
const originNode = traverseTree(origin.tree, coords);
15-
console.log('coords', coords);
16-
console.log('originNode', originNode);
1715
// set the state of the origin tree if the component is stateful
1816
if (originNode.component.setState) {
1917
originNode.component.setState(target.state, () => {
@@ -44,6 +42,8 @@ module.exports = (origin, mode) => {
4442
// setting mode disables setState from posting messages to window
4543
mode.jumping = true;
4644
jump(target);
47-
mode.jumping = false;
45+
setTimeout(() => {
46+
mode.jumping = false;
47+
}, 100);
4848
};
4949
};

0 commit comments

Comments
 (0)