@@ -19,10 +19,10 @@ const REGEXP_NOTALIASED = /^()(\{\}|\[\])?(\w+)$/i;
19
19
export default class Model {
20
20
constructor ( data ) {
21
21
// Get prototype
22
- const className = this . constructor . name ;
23
- const proto = Model . models [ className ] ;
22
+ const classKey = this . constructor . name ;
23
+ const proto = Model . models [ classKey ] ;
24
24
if ( ! proto ) {
25
- throw new Error ( `Missing model definition for ${ className } ` ) ;
25
+ throw new Error ( `Missing model definition for ${ classKey } ` ) ;
26
26
}
27
27
28
28
// Set prototype of instance prototype
@@ -36,33 +36,33 @@ export default class Model {
36
36
if ( typeof classConstructor !== 'function' ) {
37
37
throw new Error ( 'Called define without a class constructor' ) ;
38
38
}
39
- const classKey = className || classConstructor . name ;
39
+ const classKey = classConstructor . name ;
40
40
if ( Model . constructors [ classKey ] ) {
41
- throw new Error ( `Class already defined ${ classKey } ` ) ;
41
+ throw new Error ( `Class already defined ${ className || classKey } ` ) ;
42
42
}
43
- const proto = Model . $newproto ( classKey , classProps ) ;
43
+ const proto = Model . $newproto ( classKey , classProps , className ) ;
44
44
if ( ! proto ) {
45
- throw new Error ( `No prototype for ${ classKey } ` ) ;
45
+ throw new Error ( `No prototype for ${ className || classKey } ` ) ;
46
46
}
47
47
Model . constructors [ classKey ] = classConstructor ;
48
48
Model . models [ classKey ] = proto ;
49
49
}
50
50
51
- static $newproto ( className , classProps ) {
51
+ static $newproto ( classKey , classProps , className ) {
52
52
const proto = { } ;
53
53
54
54
// $className property
55
55
Object . defineProperty ( proto , '$className' , {
56
- value : className ,
56
+ value : className || classKey ,
57
57
writable : false ,
58
58
enumerable : false ,
59
59
} ) ;
60
60
61
61
// $type property
62
- Model . types [ className ] = new Map ( ) ;
62
+ Model . types [ classKey ] = new Map ( ) ;
63
63
Object . defineProperty ( proto , '$type' , {
64
64
get ( ) {
65
- return Model . types [ className ] ;
65
+ return Model . types [ classKey ] ;
66
66
} ,
67
67
enumerable : false ,
68
68
} ) ;
@@ -84,7 +84,7 @@ export default class Model {
84
84
if ( ! type ) {
85
85
throw new Error ( `Unable to parse declaration ${ decl } for ${ key } ` ) ;
86
86
} else {
87
- Model . types [ className ] . set ( key , type ) ;
87
+ Model . types [ classKey ] . set ( key , type ) ;
88
88
}
89
89
// Create getter and setter
90
90
Object . defineProperty ( proto , key , {
0 commit comments