1+ import { Base } from "./base" ;
12import { IQuestion } from "./base-interfaces" ;
23import { Helpers , HashTable } from "./helpers" ;
34
@@ -6,6 +7,9 @@ export interface IValueGetterItem {
67 index ?: number ;
78}
89export interface IValueGetterInfo {
10+ obj ?: IObjectValueContext ;
11+ propObj ?: any ;
12+ propName ?: string ;
913 context ?: IValueGetterContext ;
1014 requireStrictCompare ?: boolean ;
1115 isFound ?: boolean ;
@@ -14,9 +18,17 @@ export interface IValueGetterInfo {
1418export interface IObjectValueContext {
1519 getValueGetterContext ( isUnwrapped ?: boolean ) : IValueGetterContext ;
1620}
21+ export interface IValueGetterContextGetValueParams {
22+ path : Array < IValueGetterItem > ;
23+ isRoot : boolean ;
24+ index : number ;
25+ createObjects ?: boolean ;
26+ isProperty ?: boolean ;
27+ }
1728export interface IValueGetterContext {
18- getValue ( path : Array < IValueGetterItem > , isRoot : boolean , index : number , createObjects : boolean ) : IValueGetterInfo ;
29+ getValue ( params : IValueGetterContextGetValueParams ) : IValueGetterInfo ;
1930 getTextValue ?( name : string , value : any , isDisplayValue : boolean ) : string ;
31+ getObj ?( ) : Base ;
2032 getRootObj ?( ) : IObjectValueContext ;
2133 getQuestion ?( ) : IQuestion ;
2234}
@@ -31,6 +43,8 @@ export interface IReturnValue {
3143 isFound : boolean ;
3244 value : any ;
3345 question ?: IQuestion ;
46+ propObj ?: any ;
47+ propName ?: string ;
3448 strictCompare ?: boolean ;
3549}
3650export class ValueGetter {
@@ -60,6 +74,8 @@ export class ValueGetter {
6074 res . isFound = true ;
6175 res . value = info . value ;
6276 res . strictCompare = info . requireStrictCompare ;
77+ res . propObj = info . propObj ;
78+ res . propName = info . propName ;
6379 if ( info . context ) {
6480 if ( params . isText && info . context . getTextValue ) {
6581 res . value = info . context . getTextValue ( name , res . value , params . isDisplayValue ) ;
@@ -119,8 +135,12 @@ export class ValueGetter {
119135 private run ( name : string , context : IValueGetterContext , createObjects : boolean ) : any {
120136 if ( ! context ) return undefined ;
121137 let path = this . getPath ( name ) ;
122- const info = context . getValue ( path , true , - 1 , createObjects ) ;
123- return ! ! info && info . isFound ? info : undefined ;
138+ const isProperty = path . length > 0 && path [ 0 ] . name [ 0 ] === "$" ;
139+ if ( isProperty ) {
140+ path [ 0 ] . name = path [ 0 ] . name . substring ( 1 ) ;
141+ }
142+ const info = context . getValue ( { path, isRoot : true , index : - 1 , createObjects, isProperty } ) ;
143+ return info ?. isFound ? info : undefined ;
124144 }
125145 public getPath ( name : string ) : Array < IValueGetterItem > {
126146 const path : Array < IValueGetterItem > = [ ] ;
@@ -154,16 +174,21 @@ export class ValueGetter {
154174}
155175export class ValueGetterContextCore implements IValueGetterContext {
156176 constructor ( ) { }
157- public getValue ( path : Array < IValueGetterItem > , isRoot : boolean , index : number , createObjects : boolean ) : IValueGetterInfo {
177+ public getValue ( params : IValueGetterContextGetValueParams ) : IValueGetterInfo {
158178 let pIndex = 0 ;
179+ const path = params . path ;
159180 const res : IValueGetterInfo = { isFound : false , value : this . getInitialvalue ( ) , context : this } ;
160181 while ( pIndex < path . length ) {
161182 pIndex = this . checkValueByPath ( path , pIndex , res ) ;
162183 if ( ! res . isFound ) return undefined ;
184+ if ( params . isProperty ) {
185+ if ( ! ! res . obj ) return new PropertyGetterContext ( res . obj ) . getValue ( { path : path . slice ( 1 ) , isRoot : false , index : - 1 , isProperty : true } ) ;
186+ if ( ! res . context ) return undefined ;
187+ }
163188 const item = path [ pIndex ] ;
164189 pIndex ++ ;
165190 if ( res . context !== this && ! ! res . context ) {
166- return res . context . getValue ( [ ] . concat ( path . slice ( pIndex ) ) , false , item . index , createObjects ) ;
191+ return res . context . getValue ( { path : path . slice ( pIndex ) , isRoot : false , index : item . index , createObjects : params . createObjects , isProperty : params . isProperty } ) ;
167192 }
168193 if ( item . index !== undefined ) {
169194 this . updateItemByIndex ( item . index , res ) ;
@@ -259,21 +284,35 @@ export class VariableGetterContext extends ValueGetterContextCore {
259284 }
260285}
261286export class PropertyGetterContext extends VariableGetterContext {
287+ private lastObj : any ;
288+ private lastName : string ;
262289 constructor ( private obj : any ) {
263290 super ( obj ) ;
264291 }
292+ public getValue ( params : IValueGetterContextGetValueParams ) : IValueGetterInfo {
293+ this . lastObj = undefined ;
294+ this . lastName = undefined ;
295+ const res = super . getValue ( params ) ;
296+ if ( res ?. isFound ) {
297+ res . propObj = this . lastObj ;
298+ res . propName = this . lastName ;
299+ }
300+ return res ;
301+ }
265302 protected getValueByItemCore ( obj : any , name : string ) : any {
266303 if ( ! obj || ! name ) return undefined ;
304+ this . lastObj = obj ;
305+ this . lastName = name ;
267306 return obj [ name ] ;
268307 }
269308}
270309export class VariableGetterContextEx extends VariableGetterContext {
271310 constructor ( variables : HashTable < any > , private second : IValueGetterContext ) {
272311 super ( variables ) ;
273312 }
274- public getValue ( path : Array < IValueGetterItem > , isRoot : boolean , index : number , createObjects : boolean ) : IValueGetterInfo {
275- const res = super . getValue ( path , isRoot , index , createObjects ) ;
276- return ! this . second || res ?. isFound ? res : this . second . getValue ( path , isRoot , index , createObjects ) ;
313+ public getValue ( params : IValueGetterContextGetValueParams ) : IValueGetterInfo {
314+ const res = super . getValue ( params ) ;
315+ return ! this . second || res ?. isFound ? res : this . second . getValue ( params ) ;
277316 }
278317}
279318
@@ -304,6 +343,12 @@ export class ProcessValue {
304343 public getValueInfo ( valueInfo : any ) {
305344 if ( ! ! this . context ) {
306345 const cRes = this . getValueInfoByContext ( valueInfo . name ) ;
346+ if ( cRes . isFound ) {
347+ const obj : Base = this . context . getObj ? this . context . getObj ( ) : null ;
348+ if ( ! ! obj && ! ! cRes . propObj && ( cRes . propObj instanceof Base ) ) {
349+ obj . addPropertyDependency ( cRes . propObj , cRes . propName ) ;
350+ }
351+ }
307352 valueInfo . value = cRes . value ;
308353 valueInfo . hasValue = cRes . isFound ;
309354 valueInfo . strictCompare = cRes . strictCompare ;
0 commit comments