@@ -150,41 +150,13 @@ export default class DataVariable extends Model<DataVariableProps> {
150150 ctx : DataVariableOptions ,
151151 ) {
152152 const { collectionId = '' , variableType, path, defaultValue = '' } = params ;
153- const { em, collectionsStateMap } = ctx ;
153+ const { collectionsStateMap, em } = ctx ;
154+ const collectionItemState = collectionsStateMap ?. [ collectionId ] as DataCollectionState | undefined ;
154155
155- if ( ! collectionsStateMap ) return defaultValue ;
156+ if ( ! collectionItemState || ! variableType ) return defaultValue ;
156157
157- const collectionItem = collectionsStateMap [ collectionId ] ;
158- if ( ! collectionItem ) return defaultValue ;
159-
160- if ( ! variableType ) {
161- em . logError ( `Missing collection variable type for collection: ${ collectionId } ` ) ;
162- return defaultValue ;
163- }
164-
165- if ( variableType === 'currentItem' ) {
166- return DataVariable . resolveCurrentItem ( collectionItem as DataCollectionState , path ) ?? defaultValue ;
167- }
168-
169- const state = collectionItem as DataCollectionState ;
170- return state [ variableType ] ?? defaultValue ;
171- }
172-
173- private static resolveCurrentItem ( collectionItem : DataCollectionState , path : string | undefined ) {
174- const currentItem = collectionItem . currentItem ;
175- if ( ! currentItem ) {
176- return ;
177- }
178-
179- if ( currentItem . type === DataVariableType ) {
180- const resolvedPath = currentItem . path ? `${ currentItem . path } .${ path } ` : path ;
181- return { type : DataVariableType , path : resolvedPath } ;
182- }
183-
184- if ( path && ! ( currentItem as any ) [ path ] ) {
185- return ;
186- }
187-
188- return path ? ( currentItem as any ) [ path ] : currentItem ;
158+ return em . DataSources . getValue ( `${ variableType } ${ path ? `.${ path } ` : '' } ` , defaultValue , {
159+ context : collectionItemState ,
160+ } ) ;
189161 }
190162}
0 commit comments