@@ -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 AtomsRelationship from '../app/components/AtomsRelationship';
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,13 +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
213
// These have the newest state. We update state and then
220
214
// called updateSnapshotTree()
221
-
222
215
const {
223
216
sibling,
224
217
stateNode,
@@ -234,7 +227,7 @@ function createTree(
234
227
treeBaseDuration,
235
228
} = currentFiber ;
236
229
237
- // Checks Recoil Atom and Selector Relationships
230
+ //Checks Recoil Atom and Selector Relationships
238
231
if (
239
232
currentFiber . memoizedState
240
233
&& currentFiber . memoizedState . next
@@ -301,13 +294,10 @@ function createTree(
301
294
stateNode . state ,
302
295
stateNode
303
296
) ;
304
-
305
297
newState = stateNode . state ;
306
298
componentFound = true ;
307
299
}
308
-
309
300
let hooksIndex ;
310
-
311
301
const atomArray = [ ] ;
312
302
atomArray . push ( memoizedProps ) ;
313
303
@@ -323,21 +313,36 @@ function createTree(
323
313
// We then store them along with the corresponding memoizedState.queue,
324
314
// which includes the dispatch() function we use to change their state.
325
315
const hooksStates = traverseRecoilHooks ( memoizedState , memoizedProps ) ;
326
- hooksStates . forEach ( ( state ) => {
316
+ console . log ( "hookStates: " , hooksStates ) ;
317
+ hooksStates . forEach ( ( state , i ) => {
327
318
hooksIndex = componentActionsRecord . saveNew (
328
319
state . state ,
329
320
state . component
330
321
) ;
331
322
componentData . hooksIndex = hooksIndex ;
332
323
333
324
// 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 = [ ] ;
340
344
}
345
+ newState . hooksState . push ( { [ i ] : state . state } ) ;
341
346
componentFound = true ;
342
347
} ) ;
343
348
}
@@ -351,6 +356,7 @@ function createTree(
351
356
isRecoil === false
352
357
) {
353
358
if ( memoizedState . queue ) {
359
+ console . log ( "line 357..." )
354
360
// Hooks states are stored as a linked list using memoizedState.next,
355
361
// so we must traverse through the list and get the states.
356
362
// We then store them along with the corresponding memoizedState.queue,
@@ -363,15 +369,12 @@ function createTree(
363
369
state . component
364
370
) ;
365
371
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 ) {
372
373
newState = { hooksState : [ ] } ;
373
- newState . hooksState . push ( { [ hooksNames [ i ] ] : state . state } ) ;
374
+ } else if ( ! newState . hooksState ) {
375
+ newState . hooksState = [ ] ;
374
376
}
377
+ newState . hooksState . push ( { [ hooksNames [ i ] ] : state . state } ) ;
375
378
componentFound = true ;
376
379
} ) ;
377
380
}
@@ -396,30 +399,33 @@ function createTree(
396
399
// We want to add this fiber node to the snapshot
397
400
if ( componentFound || newState === 'stateless' ) {
398
401
// 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 ] = [ ] ;
405
407
}
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 ++ ;
422
408
}
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 ) {
423
429
// tree object from tree.ts, with addSibling
424
430
newNode = tree . addSibling (
425
431
newState ,
@@ -428,29 +434,7 @@ function createTree(
428
434
rtid ,
429
435
recoilDomNode
430
436
) ;
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 {
454
438
newNode = tree . addChild (
455
439
newState ,
456
440
elementType ? elementType . name : 'nameless' ,
0 commit comments