@@ -16,7 +16,6 @@ import {
16
16
Snapshot ,
17
17
//jump, pause, lock
18
18
Mode ,
19
-
20
19
ComponentData ,
21
20
// array of state and component
22
21
HookStates ,
@@ -37,7 +36,7 @@ import { isNull } from 'util';
37
36
38
37
// Set global variables to use in exported module and helper functions
39
38
declare global {
40
- interface Window {
39
+ interface Window {
41
40
__REACT_DEVTOOLS_GLOBAL_HOOK__ ?: any ;
42
41
}
43
42
}
@@ -56,22 +55,23 @@ let recoilDomNode = {};
56
55
if ( window [ `$recoilDebugStates` ] ) {
57
56
isRecoil = true ;
58
57
}
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
+ */
75
75
/**
76
76
* @method sendSnapshot
77
77
* @param snap The current snapshot
@@ -116,9 +116,6 @@ function sendSnapshot(snap: Snapshot, mode: Mode): void {
116
116
//updating tree depending on current mode on the panel (pause, locked etc)
117
117
function updateSnapShotTree ( snap : Snapshot , mode : Mode ) : void {
118
118
// 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);
122
119
123
120
if ( fiberRoot ) {
124
121
const { current } = fiberRoot ;
@@ -183,8 +180,7 @@ function traverseHooks(memoizedState: any): HookStates {
183
180
state : memoizedState . memoizedState ,
184
181
} ) ;
185
182
}
186
- memoizedState =
187
- memoizedState . next !== memoizedState ? memoizedState . next : null ;
183
+ memoizedState = ( memoizedState . next !== memoizedState ) ? memoizedState . next : null ;
188
184
}
189
185
return hooksStates ;
190
186
}
@@ -212,14 +208,10 @@ function createTree(
212
208
fromSibling = false
213
209
) {
214
210
// Base case: child or sibling pointed to null
215
-
216
211
if ( ! currentFiber ) return null ;
217
212
if ( ! tree ) return tree ;
218
-
219
-
220
213
// These have the newest state. We update state and then
221
214
// called updateSnapshotTree()
222
-
223
215
const {
224
216
sibling,
225
217
stateNode,
@@ -235,7 +227,6 @@ function createTree(
235
227
treeBaseDuration,
236
228
} = currentFiber ;
237
229
238
-
239
230
//Checks Recoil Atom and Selector Relationships
240
231
if (
241
232
currentFiber . memoizedState &&
@@ -302,13 +293,10 @@ function createTree(
302
293
stateNode . state ,
303
294
stateNode
304
295
) ;
305
-
306
296
newState = stateNode . state ;
307
297
componentFound = true ;
308
298
}
309
-
310
299
let hooksIndex ;
311
-
312
300
const atomArray = [ ] ;
313
301
atomArray . push ( memoizedProps ) ;
314
302
@@ -324,21 +312,36 @@ function createTree(
324
312
// We then store them along with the corresponding memoizedState.queue,
325
313
// which includes the dispatch() function we use to change their state.
326
314
const hooksStates = traverseRecoilHooks ( memoizedState , memoizedProps ) ;
327
- hooksStates . forEach ( ( state ) => {
315
+ console . log ( "hookStates: " , hooksStates ) ;
316
+ hooksStates . forEach ( ( state , i ) => {
328
317
hooksIndex = componentActionsRecord . saveNew (
329
318
state . state ,
330
319
state . component
331
320
) ;
332
321
componentData . hooksIndex = hooksIndex ;
333
322
334
323
// Improves tree visualization but breaks jump ?
335
- if ( newState && newState . hooksState ) {
336
- newState . push ( state . state ) ;
337
- } else if ( newState ) {
338
- newState = [ state . state ] ;
339
- } else {
340
- newState . push ( state . state ) ;
324
+ // if (!newState) {
325
+
326
+ // }
327
+ // newState.push(state.state);
328
+ // console.log('newState in Recoil: ', newState);
329
+ // console.log('state.state: ', state.state);
330
+ /* 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?? */
331
+ // if (newState && newState.hooksState) {
332
+ // newState.push(state.state);
333
+ // } else if (newState) {
334
+ // newState = [state.state];
335
+ // } else {
336
+ // newState.push(state.state);
337
+ // }
338
+ // componentFound = true;
339
+ if ( ! newState ) {
340
+ newState = { hooksState : [ ] } ;
341
+ } else if ( ! newState . hooksState ) {
342
+ newState . hooksState = [ ] ;
341
343
}
344
+ newState . hooksState . push ( { [ i ] : state . state } ) ;
342
345
componentFound = true ;
343
346
} ) ;
344
347
}
@@ -352,6 +355,7 @@ function createTree(
352
355
isRecoil === false
353
356
) {
354
357
if ( memoizedState . queue ) {
358
+ console . log ( "line 357..." )
355
359
// Hooks states are stored as a linked list using memoizedState.next,
356
360
// so we must traverse through the list and get the states.
357
361
// We then store them along with the corresponding memoizedState.queue,
@@ -364,15 +368,12 @@ function createTree(
364
368
state . component
365
369
) ;
366
370
componentData . hooksIndex = hooksIndex ;
367
- if ( newState && newState . hooksState ) {
368
- newState . hooksState . push ( { [ hooksNames [ i ] ] : state . state } ) ;
369
- } else if ( newState ) {
370
- newState . hooksState = [ { [ hooksNames [ i ] ] : state . state } ] ;
371
- } else {
372
- // possibly app breaks somewhere if newState and hooksState do not exist?
371
+ if ( ! newState ) {
373
372
newState = { hooksState : [ ] } ;
374
- newState . hooksState . push ( { [ hooksNames [ i ] ] : state . state } ) ;
373
+ } else if ( ! newState . hooksState ) {
374
+ newState . hooksState = [ ] ;
375
375
}
376
+ newState . hooksState . push ( { [ hooksNames [ i ] ] : state . state } ) ;
376
377
componentFound = true ;
377
378
} ) ;
378
379
}
@@ -397,33 +398,33 @@ function createTree(
397
398
// We want to add this fiber node to the snapshot
398
399
if ( componentFound || newState === 'stateless' ) {
399
400
// where does this get changed to true?
400
- if ( fromSibling ) {
401
-
402
- if ( isRecoil ) {
403
- if ( currentFiber . elementType . name ) {
404
- if ( ! recoilDomNode [ currentFiber . elementType . name ] ) {
405
- recoilDomNode [ currentFiber . elementType . name ] = [ ] ;
406
- }
401
+ if ( isRecoil ) {
402
+ // do this down below too
403
+ if ( currentFiber . elementType . name ) {
404
+ if ( ! recoilDomNode [ currentFiber . elementType . name ] ) {
405
+ recoilDomNode [ currentFiber . elementType . name ] = [ ] ;
407
406
}
408
-
409
- let pointer = currentFiber
410
-
411
- while ( pointer !== null ) {
412
- if ( pointer . stateNode !== null ) {
413
- rtid = "fromLinkFiber" + rtidCounter ++
414
- recoilDomNode [ currentFiber . elementType . name ] . push ( rtid )
415
- pointer . stateNode . setAttribute ( "id" , rtid )
416
- }
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
407
}
408
+ let pointer = currentFiber
409
+ // end of repeat code
410
+
411
+ while ( pointer !== null ) {
412
+ if ( pointer . stateNode !== null ) {
413
+ rtid = "fromLinkFiber" + rtidCounter ++
414
+ recoilDomNode [ currentFiber . elementType . name ] . push ( rtid )
415
+ pointer . stateNode . setAttribute ( "id" , rtid )
416
+ }
417
+ pointer = pointer . child
418
+ }
419
+ } else {
420
+ if ( currentFiber . child && currentFiber . child . stateNode && currentFiber . child . stateNode . setAttribute ) {
421
+ rtid = "fromLinkFiber" + rtidCounter
422
+ currentFiber . child . stateNode . setAttribute ( "id" , rtid ) ;
423
+ }
424
+ rtidCounter ++ ;
425
+ }
426
+ // checking if tree fromSibling is true
427
+ if ( fromSibling ) {
427
428
// tree object from tree.ts, with addSibling
428
429
newNode = tree . addSibling (
429
430
newState ,
@@ -432,31 +433,7 @@ function createTree(
432
433
rtid ,
433
434
recoilDomNode
434
435
) ;
435
- } else {
436
-
437
- if ( isRecoil ) {
438
- if ( currentFiber . elementType . name ) {
439
- if ( ! recoilDomNode [ currentFiber . elementType . name ] ) {
440
- recoilDomNode [ currentFiber . elementType . name ] = [ ] ;
441
- }
442
- }
443
- let pointer = currentFiber
444
- while ( pointer !== null ) {
445
- if ( pointer . stateNode !== null ) {
446
- rtid = "fromLinkFiber" + rtidCounter ++
447
- recoilDomNode [ currentFiber . elementType . name ] . push ( rtid )
448
- pointer . stateNode . setAttribute ( "id" , rtid )
449
- }
450
- pointer = pointer . child
451
- }
452
- } else {
453
- if ( currentFiber . child && currentFiber . child . stateNode && currentFiber . child . stateNode . setAttribute ) {
454
- rtid = "fromLinkFiber" + rtidCounter
455
- currentFiber . child . stateNode . setAttribute ( "id" , rtid ) ;
456
- }
457
- rtidCounter ++ ;
458
- }
459
-
436
+ } else {
460
437
newNode = tree . addChild (
461
438
newState ,
462
439
elementType ? elementType . name : 'nameless' ,
0 commit comments