@@ -20,7 +20,8 @@ import {
20
20
propOr ,
21
21
path as rpath ,
22
22
pathOr ,
23
- type
23
+ type ,
24
+ toPairs
24
25
} from 'ramda' ;
25
26
import { notifyObservers , updateProps } from './actions' ;
26
27
import isSimpleComponent from './isSimpleComponent' ;
@@ -249,24 +250,54 @@ class BaseTreeContainer extends Component {
249
250
250
251
for ( let i = 0 ; i < childrenProps . length ; i ++ ) {
251
252
const childrenProp = childrenProps [ i ] ;
253
+
254
+ const handleObject = ( obj , opath ) => {
255
+ return keys ( obj ) . reduce ( ( acc , k ) => {
256
+ const node = acc [ k ] ;
257
+ return {
258
+ ...acc ,
259
+ [ k ] : this . wrapChildrenProp (
260
+ node ,
261
+ concat ( this . props . _dashprivate_path , [ ...opath , k ] )
262
+ )
263
+ } ;
264
+ } , obj ) ;
265
+ } ;
266
+
252
267
if ( childrenProp . includes ( '.' ) ) {
253
268
let path = childrenProp . split ( '.' ) ;
254
269
let node ;
255
270
let nodeValue ;
256
271
if ( childrenProp . includes ( '[]' ) ) {
257
272
let frontPath = [ ] ,
258
273
backPath = [ ] ,
259
- found = false ;
274
+ found = false ,
275
+ hasObject = false ;
260
276
path . forEach ( p => {
261
277
if ( ! found ) {
262
278
if ( p . includes ( '[]' ) ) {
263
279
found = true ;
264
- frontPath . push ( p . replace ( '[]' , '' ) ) ;
280
+ if ( p . includes ( '{}' ) ) {
281
+ hasObject = true ;
282
+ frontPath . push (
283
+ p . replace ( '{}' , '' ) . replace ( '[]' , '' )
284
+ ) ;
285
+ } else {
286
+ frontPath . push ( p . replace ( '[]' , '' ) ) ;
287
+ }
288
+ } else if ( p . includes ( '{}' ) ) {
289
+ hasObject = true ;
290
+ frontPath . push ( p . replace ( '{}' , '' ) ) ;
265
291
} else {
266
292
frontPath . push ( p ) ;
267
293
}
268
294
} else {
269
- backPath . push ( p ) ;
295
+ if ( p . includes ( '{}' ) ) {
296
+ hasObject = true ;
297
+ backPath . push ( p . replace ( '{}' , '' ) ) ;
298
+ } else {
299
+ backPath . push ( p ) ;
300
+ }
270
301
}
271
302
} ) ;
272
303
@@ -278,38 +309,115 @@ class BaseTreeContainer extends Component {
278
309
if ( ! firstNode ) {
279
310
continue ;
280
311
}
312
+
281
313
nodeValue = node . map ( ( element , i ) => {
282
314
const elementPath = concat (
283
315
frontPath ,
284
316
concat ( [ i ] , backPath )
285
317
) ;
286
- return assocPath (
287
- backPath ,
288
- this . wrapChildrenProp (
318
+ let listValue ;
319
+ if ( hasObject ) {
320
+ listValue = handleObject ( element , elementPath ) ;
321
+ } else {
322
+ listValue = this . wrapChildrenProp (
289
323
rpath ( backPath , element ) ,
290
324
elementPath
291
- ) ,
292
- element
293
- ) ;
325
+ ) ;
326
+ }
327
+ return assocPath ( backPath , listValue , element ) ;
294
328
} ) ;
295
329
path = frontPath ;
296
330
} else {
297
- node = rpath ( path , props ) ;
298
- if ( node === undefined ) {
299
- continue ;
331
+ if ( childrenProp . includes ( '{}' ) ) {
332
+ // Only supports one level of nesting.
333
+ const front = [ ] ;
334
+ let dynamic = [ ] ;
335
+ let hasBack = false ;
336
+ const backPath = [ ] ;
337
+
338
+ for ( let j = 0 ; j < path . length ; j ++ ) {
339
+ const cur = path [ j ] ;
340
+ if ( cur . includes ( '{}' ) ) {
341
+ dynamic = concat ( front , [
342
+ cur . replace ( '{}' , '' )
343
+ ] ) ;
344
+ if ( j < path . length - 1 ) {
345
+ hasBack = true ;
346
+ }
347
+ } else {
348
+ if ( hasBack ) {
349
+ backPath . push ( cur ) ;
350
+ } else {
351
+ front . push ( cur ) ;
352
+ }
353
+ }
354
+ }
355
+
356
+ const dynValue = rpath ( dynamic , props ) ;
357
+ if ( dynValue !== undefined ) {
358
+ nodeValue = toPairs ( dynValue ) . reduce (
359
+ ( acc , [ k , d ] ) => ( {
360
+ ...acc ,
361
+ [ k ] : this . wrapChildrenProp (
362
+ hasBack ? rpath ( backPath , d ) : d ,
363
+ hasBack
364
+ ? concat (
365
+ dynamic ,
366
+ concat ( [ k ] , backPath )
367
+ )
368
+ : concat ( dynamic , [ k ] )
369
+ )
370
+ } ) ,
371
+ { }
372
+ ) ;
373
+ path = dynamic ;
374
+ }
375
+ } else {
376
+ node = rpath ( path , props ) ;
377
+ if ( node === undefined ) {
378
+ continue ;
379
+ }
380
+ nodeValue = this . wrapChildrenProp ( node , path ) ;
300
381
}
301
- nodeValue = this . wrapChildrenProp ( node , path ) ;
302
382
}
303
383
props = assocPath ( path , nodeValue , props ) ;
304
- continue ;
305
- }
306
- const node = props [ childrenProp ] ;
307
- if ( node !== undefined ) {
308
- props = assoc (
309
- childrenProp ,
310
- this . wrapChildrenProp ( node , [ childrenProp ] ) ,
311
- props
312
- ) ;
384
+ } else {
385
+ if ( childrenProp . includes ( '{}' ) ) {
386
+ let opath = childrenProp . replace ( '{}' , '' ) ;
387
+ const isArray = childrenProp . includes ( '[]' ) ;
388
+ if ( isArray ) {
389
+ opath = opath . replace ( '[]' , '' ) ;
390
+ }
391
+ const node = props [ opath ] ;
392
+
393
+ if ( node !== undefined ) {
394
+ if ( isArray ) {
395
+ for ( let j = 0 ; j < node . length ; j ++ ) {
396
+ const aPath = concat ( [ opath ] , [ j ] ) ;
397
+ props = assocPath (
398
+ aPath ,
399
+ handleObject ( node [ j ] , aPath ) ,
400
+ props
401
+ ) ;
402
+ }
403
+ } else {
404
+ props = assoc (
405
+ opath ,
406
+ handleObject ( node , [ opath ] ) ,
407
+ props
408
+ ) ;
409
+ }
410
+ }
411
+ } else {
412
+ const node = props [ childrenProp ] ;
413
+ if ( node !== undefined ) {
414
+ props = assoc (
415
+ childrenProp ,
416
+ this . wrapChildrenProp ( node , [ childrenProp ] ) ,
417
+ props
418
+ ) ;
419
+ }
420
+ }
313
421
}
314
422
}
315
423
0 commit comments