@@ -25,8 +25,9 @@ export class ReflectionParser {
25
25
parseClassObject ( item : IClassObject ) {
26
26
const Class = Loader . getClass ( item . class ) ;
27
27
const params = item . constructParams ?? [ ] ;
28
- const instance = new Class ( ...params ) ;
29
- return this . parsePropsAndMethods ( instance , item ) ;
28
+ return Promise . all ( params . map ( ( param ) => this . parseBasicType ( param ) ) )
29
+ . then ( ( resultParams ) => new Class ( ...resultParams ) )
30
+ . then ( ( instance ) => this . parsePropsAndMethods ( instance , item ) ) ;
30
31
}
31
32
32
33
parsePropsAndMethods ( instance : any , item : Omit < IClassObject , "class" > ) {
@@ -35,17 +36,15 @@ export class ReflectionParser {
35
36
for ( let methodName in item . methods ) {
36
37
const methodParams = item . methods [ methodName ] ;
37
38
for ( let i = 0 , count = methodParams . length ; i < count ; i ++ ) {
38
- const params = methodParams [ i ] ;
39
- const promise = this . parseMethod ( instance , methodName , params ) ;
40
- promises . push ( promise ) ;
39
+ promises . push ( this . parseMethod ( instance , methodName , methodParams [ i ] ) ) ;
41
40
}
42
41
}
43
42
}
44
43
45
44
if ( item . props ) {
46
45
for ( let key in item . props ) {
47
46
const value = item . props [ key ] ;
48
- const promise = this . parseBasicType ( value ) . then ( ( v ) => {
47
+ const promise = this . parseBasicType ( value , instance [ key ] ) . then ( ( v ) => {
49
48
return ( instance [ key ] = v ) ;
50
49
} ) ;
51
50
promises . push ( promise ) ;
@@ -65,7 +64,7 @@ export class ReflectionParser {
65
64
} ) ;
66
65
}
67
66
68
- parseBasicType ( value : IBasicType ) : Promise < any > {
67
+ parseBasicType ( value : IBasicType , originValue ?: any ) : Promise < any > {
69
68
if ( Array . isArray ( value ) ) {
70
69
return Promise . all ( value . map ( ( item ) => this . parseBasicType ( item ) ) ) ;
71
70
} else if ( typeof value === "object" && value != null ) {
@@ -79,13 +78,28 @@ export class ReflectionParser {
79
78
} else if ( ReflectionParser . _isEntityRef ( value ) ) {
80
79
// entity reference
81
80
return Promise . resolve ( this . _context . entityMap . get ( value . entityId ) ) ;
82
- } else {
83
- // basic type
84
- return Promise . resolve ( value ) ;
81
+ } else if ( originValue ) {
82
+ const promises : Promise < any > [ ] = [ ] ;
83
+ for ( let key in value as any ) {
84
+ if ( key === "methods" ) {
85
+ const methods : any = value [ key ] ;
86
+ for ( let methodName in methods ) {
87
+ const methodParams = methods [ methodName ] ;
88
+ for ( let i = 0 , count = methodParams . length ; i < count ; i ++ ) {
89
+ const params = methodParams [ i ] ;
90
+ const promise = this . parseMethod ( originValue , methodName , params ) ;
91
+ promises . push ( promise ) ;
92
+ }
93
+ }
94
+ } else {
95
+ promises . push ( this . parseBasicType ( value [ key ] , originValue [ key ] ) . then ( ( v ) => ( originValue [ key ] = v ) ) ) ;
96
+ }
97
+ }
98
+ return Promise . all ( promises ) . then ( ( ) => originValue ) ;
85
99
}
86
- } else {
87
- return Promise . resolve ( value ) ;
88
100
}
101
+ // primitive type
102
+ return Promise . resolve ( value ) ;
89
103
}
90
104
91
105
private _getEntityByConfig ( entityConfig : IEntity ) {
0 commit comments