@@ -137,11 +137,12 @@ export class Component extends DataComponent {
137
137
isDataFunction ?: boolean
138
138
) => {
139
139
const data = renderDynamicData ( importData , isDataFunction ) ;
140
+ const dynamicIndex = this . _dynamic . data . data . values . length ;
140
141
const dynamicData = {
141
142
value : data ,
142
- id
143
+ id,
144
+ index : dynamicIndex
143
145
} ;
144
- const dynamicIndex = this . _dynamic . data . data . values . length ;
145
146
this . _dynamic . data . data . values . push ( dynamicData ) ;
146
147
return this . _dynamic . data . data . values [ dynamicIndex ] ;
147
148
} ;
@@ -163,7 +164,12 @@ export class Component extends DataComponent {
163
164
}
164
165
} ;
165
166
const renderNewFunction = this . _isDataFunctions
166
- ? ( id : IdType , index : number , data : any ) => {
167
+ ? (
168
+ id : IdType ,
169
+ index : number ,
170
+ data : any ,
171
+ currentComponent : ComponentDynamicNodeComponentType
172
+ ) => {
167
173
try {
168
174
renderDynamicNodes ( index , data ) ;
169
175
} catch ( err ) {
@@ -174,7 +180,7 @@ export class Component extends DataComponent {
174
180
id ,
175
181
this . _objDataFuntions ,
176
182
index ,
177
- false
183
+ currentComponent
178
184
) ;
179
185
}
180
186
: ( ) => {
@@ -195,12 +201,11 @@ export class Component extends DataComponent {
195
201
) => {
196
202
if ( id !== undefined ) {
197
203
if ( data !== undefined ) {
198
- const dataIndex = data ;
199
204
const val = data ! . value ! ;
200
205
const currentData = data . value ;
201
- if ( checkObject ( dataIndex ) && val [ key ] !== undefined ) {
206
+ if ( checkObject ( data ) && val [ key ] !== undefined ) {
202
207
val [ key ] = attribute ;
203
- renderNewFunction ( id , index , currentData ) ;
208
+ renderNewFunction ( id , index , currentData , currentComponent ) ;
204
209
renderDynamicExportData (
205
210
currentComponent ,
206
211
currentIndex ,
@@ -212,7 +217,7 @@ export class Component extends DataComponent {
212
217
if ( this . data && key && this . data [ key ] ) {
213
218
const currentData = data !== undefined ? data . value : undefined ;
214
219
this . data [ key ] = attribute ;
215
- renderNewFunction ( id , index , currentData ) ;
220
+ renderNewFunction ( id , index , currentData , currentComponent ) ;
216
221
}
217
222
}
218
223
} ;
@@ -254,8 +259,10 @@ export class Component extends DataComponent {
254
259
functions : FunctionsType
255
260
) => {
256
261
const renderNewData = ( value : any ) => {
257
- const val = renderComponentDynamicKeyData ( data , value , false , value ) ;
258
- return val ;
262
+ const { dynamicKey, renderDynamicKeyData } = value ;
263
+ const firstKeyData = data [ dynamicKey ] ;
264
+ const newData = renderDynamicKeyData ( firstKeyData ) ;
265
+ return newData ;
259
266
} ;
260
267
const newObj : ExportTemplateDataType = {
261
268
data : { } ,
@@ -291,7 +298,6 @@ export class Component extends DataComponent {
291
298
functions : FunctionsType
292
299
) => {
293
300
const renderNewData = ( value : string ) => {
294
- // const values = getValues(index);
295
301
const val = renderComponentDynamicKeyData (
296
302
getData ( this . _dynamic . data . data . values , index ) ,
297
303
value
@@ -542,57 +548,44 @@ export class Component extends DataComponent {
542
548
key : string ,
543
549
id : IdType ,
544
550
index : number ,
545
- isRender : boolean = false
551
+ component : ComponentDynamicNodeComponentType
546
552
) => {
547
553
const updateData = ( attr = getDefaultData ( id , key ) ) => {
548
554
return attr ;
549
555
} ;
550
- const component = getComponent ( index ) ;
551
- if ( component . dataFunctions [ name ] !== undefined && isRender ) {
552
- createError ( "Function name is unique" ) ;
553
- } else {
554
- component . dataFunctions [ name ] = ( attribute : any = updateData ) => {
555
- let data : any = undefined ;
556
- let currentIndex = - 1 ;
557
- for ( let i = 0 ; i < this . _dynamic . data . data . values . length ; i ++ ) {
558
- const e = this . _dynamic . data . data . values [ i ] ;
559
- if ( e !== undefined && e . id === id ) {
560
- data = e ;
561
- currentIndex = i ;
562
- break ;
563
- }
564
- }
565
- if ( typeof attribute === "function" ) {
566
- const defaultData =
567
- id !== undefined
568
- ? data !== undefined && data . value
569
- ? data . value [ key ]
570
- : undefined
571
- : this . data && this . data [ key ]
572
- ? this . data [ key ]
573
- : undefined ;
574
- newFunction (
575
- attribute ( defaultData ) ,
576
- key ,
577
- id ,
578
- index ,
579
- component ,
580
- currentIndex ,
581
- data
582
- ) ;
583
- } else {
584
- newFunction (
585
- attribute ,
586
- key ,
587
- id ,
588
- index ,
589
- component ,
590
- currentIndex ,
591
- data
592
- ) ;
593
- }
594
- } ;
595
- }
556
+ component . dataFunctions [ name ] = ( attribute : any = updateData ) => {
557
+ const { value : data } = component ;
558
+ const { index : currentIndex } = data ;
559
+ if ( typeof attribute === "function" ) {
560
+ const defaultData =
561
+ id !== undefined
562
+ ? data !== undefined && data . value
563
+ ? data . value [ key ]
564
+ : undefined
565
+ : this . data && this . data [ key ]
566
+ ? this . data [ key ]
567
+ : undefined ;
568
+ newFunction (
569
+ attribute ( defaultData ) ,
570
+ key ,
571
+ id ,
572
+ index ,
573
+ component ,
574
+ currentIndex as number ,
575
+ data
576
+ ) ;
577
+ } else {
578
+ newFunction (
579
+ attribute ,
580
+ key ,
581
+ id ,
582
+ index ,
583
+ component ,
584
+ currentIndex as number ,
585
+ data
586
+ ) ;
587
+ }
588
+ } ;
596
589
} ;
597
590
const renderScriptsAndStyles = (
598
591
e : Element | null ,
@@ -648,12 +641,14 @@ export class Component extends DataComponent {
648
641
} ;
649
642
const setDynamicNodeComponentType = (
650
643
dataId : number ,
651
- importObject : ImportObjectType | undefined
644
+ importObject : ImportObjectType | undefined ,
645
+ value : DynamicDataType
652
646
) => {
653
647
const DynamicNodeComponent = createComponentDynamicNodeComponentType (
654
648
dataId ,
655
649
getExportObject ( dataId ) ,
656
- importObject
650
+ importObject ,
651
+ value
657
652
) ;
658
653
this . _dynamic . data . data . components . push ( DynamicNodeComponent ) ;
659
654
return DynamicNodeComponent ;
@@ -932,23 +927,27 @@ export class Component extends DataComponent {
932
927
renderScriptsAndStyles ( el , "afterLoad" , importData , index )
933
928
) ;
934
929
const currentId = this . _dynamic . data . data . currentId ;
935
- const data = setData (
936
- currentId ,
937
- importData ,
938
- this . _isDataFunction
939
- ) ?. value ;
930
+ const value = setData ( currentId , importData , this . _isDataFunction ) ;
931
+ const data = value ?. value ;
932
+ const currentComponent : ComponentDynamicNodeComponentType =
933
+ setDynamicNodeComponentType ( index , importObject , value ) ;
940
934
const setDataFunctions = ( ) => {
941
935
if ( this . _isDataFunctions )
942
- renderFunctionsData (
943
- updateFunction ,
944
- this . _dynamic . data . data . currentId ,
945
- this . _objDataFuntions ,
946
- index ,
947
- true
948
- ) ;
936
+ for ( let i = 0 ; i < this . _objDataFuntions . length ; i ++ ) {
937
+ const { key, value } = this . _objDataFuntions [ i ] ;
938
+ if ( currentComponent . dataFunctions [ key ] !== undefined ) {
939
+ createError ( "functionName is unique" ) ;
940
+ } else {
941
+ updateFunction (
942
+ key ,
943
+ value ,
944
+ this . _dynamic . data . data . currentId ,
945
+ index ,
946
+ currentComponent
947
+ ) ;
948
+ }
949
+ }
949
950
} ;
950
- const currentComponent : ComponentDynamicNodeComponentType =
951
- setDynamicNodeComponentType ( index , importObject ) ;
952
951
const runRenderFunction = ( ) =>
953
952
renderFunctions (
954
953
currentComponent . functions ,
@@ -1032,7 +1031,7 @@ export class Component extends DataComponent {
1032
1031
undefined ,
1033
1032
this . _objDataFuntions ,
1034
1033
index ,
1035
- true
1034
+ currentComponent
1036
1035
) ;
1037
1036
}
1038
1037
renderHTML ( e , el , functionsArray , "component" ) ;
0 commit comments