@@ -20,14 +20,14 @@ const TreeModelHelper = {
2020 copyItemsToTree (
2121 sourceTree : TaskModel [ ] ,
2222 destTree : TaskInMyDay [ ] ,
23- keysToTask : string [ ]
23+ keysToNode : string [ ]
2424 ) {
2525 let keyIdx = 0 ;
2626 let sourceChildren = sourceTree ;
2727 let destChildren = destTree ;
2828
29- if ( keysToTask . length === 1 ) {
30- const source = sourceChildren . find ( ( node ) => node . key === keysToTask [ 0 ] ) ;
29+ if ( keysToNode . length === 1 ) {
30+ const source = sourceChildren . find ( ( node ) => node . key === keysToNode [ 0 ] ) ;
3131 if ( source ) {
3232 destChildren . push ( TaskFactory . createTaskModelProxy ( source ) ) ;
3333 }
@@ -36,62 +36,64 @@ const TreeModelHelper = {
3636
3737 do {
3838 const nextSourceNode = sourceChildren . find (
39- ( task ) => task . key === keysToTask [ keyIdx ]
39+ ( task ) => task . key === keysToNode [ keyIdx ]
4040 ) ;
4141 if ( ! nextSourceNode ) {
4242 return false ;
4343 }
4444
4545 const nextDestNode = destChildren . find (
46- ( task ) => task . key === keysToTask [ keyIdx ]
46+ ( task ) => task . key === keysToNode [ keyIdx ]
4747 ) ;
4848
4949 if ( nextDestNode ) {
50+ // We already have a copy of node, go on
5051 keyIdx ++ ;
5152 sourceChildren = nextSourceNode . children ;
5253 destChildren = nextDestNode . children ;
5354 } else {
54- const restKeysToTask = keysToTask . slice ( keyIdx ) ;
55+ // Make a copy from this node
56+ const restKeysToNode = keysToNode . slice ( keyIdx ) ;
5557 return TreeModelHelper . copySubItemsToTree (
5658 sourceChildren ,
5759 destChildren ,
58- restKeysToTask
60+ restKeysToNode
5961 ) ;
6062 }
61- } while ( keyIdx < keysToTask . length ) ;
63+ } while ( keyIdx < keysToNode . length ) ;
6264
6365 return true ;
6466 } ,
6567
6668 copySubItemsToTree (
6769 sourceTree : TaskModel [ ] ,
6870 destTree : TaskInMyDay [ ] ,
69- keysToTask : string [ ]
71+ keysToNode : string [ ]
7072 ) {
7173 if ( ! sourceTree ) {
7274 return false ;
7375 }
7476
7577 let keyIdx = 0 ;
7678 let destChildren = destTree ;
77- let sourceNode = sourceTree . find ( ( node ) => node . key === keysToTask [ keyIdx ] ) ;
79+ let sourceNode = sourceTree . find ( ( node ) => node . key === keysToNode [ keyIdx ] ) ;
7880
7981 if ( ! sourceNode ) {
8082 return false ;
8183 }
8284
8385 while ( true ) {
84- const copy = TaskFactory . createTaskModelProxy ( sourceNode ) ;
85- destChildren . push ( copy ) ;
86+ const copyNode = TaskFactory . createTaskModelProxy ( sourceNode ) ;
87+ destChildren . push ( copyNode ) ;
8688
8789 keyIdx ++ ;
88- if ( keyIdx === keysToTask . length ) {
90+ if ( keyIdx === keysToNode . length ) {
8991 return true ;
9092 }
9193
92- destChildren = copy . children ;
94+ destChildren = copyNode . children ;
9395 sourceNode = sourceNode . children . find (
94- ( node ) => node . key === keysToTask [ keyIdx ]
96+ ( node ) => node . key === keysToNode [ keyIdx ]
9597 ) ;
9698 if ( ! sourceNode ) {
9799 return false ;
0 commit comments