Bugfix: TypeError curValue is null

This commit is contained in:
djmaze 2021-09-03 09:30:53 +02:00
parent d71b36f09e
commit b65b77f518

View file

@ -7,6 +7,7 @@ function dispose(disposable) {
} }
function typeCast(curValue, newValue) { function typeCast(curValue, newValue) {
if (null != curValue) {
switch (typeof curValue) switch (typeof curValue)
{ {
case 'boolean': return 0 != newValue && !!newValue; case 'boolean': return 0 != newValue && !!newValue;
@ -19,6 +20,7 @@ function typeCast(curValue, newValue) {
if (isArray(curValue) && !isArray(newValue)) if (isArray(curValue) && !isArray(newValue))
return []; return [];
} }
}
return newValue; return newValue;
} }
@ -84,12 +86,11 @@ export class AbstractModel {
revivePropertiesFromJson(json) { revivePropertiesFromJson(json) {
let model = this.constructor; let model = this.constructor;
try {
if (!model.validJson(json)) { if (!model.validJson(json)) {
return false; return false;
} }
Object.entries(json).forEach(([key, value]) => { Object.entries(json).forEach(([key, value]) => {
if ('@' !== key[0]) { if ('@' !== key[0]) try {
key = key[0].toLowerCase() + key.substr(1); key = key[0].toLowerCase() + key.substr(1);
switch (typeof this[key]) switch (typeof this[key])
{ {
@ -111,12 +112,11 @@ export class AbstractModel {
default: default:
// console.log((typeof this[key])+' '+(model.name)+'.'+key+' not revived'); // console.log((typeof this[key])+' '+(model.name)+'.'+key+' not revived');
} }
}
});
} catch (e) { } catch (e) {
console.log(model.name); console.log(model.name + '.' + key);
console.error(e); console.error(e);
} }
});
return true; return true;
} }