@@ -15,15 +15,18 @@ import 'core-js';
15
15
// const componentActionsRecord = require('./masterState');
16
16
import componentActionsRecord from './masterState' ;
17
17
18
+ const circularComponentTable = new Set ( ) ;
19
+
18
20
// Carlos: origin is latest snapshot, linking to the fiber,
19
21
// so changes to origin change app
20
22
// module.exports = (origin, mode) => {
21
23
export default ( origin , mode ) => {
22
24
// Recursively change state of tree
23
25
// Carlos: target is past state we are travelling to
24
26
25
- function jump ( target ) {
27
+ function jump ( target , firstCall = false ) {
26
28
// Set the state of the origin tree if the component is stateful
29
+
27
30
if ( ! target ) return ;
28
31
if ( target . state === 'stateless' ) target . children . forEach ( child => jump ( child ) ) ;
29
32
const component = componentActionsRecord . getComponentByIndex ( target . componentData . index ) ;
@@ -45,21 +48,26 @@ export default (origin, mode) => {
45
48
// const [hooksState] = [target.state.hooksState];
46
49
const hooksState = Object . values ( target . state . hooksState [ 0 ] ) [ 0 ] ;
47
50
if ( hooksComponent && hooksComponent . dispatch ) {
48
- //hooksComponent.dispatch(Object.values(target.state.hooksState[0])[0]);
49
- console . log ( 'setting hooksState of component id:' , target . state . hooksState [ 1 ] , 'to:' , hooksState )
51
+ // hooksComponent.dispatch(Object.values(target.state.hooksState[0])[0]);
50
52
hooksComponent . dispatch ( hooksState ) ;
51
53
}
52
54
target . children . forEach ( child => jump ( child ) ) ;
53
55
}
54
56
55
- if ( ( ! component || ! component . state ) && ! target . state . hooksState ) {
56
- target . children . forEach ( child => jump ( child ) ) ;
57
- }
57
+ target . children . forEach ( child => {
58
+ if ( ! circularComponentTable . has ( child ) ) {
59
+ circularComponentTable . add ( child ) ;
60
+ jump ( child ) ;
61
+ }
62
+ } ) ;
63
+
64
+ // }
58
65
}
59
66
60
- return target => {
67
+ return ( target , firstCall = false ) => {
61
68
// * Setting mode disables setState from posting messages to window
62
69
mode . jumping = true ;
70
+ if ( firstCall ) circularComponentTable . clear ( ) ;
63
71
jump ( target ) ;
64
72
setTimeout ( ( ) => {
65
73
mode . jumping = false ;
0 commit comments