@@ -14,27 +14,68 @@ interface ChangedPropsRecord {
14
14
renderType : string ;
15
15
}
16
16
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
+ } ;
18
44
19
45
function determineChangedProps (
20
46
state : any ,
21
47
strPath : string
22
48
) : ChangedPropsRecord {
23
49
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 > = { } ;
25
52
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 ) {
27
58
const previousHash : any = pathOr ( { } , [ updatedPath ] , previousHashes ) ;
28
59
combinedHash += pathOr ( 0 , [ 'hash' ] , pathHash ) ;
29
60
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 ;
31
72
}
32
73
}
33
74
} ) ;
34
75
35
76
return {
36
77
hash : combinedHash ,
37
- changedProps : { } ,
78
+ changedProps,
38
79
renderType
39
80
} ;
40
81
}
0 commit comments