mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Bugfix: TypeError curValue is null
This commit is contained in:
parent
d71b36f09e
commit
b65b77f518
1 changed files with 42 additions and 42 deletions
|
|
@ -7,17 +7,19 @@ function dispose(disposable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function typeCast(curValue, newValue) {
|
function typeCast(curValue, newValue) {
|
||||||
switch (typeof curValue)
|
if (null != curValue) {
|
||||||
{
|
switch (typeof curValue)
|
||||||
case 'boolean': return 0 != newValue && !!newValue;
|
{
|
||||||
case 'number': return isFinite(newValue) ? parseFloat(newValue) : 0;
|
case 'boolean': return 0 != newValue && !!newValue;
|
||||||
case 'string': return null != newValue ? '' + newValue : '';
|
case 'number': return isFinite(newValue) ? parseFloat(newValue) : 0;
|
||||||
case 'object':
|
case 'string': return null != newValue ? '' + newValue : '';
|
||||||
if (curValue.constructor.reviveFromJson) {
|
case 'object':
|
||||||
return curValue.constructor.reviveFromJson(newValue);
|
if (curValue.constructor.reviveFromJson) {
|
||||||
|
return curValue.constructor.reviveFromJson(newValue);
|
||||||
|
}
|
||||||
|
if (isArray(curValue) && !isArray(newValue))
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
if (isArray(curValue) && !isArray(newValue))
|
|
||||||
return [];
|
|
||||||
}
|
}
|
||||||
return newValue;
|
return newValue;
|
||||||
}
|
}
|
||||||
|
|
@ -84,39 +86,37 @@ 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]) => {
|
|
||||||
if ('@' !== key[0]) {
|
|
||||||
key = key[0].toLowerCase() + key.substr(1);
|
|
||||||
switch (typeof this[key])
|
|
||||||
{
|
|
||||||
case 'function':
|
|
||||||
if (ko.isObservable(this[key])) {
|
|
||||||
this[key](typeCast(this[key](), value));
|
|
||||||
// console.log('Observable ' + (typeof this[key]()) + ' ' + (model.name) + '.' + key + ' revived');
|
|
||||||
}
|
|
||||||
// else console.log(model.name + '.' + key + ' is a function');
|
|
||||||
break;
|
|
||||||
case 'boolean':
|
|
||||||
case 'number':
|
|
||||||
case 'object':
|
|
||||||
case 'string':
|
|
||||||
this[key] = typeCast(this[key], value);
|
|
||||||
break;
|
|
||||||
// fall through
|
|
||||||
case 'undefined':
|
|
||||||
default:
|
|
||||||
// console.log((typeof this[key])+' '+(model.name)+'.'+key+' not revived');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
console.log(model.name);
|
|
||||||
console.error(e);
|
|
||||||
}
|
}
|
||||||
|
Object.entries(json).forEach(([key, value]) => {
|
||||||
|
if ('@' !== key[0]) try {
|
||||||
|
key = key[0].toLowerCase() + key.substr(1);
|
||||||
|
switch (typeof this[key])
|
||||||
|
{
|
||||||
|
case 'function':
|
||||||
|
if (ko.isObservable(this[key])) {
|
||||||
|
this[key](typeCast(this[key](), value));
|
||||||
|
// console.log('Observable ' + (typeof this[key]()) + ' ' + (model.name) + '.' + key + ' revived');
|
||||||
|
}
|
||||||
|
// else console.log(model.name + '.' + key + ' is a function');
|
||||||
|
break;
|
||||||
|
case 'boolean':
|
||||||
|
case 'number':
|
||||||
|
case 'object':
|
||||||
|
case 'string':
|
||||||
|
this[key] = typeCast(this[key], value);
|
||||||
|
break;
|
||||||
|
// fall through
|
||||||
|
case 'undefined':
|
||||||
|
default:
|
||||||
|
// console.log((typeof this[key])+' '+(model.name)+'.'+key+' not revived');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(model.name + '.' + key);
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue