@@ -88,6 +88,13 @@ async function render({ source, element, data, key, index, currentIndex, update,
8888 remove = remove || data . $filter . remove
8989 }
9090
91+ let type = data . type
92+ if ( ! type && data . method ) {
93+ type = data . method . split ( '.' ) [ 1 ]
94+ } else if ( type == 'key' )
95+ type = 'object'
96+
97+
9198 if ( ! Array . isArray ( element ) && ! ( element instanceof HTMLCollection ) && ! ( element instanceof NodeList ) )
9299 element = [ element ]
93100
@@ -103,6 +110,7 @@ async function render({ source, element, data, key, index, currentIndex, update,
103110 }
104111 }
105112
113+ // TODO: for loop data[type]?
106114 if ( remove ) {
107115 if ( renderedNode . source ) {
108116 if ( key )
@@ -112,39 +120,48 @@ async function render({ source, element, data, key, index, currentIndex, update,
112120 }
113121 }
114122
115- let clone = Array . from ( renderedNode . clones ) [ index ]
123+ let cloneKey
124+ if ( type === 'object' ) {
125+ cloneKey = data [ type ] [ 0 ] . _id ;
126+ } else {
127+ cloneKey = data [ type ] [ 0 ] . name ;
128+ }
129+
130+ let clone = renderedNode . clones . get ( cloneKey )
116131 if ( ! clone ) return
117132
118- renderedNode . clones . delete ( clone [ 0 ] )
119- renderedNodes . delete ( clone [ 1 ] )
120- clone [ 1 ] . remove ( )
133+ renderedNode . clones . delete ( cloneKey )
134+ renderedNodes . delete ( clone )
135+ clone . remove ( )
121136 } else if ( key || Array . isArray ( data ) ) {
122137 if ( update ) {
123138 let clone
139+ if ( type === 'object' ) {
140+ clone = renderedNode . clones . get ( data [ type ] [ 0 ] . _id ) ;
141+ } else {
142+ clone = renderedNode . clones . get ( data [ type ] [ 0 ] . name ) ;
143+ }
124144
125145 if ( ! currentIndex )
126146 currentIndex = data . $filter . currentIndex
127147
128- if ( currentIndex >= 0 )
129- clone = Array . from ( renderedNode . clones ) [ currentIndex ]
130- else
131- clone = Array . from ( renderedNode . clones ) [ index ]
132-
133148 if ( ! clone ) return
149+ for ( let j = 0 ; j < data [ type ] . length ; j ++ ) {
150+ await renderValues ( clone , { object : data [ type ] [ j ] } ) ;
151+ if ( currentIndex >= 0 )
152+ insertElement ( renderedNode , clone , index , currentIndex )
153+ }
154+ } else {
134155
135- await renderValues ( clone [ 1 ] , data ) ;
136- if ( currentIndex >= 0 )
137- insertElement ( renderedNode , clone [ 1 ] , index , currentIndex )
138- }
139-
140- // TODO: if $auto here every subsequent clone will have same value, not replacing here will apply unique value to each clone
141- if ( key === '$auto' )
142- key = key . replace ( / \$ a u t o / g, uuid . generate ( 6 ) ) ;
156+ // TODO: if $auto here every subsequent clone will have same value, not replacing here will apply unique value to each clone
157+ if ( key === '$auto' )
158+ key = key . replace ( / \$ a u t o / g, uuid . generate ( 6 ) ) ;
143159
144- if ( key )
145- element [ i ] . setAttribute ( 'render' , key ) ;
160+ if ( key )
161+ element [ i ] . setAttribute ( 'render' , key ) ;
146162
147- renderTemplate ( element [ i ] , data , key , index ) ;
163+ renderTemplate ( element [ i ] , data , key , index ) ;
164+ }
148165 } else
149166 await renderValues ( element [ i ] , data ) ;
150167
0 commit comments