Skip to content

Commit e3971f9

Browse files
committed
Object uses class name alias first
1 parent 9cc7f3c commit e3971f9

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

js/model.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ export default class Model {
116116
static $newproto(classKey, classProps, className) {
117117
const proto = {};
118118

119+
// Set className alias
120+
if (className) {
121+
Model.alias[className] = classKey;
122+
}
123+
119124
// $className property
120125
Object.defineProperty(proto, '$className', {
121126
value: className || classKey,
@@ -383,14 +388,15 @@ export default class Model {
383388
}
384389

385390
static $castobject(value, model) {
386-
const constructor = Model.constructors[model];
391+
const classKey = Model.alias[model] || model;
392+
const constructor = Model.constructors[classKey];
387393
if (constructor) {
388394
if (value instanceof constructor) {
389395
return value;
390396
}
391397
return new constructor(value);
392398
}
393-
throw new Error(`Undefined Model of type ${model}`);
399+
throw new Error(`Undefined Model of type ${classKey}`);
394400
}
395401

396402
static $castnumber(value) {
@@ -438,6 +444,7 @@ export default class Model {
438444
// GLOBALS
439445

440446
Model.constructors = {};
447+
Model.alias = {};
441448
Model.models = {};
442449
Model.types = {};
443450
Model.primitive = Object.freeze({

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@djthorpe/js-framework",
3-
"version": "0.0.24",
3+
"version": "0.0.25",
44
"description": "Javascript Framework",
55
"main": "dist/js/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)