File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -116,6 +116,11 @@ export default class Model {
116
116
static $newproto ( classKey , classProps , className ) {
117
117
const proto = { } ;
118
118
119
+ // Set className alias
120
+ if ( className ) {
121
+ Model . alias [ className ] = classKey ;
122
+ }
123
+
119
124
// $className property
120
125
Object . defineProperty ( proto , '$className' , {
121
126
value : className || classKey ,
@@ -383,14 +388,15 @@ export default class Model {
383
388
}
384
389
385
390
static $castobject ( value , model ) {
386
- const constructor = Model . constructors [ model ] ;
391
+ const classKey = Model . alias [ model ] || model ;
392
+ const constructor = Model . constructors [ classKey ] ;
387
393
if ( constructor ) {
388
394
if ( value instanceof constructor ) {
389
395
return value ;
390
396
}
391
397
return new constructor ( value ) ;
392
398
}
393
- throw new Error ( `Undefined Model of type ${ model } ` ) ;
399
+ throw new Error ( `Undefined Model of type ${ classKey } ` ) ;
394
400
}
395
401
396
402
static $castnumber ( value ) {
@@ -438,6 +444,7 @@ export default class Model {
438
444
// GLOBALS
439
445
440
446
Model . constructors = { } ;
447
+ Model . alias = { } ;
441
448
Model . models = { } ;
442
449
Model . types = { } ;
443
450
Model . primitive = Object . freeze ( {
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @djthorpe/js-framework" ,
3
- "version" : " 0.0.24 " ,
3
+ "version" : " 0.0.25 " ,
4
4
"description" : " Javascript Framework" ,
5
5
"main" : " dist/js/index.js" ,
6
6
"scripts" : {
You can’t perform that action at this time.
0 commit comments