Skip to content

Commit c75d378

Browse files
committed
Merge branch 'reactime7' of https://github.com/rtviner/reactime into reactime7
2 parents 04bf179 + 0d36103 commit c75d378

File tree

2 files changed

+81
-97
lines changed

2 files changed

+81
-97
lines changed

src/backend/helpers.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ const JSXParser = acorn.Parser.extend(jsx());
1515

1616
/**
1717
* @method throttle
18-
* @param f A function to throttle
19-
* @param t A number of milliseconds to use as throttling interval
20-
* @returns A function that limits input function, `f`, from being called more than once every `t` milliseconds
18+
* @param callback A function to throttle
19+
* @param ms A number of milliseconds to use as throttling interval
20+
* @returns A function that limits input function, `callback`, from being called more than once every `ms` milliseconds
2121
*
2222
*/
23-
export const throttle = (f: Function, t: number): Function => {
23+
export const throttle = (callback: Function, ms: number): Function => {
2424
// Initialize boolean flags for callback, throttledFunc
2525
let isOnCooldown = false;
2626
let isCallQueued = false;
@@ -42,7 +42,7 @@ export const throttle = (f: Function, t: number): Function => {
4242

4343
// CASE 3: If we are ready to "fire":
4444
// Execute the function, f, immediately
45-
f();
45+
callback();
4646
// Initiate a new cooldown period and reset the "call queue"
4747
isOnCooldown = true;
4848
isCallQueued = false;
@@ -53,14 +53,14 @@ export const throttle = (f: Function, t: number): Function => {
5353
if (isCallQueued) {
5454
isCallQueued = false;
5555
isOnCooldown = true; // not needed I think
56-
f();
57-
setTimeout(runAfterTimeout, t);
56+
callback();
57+
setTimeout(runAfterTimeout, ms);
5858
return;
5959
}
6060
isOnCooldown = false;
6161
};
6262

63-
setTimeout(runAfterTimeout, t);
63+
setTimeout(runAfterTimeout, ms);
6464
};
6565

6666
return throttledFunc;

src/backend/linkFiber.ts

Lines changed: 73 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
Snapshot,
1717
//jump, pause, lock
1818
Mode,
19-
2019
ComponentData,
2120
// array of state and component
2221
HookStates,
@@ -37,7 +36,7 @@ import AtomsRelationship from '../app/components/AtomsRelationship';
3736

3837
// Set global variables to use in exported module and helper functions
3938
declare global {
40-
interface Window {
39+
interface Window {
4140
__REACT_DEVTOOLS_GLOBAL_HOOK__?: any;
4241
}
4342
}
@@ -56,22 +55,23 @@ let recoilDomNode = {};
5655
if (window[`$recoilDebugStates`]) {
5756
isRecoil = true;
5857
}
59-
60-
// function getRecoilState(): any {
61-
// const RecoilSnapshotsLength = window[`$recoilDebugStates`].length;
62-
// const lastRecoilSnapshot =
63-
// window[`$recoilDebugStates`][RecoilSnapshotsLength - 1];
64-
// const nodeToNodeSubs = lastRecoilSnapshot.nodeToNodeSubscriptions;
65-
// const nodeToNodeSubsKeys = lastRecoilSnapshot.nodeToNodeSubscriptions.keys();
66-
// nodeToNodeSubsKeys.forEach((node) => {
67-
// nodeToNodeSubs
68-
// .get(node)
69-
// .forEach((nodeSubs) =>
70-
// allAtomsRelationship.push([node, nodeSubs, 'atoms and selectors'])
71-
// );
72-
// });
73-
// }
74-
58+
// function for recoil apps (unused as of 11.22.2020)
59+
/*
60+
function getRecoilState(): any {
61+
const RecoilSnapshotsLength = window[`$recoilDebugStates`].length;
62+
const lastRecoilSnapshot =
63+
window[`$recoilDebugStates`][RecoilSnapshotsLength - 1];
64+
const nodeToNodeSubs = lastRecoilSnapshot.nodeToNodeSubscriptions;
65+
const nodeToNodeSubsKeys = lastRecoilSnapshot.nodeToNodeSubscriptions.keys();
66+
nodeToNodeSubsKeys.forEach((node) => {
67+
nodeToNodeSubs
68+
.get(node)
69+
.forEach((nodeSubs) =>
70+
allAtomsRelationship.push([node, nodeSubs, 'atoms and selectors'])
71+
);
72+
});
73+
}
74+
*/
7575
/**
7676
* @method sendSnapshot
7777
* @param snap The current snapshot
@@ -116,9 +116,6 @@ function sendSnapshot(snap: Snapshot, mode: Mode): void {
116116
//updating tree depending on current mode on the panel (pause, locked etc)
117117
function updateSnapShotTree(snap: Snapshot, mode: Mode): void {
118118
// this is the currently active root fiber(the mutable root of the tree)
119-
let fiberRootCurrent = fiberRoot.current;
120-
// console.log("fiber root props: ", Object.entries(fiberRootCurrent));
121-
// console.log("fiberroot sibling:", fiberRootCurrent.sibling, "fiberroot stateNode:", fiberRootCurrent.stateNode, "fiberroot child:", fiberRootCurrent.child, "fiberroot memoizedState:", fiberRootCurrent.memoizedState, "fiberroot memoizedProps:", fiberRootCurrent.memoizedProps, "fiberRootCurrent.elementType:",fiberRootCurrent.elementType, "fiberRootCurrent.tag: ", fiberRootCurrent.tag, "fiberRootCurrent.actualDuration: ", fiberRootCurrent.actualDuration, "fiberRootCurrent.actualStartTime: ", fiberRootCurrent.actualStartTime, "fiberRootCurrent.selfBaseDuration: ", fiberRootCurrent.selfBaseDuration, "fiberRootCurrent.treeBaseDuration:", fiberRootCurrent.treeBaseDuration);
122119

123120
if (fiberRoot) {
124121
const { current } = fiberRoot;
@@ -183,8 +180,7 @@ function traverseHooks(memoizedState: any): HookStates {
183180
state: memoizedState.memoizedState,
184181
});
185182
}
186-
memoizedState =
187-
memoizedState.next !== memoizedState ? memoizedState.next : null;
183+
memoizedState = (memoizedState.next !== memoizedState) ? memoizedState.next : null;
188184
}
189185
return hooksStates;
190186
}
@@ -212,13 +208,10 @@ function createTree(
212208
fromSibling = false
213209
) {
214210
// Base case: child or sibling pointed to null
215-
216211
if (!currentFiber) return null;
217212
if (!tree) return tree;
218-
219213
// These have the newest state. We update state and then
220214
// called updateSnapshotTree()
221-
222215
const {
223216
sibling,
224217
stateNode,
@@ -234,7 +227,7 @@ function createTree(
234227
treeBaseDuration,
235228
} = currentFiber;
236229

237-
// Checks Recoil Atom and Selector Relationships
230+
//Checks Recoil Atom and Selector Relationships
238231
if (
239232
currentFiber.memoizedState
240233
&& currentFiber.memoizedState.next
@@ -301,13 +294,10 @@ function createTree(
301294
stateNode.state,
302295
stateNode
303296
);
304-
305297
newState = stateNode.state;
306298
componentFound = true;
307299
}
308-
309300
let hooksIndex;
310-
311301
const atomArray = [];
312302
atomArray.push(memoizedProps);
313303

@@ -323,21 +313,36 @@ function createTree(
323313
// We then store them along with the corresponding memoizedState.queue,
324314
// which includes the dispatch() function we use to change their state.
325315
const hooksStates = traverseRecoilHooks(memoizedState, memoizedProps);
326-
hooksStates.forEach((state) => {
316+
console.log("hookStates: ", hooksStates);
317+
hooksStates.forEach((state, i) => {
327318
hooksIndex = componentActionsRecord.saveNew(
328319
state.state,
329320
state.component
330321
);
331322
componentData.hooksIndex = hooksIndex;
332323

333324
// Improves tree visualization but breaks jump ?
334-
if (newState && newState.hooksState) {
335-
newState.push(state.state);
336-
} else if (newState) {
337-
newState = [state.state];
338-
} else {
339-
newState.push(state.state);
325+
// if (!newState) {
326+
327+
// }
328+
// newState.push(state.state);
329+
// console.log('newState in Recoil: ', newState);
330+
// console.log('state.state: ', state.state);
331+
/* what is this supposed to do??? currently doesn't work?? and makes no sense, newState is an object, how can you push state.state into an object?? */
332+
// if (newState && newState.hooksState) {
333+
// newState.push(state.state);
334+
// } else if (newState) {
335+
// newState = [state.state];
336+
// } else {
337+
// newState.push(state.state);
338+
// }
339+
// componentFound = true;
340+
if (!newState) {
341+
newState = { hooksState: [] };
342+
} else if (!newState.hooksState) {
343+
newState.hooksState = [];
340344
}
345+
newState.hooksState.push({ [i]: state.state });
341346
componentFound = true;
342347
});
343348
}
@@ -351,6 +356,7 @@ function createTree(
351356
isRecoil === false
352357
) {
353358
if (memoizedState.queue) {
359+
console.log("line 357...")
354360
// Hooks states are stored as a linked list using memoizedState.next,
355361
// so we must traverse through the list and get the states.
356362
// We then store them along with the corresponding memoizedState.queue,
@@ -363,15 +369,12 @@ function createTree(
363369
state.component
364370
);
365371
componentData.hooksIndex = hooksIndex;
366-
if (newState && newState.hooksState) {
367-
newState.hooksState.push({ [hooksNames[i]]: state.state });
368-
} else if (newState) {
369-
newState.hooksState = [{ [hooksNames[i]]: state.state }];
370-
} else {
371-
// possibly app breaks somewhere if newState and hooksState do not exist?
372+
if (!newState) {
372373
newState = { hooksState: [] };
373-
newState.hooksState.push({ [hooksNames[i]]: state.state });
374+
} else if (!newState.hooksState) {
375+
newState.hooksState = [];
374376
}
377+
newState.hooksState.push({ [hooksNames[i]]: state.state });
375378
componentFound = true;
376379
});
377380
}
@@ -396,30 +399,33 @@ function createTree(
396399
// We want to add this fiber node to the snapshot
397400
if (componentFound || newState === 'stateless') {
398401
// where does this get changed to true?
399-
if (fromSibling) {
400-
if (isRecoil) {
401-
if (currentFiber.elementType.name) {
402-
if (!recoilDomNode[currentFiber.elementType.name]) {
403-
recoilDomNode[currentFiber.elementType.name] = [];
404-
}
402+
if (isRecoil) {
403+
// do this down below too
404+
if(currentFiber.elementType.name){
405+
if(!recoilDomNode[currentFiber.elementType.name]){
406+
recoilDomNode[currentFiber.elementType.name] = [];
405407
}
406-
407-
let pointer = currentFiber;
408-
while (pointer !== null) {
409-
if (pointer.stateNode !== null) {
410-
rtid = "fromLinkFiber" + rtidCounter++
411-
recoilDomNode[currentFiber.elementType.name].push(rtid);
412-
pointer.stateNode.setAttribute("id", rtid);
413-
}
414-
pointer = pointer.child;
415-
}
416-
} else {
417-
if (currentFiber.child && currentFiber.child.stateNode && currentFiber.child.stateNode.setAttribute) {
418-
rtid = "fromLinkFiber" + rtidCounter
419-
currentFiber.child.stateNode.setAttribute("id", rtid);
420-
}
421-
rtidCounter++;
422408
}
409+
let pointer = currentFiber
410+
// end of repeat code
411+
412+
while (pointer !== null) {
413+
if(pointer.stateNode !== null){
414+
rtid = "fromLinkFiber" + rtidCounter++
415+
recoilDomNode[currentFiber.elementType.name].push(rtid)
416+
pointer.stateNode.setAttribute("id", rtid)
417+
}
418+
pointer = pointer.child
419+
}
420+
} else {
421+
if (currentFiber.child && currentFiber.child.stateNode && currentFiber.child.stateNode.setAttribute) {
422+
rtid = "fromLinkFiber" + rtidCounter
423+
currentFiber.child.stateNode.setAttribute("id", rtid);
424+
}
425+
rtidCounter++;
426+
}
427+
// checking if tree fromSibling is true
428+
if (fromSibling) {
423429
// tree object from tree.ts, with addSibling
424430
newNode = tree.addSibling(
425431
newState,
@@ -428,29 +434,7 @@ function createTree(
428434
rtid,
429435
recoilDomNode
430436
);
431-
} else {
432-
if (isRecoil) {
433-
if (currentFiber.elementType.name) {
434-
if (!recoilDomNode[currentFiber.elementType.name]) {
435-
recoilDomNode[currentFiber.elementType.name] = [];
436-
}
437-
}
438-
let pointer = currentFiber
439-
while (pointer !== null) {
440-
if (pointer.stateNode !== null) {
441-
rtid = "fromLinkFiber" + rtidCounter++
442-
recoilDomNode[currentFiber.elementType.name].push(rtid)
443-
pointer.stateNode.setAttribute("id", rtid)
444-
}
445-
pointer = pointer.child
446-
}
447-
} else {
448-
if (currentFiber.child && currentFiber.child.stateNode && currentFiber.child.stateNode.setAttribute) {
449-
rtid = "fromLinkFiber" + rtidCounter
450-
currentFiber.child.stateNode.setAttribute("id", rtid);
451-
}
452-
rtidCounter++;
453-
}
437+
} else {
454438
newNode = tree.addChild(
455439
newState,
456440
elementType ? elementType.name : 'nameless',

0 commit comments

Comments
 (0)