mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-06-26 16:26:44 +03:00
Bugfix: revivePropertiesFromJson always set observables
This commit is contained in:
parent
65030bf8d8
commit
cc04e42444
2 changed files with 9 additions and 17 deletions
|
|
@ -13,10 +13,10 @@ function typeCast(curValue, newValue) {
|
|||
case 'string': return null != newValue ? '' + newValue : '';
|
||||
case 'object':
|
||||
if (curValue.constructor.reviveFromJson) {
|
||||
return curValue.constructor.reviveFromJson(newValue) || undefined;
|
||||
return curValue.constructor.reviveFromJson(newValue);
|
||||
}
|
||||
if (!Array.isArray(curValue) || !Array.isArray(newValue))
|
||||
return undefined;
|
||||
if (Array.isArray(curValue) && !Array.isArray(newValue))
|
||||
return [];
|
||||
}
|
||||
return newValue;
|
||||
}
|
||||
|
|
@ -95,12 +95,8 @@ export class AbstractModel {
|
|||
{
|
||||
case 'function':
|
||||
if (ko.isObservable(this[key])) {
|
||||
value = typeCast(this[key](), value);
|
||||
if (undefined !== value) {
|
||||
this[key](value);
|
||||
break;
|
||||
}
|
||||
// console.log((typeof this[key]())+' '+(model.name)+'.'+key+' not revived');
|
||||
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;
|
||||
|
|
@ -108,11 +104,8 @@ export class AbstractModel {
|
|||
case 'number':
|
||||
case 'object':
|
||||
case 'string':
|
||||
value = typeCast(this[key], value);
|
||||
if (undefined !== value) {
|
||||
this[key] = value;
|
||||
break;
|
||||
}
|
||||
this[key] = typeCast(this[key], value);
|
||||
break;
|
||||
// fall through
|
||||
case 'undefined':
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ export class AbstractCollectionModel extends Array
|
|||
* @returns {*CollectionModel}
|
||||
*/
|
||||
static reviveFromJson(json, itemCallback) {
|
||||
const result = new this();
|
||||
if (json) {
|
||||
const result = new this();
|
||||
if ('Collection/'+this.name.replace('Model', '') === json['@Object']) {
|
||||
Object.entries(json).forEach(([key, value]) => '@' !== key[0] && (result[key] = value));
|
||||
// json[@Count]
|
||||
|
|
@ -32,10 +32,9 @@ export class AbstractCollectionModel extends Array
|
|||
item && itemCallback && (item = itemCallback(item, result));
|
||||
item && result.push(item);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue