@@ -15,15 +15,18 @@ import 'core-js';
1515// const componentActionsRecord = require('./masterState');
1616import componentActionsRecord from './masterState' ;
1717
18+ const circularComponentTable = new Set ( ) ;
19+
1820// Carlos: origin is latest snapshot, linking to the fiber,
1921// so changes to origin change app
2022// module.exports = (origin, mode) => {
2123export default ( origin , mode ) => {
2224 // Recursively change state of tree
2325 // Carlos: target is past state we are travelling to
2426
25- function jump ( target ) {
27+ function jump ( target , firstCall = false ) {
2628 // Set the state of the origin tree if the component is stateful
29+
2730 if ( ! target ) return ;
2831 if ( target . state === 'stateless' ) target . children . forEach ( child => jump ( child ) ) ;
2932 const component = componentActionsRecord . getComponentByIndex ( target . componentData . index ) ;
@@ -45,21 +48,26 @@ export default (origin, mode) => {
4548 // const [hooksState] = [target.state.hooksState];
4649 const hooksState = Object . values ( target . state . hooksState [ 0 ] ) [ 0 ] ;
4750 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]);
5052 hooksComponent . dispatch ( hooksState ) ;
5153 }
5254 target . children . forEach ( child => jump ( child ) ) ;
5355 }
5456
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+ // }
5865 }
5966
60- return target => {
67+ return ( target , firstCall = false ) => {
6168 // * Setting mode disables setState from posting messages to window
6269 mode . jumping = true ;
70+ if ( firstCall ) circularComponentTable . clear ( ) ;
6371 jump ( target ) ;
6472 setTimeout ( ( ) => {
6573 mode . jumping = false ;
0 commit comments