@@ -14,27 +14,68 @@ interface ChangedPropsRecord {
1414 renderType : string ;
1515}
1616
17- const previousHashes = { } ;
17+ interface Hashes {
18+ [ key : string ] : any ; // Index signature for string keys with number values
19+ }
20+
21+ const previousHashes : Hashes = { } ;
22+
23+ const isFirstLevelPropsChild = (
24+ updatedPath : string ,
25+ strPath : string
26+ ) : [ boolean , string [ ] ] => {
27+ const updatedSegments = updatedPath . split ( ',' ) ;
28+ const fullSegments = strPath . split ( ',' ) ;
29+
30+ // Check that strPath actually starts with updatedPath
31+ const startsWithPath = fullSegments . every (
32+ ( seg , i ) => updatedSegments [ i ] === seg
33+ ) ;
34+
35+ if ( ! startsWithPath ) return [ false , [ ] ] ;
36+
37+ // Get the remaining path after the prefix
38+ const remainingSegments = updatedSegments . slice ( fullSegments . length ) ;
39+
40+ const propsCount = remainingSegments . filter ( s => s === 'props' ) . length ;
41+
42+ return [ propsCount < 2 , remainingSegments ] ;
43+ } ;
1844
1945function determineChangedProps (
2046 state : any ,
2147 strPath : string
2248) : ChangedPropsRecord {
2349 let combinedHash = 0 ;
24- const renderType = 'update' ; // Default render type, adjust as needed
50+ let renderType : any ; // Default render type, adjust as needed
51+ const changedProps : Record < string , any > = { } ;
2552 Object . entries ( state . layoutHashes ) . forEach ( ( [ updatedPath , pathHash ] ) => {
26- if ( updatedPath . startsWith ( strPath ) ) {
53+ const [ descendant , remainingSegments ] = isFirstLevelPropsChild (
54+ updatedPath ,
55+ strPath
56+ ) ;
57+ if ( descendant ) {
2758 const previousHash : any = pathOr ( { } , [ updatedPath ] , previousHashes ) ;
2859 combinedHash += pathOr ( 0 , [ 'hash' ] , pathHash ) ;
2960 if ( previousHash !== pathHash ) {
30- previousHash [ updatedPath ] = pathHash ;
61+ if ( updatedPath !== strPath ) {
62+ Object . assign ( changedProps , { [ remainingSegments [ 1 ] ] : true } ) ;
63+ renderType = 'components' ;
64+ } else {
65+ Object . assign (
66+ changedProps ,
67+ pathOr ( { } , [ 'changedProps' ] , pathHash )
68+ ) ;
69+ renderType = pathOr ( { } , [ 'renderType' ] , pathHash ) ;
70+ }
71+ previousHashes [ updatedPath ] = pathHash ;
3172 }
3273 }
3374 } ) ;
3475
3576 return {
3677 hash : combinedHash ,
37- changedProps : { } ,
78+ changedProps,
3879 renderType
3980 } ;
4081}
0 commit comments