1
1
function _getClassParser ( typename ) {
2
- return function ( app , data ) {
2
+ return function ( app , data , propInfo , entities ) {
3
3
let ctor = app . getClass ( typename ) ;
4
4
if ( ctor === undefined ) {
5
5
console . warn ( `Can not find class ${ typename } .` ) ;
@@ -17,17 +17,20 @@ function _getClassParser(typename) {
17
17
return null ;
18
18
}
19
19
20
- return instantiate ( app , ctor , data ) ;
20
+ let obj = new ctor ( ) ;
21
+ parse ( app , obj , data , entities ) ;
22
+
23
+ return obj ;
21
24
} ;
22
25
}
23
26
24
27
function _getArrayParser ( elementParser ) {
25
28
if ( elementParser ) {
26
- return function ( app , data ) {
29
+ return function ( app , data , propInfo , entities ) {
27
30
let result = new Array ( data . length ) ;
28
31
29
32
for ( let i = 0 ; i < data . length ; ++ i ) {
30
- result [ i ] = elementParser ( app , data [ i ] ) ;
33
+ result [ i ] = elementParser ( app , data [ i ] , propInfo , entities ) ;
31
34
}
32
35
33
36
return result ;
@@ -160,10 +163,9 @@ function createPrototypeAccessors(app, schema) {
160
163
return prototypeAccessors ;
161
164
}
162
165
163
- function instantiate ( app , ctor , data ) {
164
- let obj = new ctor ( ) ;
166
+ function parse ( app , obj , data , entities ) {
167
+ let proto = obj . constructor ;
165
168
166
- let proto = ctor ;
167
169
while ( proto . __classname__ !== undefined ) {
168
170
if ( proto . hasOwnProperty ( 'schema' ) === false ) {
169
171
proto = Object . getPrototypeOf ( proto ) ;
@@ -187,7 +189,7 @@ function instantiate(app, ctor, data) {
187
189
188
190
//
189
191
if ( parser ) {
190
- let result = parser ( app , value , propInfo ) ;
192
+ let result = parser ( app , value , propInfo , entities ) ;
191
193
obj [ interName ] = result ;
192
194
} else {
193
195
obj [ interName ] = value ;
@@ -196,11 +198,9 @@ function instantiate(app, ctor, data) {
196
198
197
199
proto = Object . getPrototypeOf ( proto ) ;
198
200
}
199
-
200
- return obj ;
201
201
}
202
202
203
203
export default {
204
204
createPrototypeAccessors,
205
- instantiate ,
205
+ parse ,
206
206
} ;
0 commit comments