@@ -27,177 +27,17 @@ export const apiRequests = [
27
27
'loginRequest'
28
28
] ;
29
29
30
- function handleChildrenPropsUpdate ( {
31
- component,
32
- config,
33
- action,
34
- actionPath,
35
- state
36
- } ) {
37
- const childrenProps = pathOr (
38
- [ ] ,
39
- [ 'children_props' , component ?. namespace , component ?. type ] ,
40
- config
41
- ) ;
42
-
43
- // Ensure "children" is always considered
44
- if ( ! childrenProps . includes ( 'children' ) ) {
45
- childrenProps . push ( 'children' ) ;
46
- }
47
-
48
- childrenProps . forEach ( childrenProp => {
49
- const segments = childrenProp . split ( '.' ) ;
50
- const includesArray = childrenProp . includes ( '[]' ) ;
51
- const includesObject = childrenProp . includes ( '{}' ) ;
52
-
53
- const cleanSegments = segments . map ( s =>
54
- s . replace ( '[]' , '' ) . replace ( '{}' , '' )
55
- ) ;
56
-
57
- const getFrontBack = ( ) => {
58
- const front = [ ] ;
59
- const back = [ ] ;
60
- let found = false ;
61
-
62
- for ( const segment of segments ) {
63
- const clean = segment . replace ( '{}' , '' ) . replace ( '[]' , '' ) ;
64
- if (
65
- ! found &&
66
- ( segment . includes ( '[]' ) || segment . includes ( '{}' ) )
67
- ) {
68
- found = true ;
69
- front . push ( clean ) ;
70
- } else if ( found ) {
71
- back . push ( clean ) ;
72
- } else {
73
- front . push ( clean ) ;
74
- }
75
- }
76
-
77
- return [ front , back ] ;
78
- } ;
79
-
80
- const [ frontPath , backPath ] = getFrontBack ( ) ;
81
- const basePath = [ ...actionPath , 'props' , ...frontPath ] ;
82
- const propRoot = pathOr ( { } , [ 'payload' , 'props' ] , action ) ;
83
-
84
- if ( ! ( cleanSegments [ 0 ] in propRoot ) ) return ;
85
-
86
- const _fullValue = path ( cleanSegments , propRoot ) ;
87
- const fullValues = Array . isArray ( _fullValue )
88
- ? _fullValue
89
- : [ _fullValue ] ;
90
-
91
- fullValues . forEach ( ( fullValue , y ) => {
92
- if ( includesArray ) {
93
- if ( Array . isArray ( fullValue ) ) {
94
- fullValue . forEach ( ( el , i ) => {
95
- let value = el ;
96
- if ( includesObject && backPath . length ) {
97
- value = path ( backPath , el ) ;
98
- }
99
-
100
- if ( value ) {
101
- const itempath = [ ...basePath , i , ...backPath ] ;
102
- state = adjustHashes ( state , {
103
- payload : {
104
- itempath,
105
- props : value ?. props ,
106
- component : value ,
107
- config
108
- }
109
- } ) ;
110
- }
111
- } ) ;
112
- } else if (
113
- fullValue &&
114
- typeof fullValue === 'object' &&
115
- ! ( 'props' in fullValue )
116
- ) {
117
- Object . entries ( fullValue ) . forEach ( ( [ key , value ] ) => {
118
- const finalVal = backPath . length
119
- ? path ( backPath , value )
120
- : value ;
121
- if ( finalVal ) {
122
- const itempath = [ ...basePath , y , key , ...backPath ] ;
123
- state = adjustHashes ( state , {
124
- payload : {
125
- itempath,
126
- props : finalVal ?. props ,
127
- component : finalVal ,
128
- config
129
- }
130
- } ) ;
131
- }
132
- } ) ;
133
- } else if ( fullValue ) {
134
- const itempath = [ ...basePath , ...backPath ] ;
135
- if ( Array . isArray ( _fullValue ) ) {
136
- itempath . push ( y ) ;
137
- }
138
- state = adjustHashes ( state , {
139
- payload : {
140
- itempath,
141
- props : fullValue ?. props ,
142
- component : fullValue ,
143
- config
144
- }
145
- } ) ;
146
- }
147
- } else if ( includesObject ) {
148
- if ( fullValue && typeof fullValue === 'object' ) {
149
- Object . entries ( fullValue ) . forEach ( ( [ key , value ] ) => {
150
- const finalVal = backPath . length
151
- ? path ( backPath , value )
152
- : value ;
153
- if ( finalVal ) {
154
- const itempath = [ ...basePath , key , ...backPath ] ;
155
- state = adjustHashes ( state , {
156
- payload : {
157
- itempath,
158
- props : finalVal ?. props ,
159
- component : finalVal ,
160
- config
161
- }
162
- } ) ;
163
- }
164
- } ) ;
165
- }
166
- } else {
167
- if ( fullValue ) {
168
- const itempath = [ ...actionPath , 'props' , ...cleanSegments ] ;
169
- if ( Array . isArray ( _fullValue ) ) {
170
- itempath . push ( y ) ;
171
- }
172
- state = adjustHashes ( state , {
173
- payload : {
174
- itempath,
175
- props : fullValue ?. props ,
176
- component : fullValue ,
177
- config
178
- }
179
- } ) ;
180
- }
181
- }
182
- } ) ;
183
- } ) ;
184
-
185
- return state ;
186
- }
187
-
188
30
function adjustHashes ( state , action ) {
189
31
const actionPath = action . payload . itempath ;
190
32
const strPath = stringifyPath ( actionPath ) ;
191
- const prev = pathOr ( 0 , [ strPath ] , state ) ;
192
- const { component, config} = action . payload ;
193
- state = assoc ( strPath , prev + 1 , state ) ;
194
- state = handleChildrenPropsUpdate ( {
195
- component,
196
- config,
197
- action,
198
- actionPath,
33
+ const prev = pathOr ( '0' , [ strPath ] , state ) ;
34
+ state = assoc (
35
+ strPath ,
36
+ `${ parseInt ( prev . split ( ' -' ) [ 0 ] ) + 1 } - ${ JSON . stringify (
37
+ action . payload . props
38
+ ) } `,
199
39
state
200
- } ) ;
40
+ ) ;
201
41
return state ;
202
42
}
203
43
0 commit comments