Skip to content

Commit 1a67971

Browse files
committed
add changes
1 parent 528f416 commit 1a67971

File tree

5 files changed

+54
-55
lines changed

5 files changed

+54
-55
lines changed

src/backend/index.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,9 @@
3838
*
3939
*/
4040

41-
42-
4341
declare module "reactime" {
4442
function linkFiber(
4543
container: HTMLElement,
4644
): void;
4745
export = linkFiber;
4846
}
49-
50-

src/backend/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ window.addEventListener('message', ({ data: { action, payload } }: MsgData) => {
5959
mode.paused = payload;
6060
break;
6161
case 'onHover':
62-
if(Array.isArray(payload)){
63-
for (let i=0; i<payload.length;i++){
62+
if (Array.isArray(payload)) {
63+
for (let i = 0; i < payload.length; i + 1) {
6464
let element = document.getElementById(payload[i])
6565
if (element !== null) {
66-
element.style.backgroundColor = '#C0D9D9';
67-
}
66+
element.style.backgroundColor = '#C0D9D9';
67+
}
6868
}
6969
} else {
7070
let element = document.getElementById(payload)

src/backend/linkFiber.ts

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,26 @@ import 'core-js';
1111

1212
import {
1313
// eslint-disable-next-line @typescript-eslint/no-unused-vars
14+
//tree
1415
Snapshot,
16+
//jump, pause, lock
1517
Mode,
1618
ComponentData,
19+
//array of state and component
1720
HookStates,
21+
//object with tree structure
1822
Fiber,
1923
} from './types/backendTypes';
24+
//import function that creates a tree
2025
import Tree from './tree';
26+
//passes data down to its components
2127
import componentActionsRecord from './masterState';
28+
// throttle returns a function that can be called any number of times (possibly in quick succession) but will only invoke the callback at most once every x ms
29+
// getHooksNames - helper function to grab the getters/setters from `elementType`
2230
import { throttle, getHooksNames } from './helpers';
23-
import { Console } from 'console';
31+
// import { Console } from 'console';
2432
import AtomsRelationship from '../app/components/AtomsRelationship';
25-
import { isNull } from 'util';
33+
// import { isNull } from 'util';
2634

2735
// Set global variables to use in exported module and helper functions
2836
declare global {
@@ -36,7 +44,7 @@ const circularComponentTable = new Set();
3644
let isRecoil = false;
3745
let allAtomsRelationship = [];
3846
let initialstart = false;
39-
let rtidCounter = 0;
47+
let rtidCounter = 0;
4048
let rtid = null;
4149
let recoilDomNode = {};
4250

@@ -71,6 +79,7 @@ if (window[`$recoilDebugStates`]) {
7179
function sendSnapshot(snap: Snapshot, mode: Mode): void {
7280
// Don't send messages while jumping or while paused
7381
if (mode.jumping || mode.paused) return;
82+
// If there is no current tree creates a new one
7483
if (!snap.tree) {
7584
snap.tree = new Tree('root', 'root');
7685
}
@@ -82,7 +91,7 @@ function sendSnapshot(snap: Snapshot, mode: Mode): void {
8291
payload.atomSelectors = atomsSelectors;
8392
payload.recoilDomNode = recoilDomNode
8493
}
85-
94+
//method safely enables cross-origin communication between Window objects; e.g., between a page and a pop-up that it spawned, or between a page and an iframe embedded within it.
8695
window.postMessage(
8796
{
8897
action: 'recordSnap',
@@ -187,7 +196,6 @@ function createTree(
187196
if (!currentFiber) return null;
188197
if (!tree) return tree;
189198

190-
191199
// These have the newest state. We update state and then
192200
// called updateSnapshotTree()
193201

@@ -205,16 +213,16 @@ function createTree(
205213
treeBaseDuration,
206214
} = currentFiber;
207215

208-
209-
//Checks Recoil Atom and Selector Relationships
216+
// Checks Recoil Atom and Selector Relationships
210217
if (
211-
currentFiber.memoizedState &&
212-
currentFiber.memoizedState.next &&
213-
currentFiber.memoizedState.next.memoizedState &&
214-
currentFiber.memoizedState.next.memoizedState.deps &&
215-
isRecoil &&
216-
currentFiber.tag === 0 &&
217-
currentFiber.key === null //prevents capturing the same Fiber nodes but different key values that result from being changed
218+
currentFiber.memoizedState
219+
&& currentFiber.memoizedState.next
220+
&& currentFiber.memoizedState.next.memoizedState
221+
&& currentFiber.memoizedState.next.memoizedState.deps
222+
&& isRecoil
223+
&& currentFiber.tag === 0
224+
&& currentFiber.key === null
225+
// prevents capturing the same Fiber nodes but different key values that result from being changed
218226
) {
219227
let pointer = currentFiber.memoizedState.next;
220228
let componentName = currentFiber.elementType.name;
@@ -284,8 +292,8 @@ function createTree(
284292

285293
// RECOIL HOOKS
286294
if (
287-
memoizedState &&
288-
(tag === 0 || tag === 1 || tag === 2 || tag === 10) &&
295+
memoizedState
296+
&& (tag === 0 || tag === 1 || tag === 2 || tag === 10) &&
289297
isRecoil === true
290298
) {
291299
if (memoizedState.queue) {
@@ -317,8 +325,8 @@ function createTree(
317325
// Check if node is a hooks useState function
318326
// REGULAR REACT HOOKS
319327
if (
320-
memoizedState &&
321-
(tag === 0 || tag === 1 || tag === 2 || tag === 10) &&
328+
memoizedState
329+
&& (tag === 0 || tag === 1 || tag === 2 || tag === 10) &&
322330
isRecoil === false
323331
) {
324332
if (memoizedState.queue) {
@@ -366,24 +374,21 @@ function createTree(
366374
// We want to add this fiber node to the snapshot
367375
if (componentFound || newState === 'stateless') {
368376
if (fromSibling) {
369-
370-
if(isRecoil){
371-
if(currentFiber.elementType.name){
372-
if(!recoilDomNode[currentFiber.elementType.name]){
377+
if (isRecoil) {
378+
if (currentFiber.elementType.name) {
379+
if (!recoilDomNode[currentFiber.elementType.name]) {
373380
recoilDomNode[currentFiber.elementType.name] = [];
374381
}
375382
}
376383

377-
let pointer = currentFiber
378-
379-
while(pointer !== null){
380-
if(pointer.stateNode !== null){
384+
let pointer = currentFiber;
385+
while (pointer !== null) {
386+
if (pointer.stateNode !== null) {
381387
rtid = "fromLinkFiber" + rtidCounter++
382-
recoilDomNode[currentFiber.elementType.name].push(rtid)
383-
pointer.stateNode.setAttribute("id", rtid)
388+
recoilDomNode[currentFiber.elementType.name].push(rtid);
389+
pointer.stateNode.setAttribute("id", rtid);
384390
}
385-
386-
pointer = pointer.child
391+
pointer = pointer.child;
387392
}
388393
} else {
389394
if (currentFiber.child && currentFiber.child.stateNode && currentFiber.child.stateNode.setAttribute) {
@@ -401,20 +406,19 @@ function createTree(
401406
recoilDomNode
402407
);
403408
} else {
404-
405-
if(isRecoil){
406-
if(currentFiber.elementType.name){
407-
if(!recoilDomNode[currentFiber.elementType.name]){
409+
if (isRecoil) {
410+
if (currentFiber.elementType.name) {
411+
if (!recoilDomNode[currentFiber.elementType.name]) {
408412
recoilDomNode[currentFiber.elementType.name] = [];
409413
}
410414
}
411415
let pointer = currentFiber
412-
while(pointer !== null){
413-
if(pointer.stateNode !== null){
416+
while (pointer !== null) {
417+
if (pointer.stateNode !== null) {
414418
rtid = "fromLinkFiber" + rtidCounter++
415419
recoilDomNode[currentFiber.elementType.name].push(rtid)
416-
pointer.stateNode.setAttribute("id", rtid)
417-
}
420+
pointer.stateNode.setAttribute("id", rtid)
421+
}
418422
pointer = pointer.child
419423
}
420424
} else {
@@ -423,8 +427,7 @@ function createTree(
423427
currentFiber.child.stateNode.setAttribute("id", rtid);
424428
}
425429
rtidCounter++;
426-
}
427-
430+
}
428431
newNode = tree.addChild(
429432
newState,
430433
elementType ? elementType.name : 'nameless',

src/backend/timeJump.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default (origin, mode) => {
4646
return target.state;
4747
},
4848
// Iterate through new children after state has been set
49-
() => target.children.forEach(child => jump(child))
49+
() => target.children.forEach(child => jump(child)),
5050
);
5151
}
5252

src/backend/tree.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ class Tree {
4949

5050
atomSelectors: any;
5151

52-
rtid: any;
52+
rtid: any;
5353

54-
recoilDomNode: any;
54+
recoilDomNode: any;
5555

5656
constructor(state: string | {}, name = 'nameless', componentData: {} = {}, rtid: any = null, recoilDomNode:any = null) {
5757
this.state = state === 'root' ? 'root' : serializeState(state);
5858
this.name = name;
5959
this.componentData = componentData ? JSON.parse(JSON.stringify(componentData)) : {};
6060
this.children = [];
6161
this.parent = null; // ref to parent so we can add siblings
62-
this.rtid = rtid
63-
this.recoilDomNode = recoilDomNode
62+
this.rtid = rtid;
63+
this.recoilDomNode = recoilDomNode;
6464
}
6565

6666
addChild(state: string | {}, name: string, componentData: {}, rtid: any, recoilDomNode:any): Tree {
@@ -70,8 +70,8 @@ class Tree {
7070
return newChild;
7171
}
7272

73-
addSibling(state: string | {}, name: string, componentData: {}, rtid: any, recoilDomNode:any): Tree {
74-
const newSibling: Tree = new Tree(state, name, componentData, rtid,recoilDomNode);
73+
addSibling(state: string | {}, name: string, componentData: {}, rtid: any, recoilDomNode: any): Tree {
74+
const newSibling: Tree = new Tree(state, name, componentData, rtid, recoilDomNode);
7575
newSibling.parent = this.parent;
7676
this.parent.children.push(newSibling);
7777
return newSibling;

0 commit comments

Comments
 (0)