@@ -19,10 +19,10 @@ const REGEXP_NOTALIASED = /^()(\{\}|\[\])?(\w+)$/i;
1919export default class Model {
2020 constructor ( data ) {
2121 // 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 ] ;
2424 if ( ! proto ) {
25- throw new Error ( `Missing model definition for ${ className } ` ) ;
25+ throw new Error ( `Missing model definition for ${ classKey } ` ) ;
2626 }
2727
2828 // Set prototype of instance prototype
@@ -36,33 +36,33 @@ export default class Model {
3636 if ( typeof classConstructor !== 'function' ) {
3737 throw new Error ( 'Called define without a class constructor' ) ;
3838 }
39- const classKey = className || classConstructor . name ;
39+ const classKey = classConstructor . name ;
4040 if ( Model . constructors [ classKey ] ) {
41- throw new Error ( `Class already defined ${ classKey } ` ) ;
41+ throw new Error ( `Class already defined ${ className || classKey } ` ) ;
4242 }
43- const proto = Model . $newproto ( classKey , classProps ) ;
43+ const proto = Model . $newproto ( classKey , classProps , className ) ;
4444 if ( ! proto ) {
45- throw new Error ( `No prototype for ${ classKey } ` ) ;
45+ throw new Error ( `No prototype for ${ className || classKey } ` ) ;
4646 }
4747 Model . constructors [ classKey ] = classConstructor ;
4848 Model . models [ classKey ] = proto ;
4949 }
5050
51- static $newproto ( className , classProps ) {
51+ static $newproto ( classKey , classProps , className ) {
5252 const proto = { } ;
5353
5454 // $className property
5555 Object . defineProperty ( proto , '$className' , {
56- value : className ,
56+ value : className || classKey ,
5757 writable : false ,
5858 enumerable : false ,
5959 } ) ;
6060
6161 // $type property
62- Model . types [ className ] = new Map ( ) ;
62+ Model . types [ classKey ] = new Map ( ) ;
6363 Object . defineProperty ( proto , '$type' , {
6464 get ( ) {
65- return Model . types [ className ] ;
65+ return Model . types [ classKey ] ;
6666 } ,
6767 enumerable : false ,
6868 } ) ;
@@ -84,7 +84,7 @@ export default class Model {
8484 if ( ! type ) {
8585 throw new Error ( `Unable to parse declaration ${ decl } for ${ key } ` ) ;
8686 } else {
87- Model . types [ className ] . set ( key , type ) ;
87+ Model . types [ classKey ] . set ( key , type ) ;
8888 }
8989 // Create getter and setter
9090 Object . defineProperty ( proto , key , {
0 commit comments