@@ -11,18 +11,26 @@ import 'core-js';
11
11
12
12
import {
13
13
// eslint-disable-next-line @typescript-eslint/no-unused-vars
14
+ //tree
14
15
Snapshot ,
16
+ //jump, pause, lock
15
17
Mode ,
16
18
ComponentData ,
19
+ //array of state and component
17
20
HookStates ,
21
+ //object with tree structure
18
22
Fiber ,
19
23
} from './types/backendTypes' ;
24
+ //import function that creates a tree
20
25
import Tree from './tree' ;
26
+ //passes data down to its components
21
27
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`
22
30
import { throttle , getHooksNames } from './helpers' ;
23
- import { Console } from 'console' ;
31
+ // import { Console } from 'console';
24
32
import AtomsRelationship from '../app/components/AtomsRelationship' ;
25
- import { isNull } from 'util' ;
33
+ // import { isNull } from 'util';
26
34
27
35
// Set global variables to use in exported module and helper functions
28
36
declare global {
@@ -36,7 +44,7 @@ const circularComponentTable = new Set();
36
44
let isRecoil = false ;
37
45
let allAtomsRelationship = [ ] ;
38
46
let initialstart = false ;
39
- let rtidCounter = 0 ;
47
+ let rtidCounter = 0 ;
40
48
let rtid = null ;
41
49
let recoilDomNode = { } ;
42
50
@@ -71,6 +79,7 @@ if (window[`$recoilDebugStates`]) {
71
79
function sendSnapshot ( snap : Snapshot , mode : Mode ) : void {
72
80
// Don't send messages while jumping or while paused
73
81
if ( mode . jumping || mode . paused ) return ;
82
+ // If there is no current tree creates a new one
74
83
if ( ! snap . tree ) {
75
84
snap . tree = new Tree ( 'root' , 'root' ) ;
76
85
}
@@ -82,7 +91,7 @@ function sendSnapshot(snap: Snapshot, mode: Mode): void {
82
91
payload . atomSelectors = atomsSelectors ;
83
92
payload . recoilDomNode = recoilDomNode
84
93
}
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.
86
95
window . postMessage (
87
96
{
88
97
action : 'recordSnap' ,
@@ -187,7 +196,6 @@ function createTree(
187
196
if ( ! currentFiber ) return null ;
188
197
if ( ! tree ) return tree ;
189
198
190
-
191
199
// These have the newest state. We update state and then
192
200
// called updateSnapshotTree()
193
201
@@ -205,16 +213,16 @@ function createTree(
205
213
treeBaseDuration,
206
214
} = currentFiber ;
207
215
208
-
209
- //Checks Recoil Atom and Selector Relationships
216
+ // Checks Recoil Atom and Selector Relationships
210
217
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
218
226
) {
219
227
let pointer = currentFiber . memoizedState . next ;
220
228
let componentName = currentFiber . elementType . name ;
@@ -284,8 +292,8 @@ function createTree(
284
292
285
293
// RECOIL HOOKS
286
294
if (
287
- memoizedState &&
288
- ( tag === 0 || tag === 1 || tag === 2 || tag === 10 ) &&
295
+ memoizedState
296
+ && ( tag === 0 || tag === 1 || tag === 2 || tag === 10 ) &&
289
297
isRecoil === true
290
298
) {
291
299
if ( memoizedState . queue ) {
@@ -317,8 +325,8 @@ function createTree(
317
325
// Check if node is a hooks useState function
318
326
// REGULAR REACT HOOKS
319
327
if (
320
- memoizedState &&
321
- ( tag === 0 || tag === 1 || tag === 2 || tag === 10 ) &&
328
+ memoizedState
329
+ && ( tag === 0 || tag === 1 || tag === 2 || tag === 10 ) &&
322
330
isRecoil === false
323
331
) {
324
332
if ( memoizedState . queue ) {
@@ -366,24 +374,21 @@ function createTree(
366
374
// We want to add this fiber node to the snapshot
367
375
if ( componentFound || newState === 'stateless' ) {
368
376
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 ] ) {
373
380
recoilDomNode [ currentFiber . elementType . name ] = [ ] ;
374
381
}
375
382
}
376
383
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 ) {
381
387
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 ) ;
384
390
}
385
-
386
- pointer = pointer . child
391
+ pointer = pointer . child ;
387
392
}
388
393
} else {
389
394
if ( currentFiber . child && currentFiber . child . stateNode && currentFiber . child . stateNode . setAttribute ) {
@@ -401,20 +406,19 @@ function createTree(
401
406
recoilDomNode
402
407
) ;
403
408
} 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 ] ) {
408
412
recoilDomNode [ currentFiber . elementType . name ] = [ ] ;
409
413
}
410
414
}
411
415
let pointer = currentFiber
412
- while ( pointer !== null ) {
413
- if ( pointer . stateNode !== null ) {
416
+ while ( pointer !== null ) {
417
+ if ( pointer . stateNode !== null ) {
414
418
rtid = "fromLinkFiber" + rtidCounter ++
415
419
recoilDomNode [ currentFiber . elementType . name ] . push ( rtid )
416
- pointer . stateNode . setAttribute ( "id" , rtid )
417
- }
420
+ pointer . stateNode . setAttribute ( "id" , rtid )
421
+ }
418
422
pointer = pointer . child
419
423
}
420
424
} else {
@@ -423,8 +427,7 @@ function createTree(
423
427
currentFiber . child . stateNode . setAttribute ( "id" , rtid ) ;
424
428
}
425
429
rtidCounter ++ ;
426
- }
427
-
430
+ }
428
431
newNode = tree . addChild (
429
432
newState ,
430
433
elementType ? elementType . name : 'nameless' ,
0 commit comments