mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-31 21:19:21 +03:00
merge all Model JSON @Object parsers into a reviveFromJson()
This commit is contained in:
parent
76648f04ae
commit
15e07a73e9
18 changed files with 378 additions and 411 deletions
|
|
@ -12,7 +12,14 @@ export class AbstractModel {
|
|||
* @param {string} modelName = ''
|
||||
*/
|
||||
constructor() {
|
||||
// this.sModelName = new.target.name;
|
||||
/*
|
||||
constructor(props) {
|
||||
if (new.target === Parent) {
|
||||
throw new Error("Can't instantiate abstract class!");
|
||||
}
|
||||
this.sModelName = new.target.name;
|
||||
props && Object.entries(props).forEach(([key, value]) => '@' !== key[0] && (this[key] = value));
|
||||
*/
|
||||
}
|
||||
|
||||
regDisposables(value) {
|
||||
|
|
@ -29,4 +36,30 @@ export class AbstractModel {
|
|||
}
|
||||
Object.values(this).forEach(disposeOne);
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param {FetchJson} json
|
||||
* @returns {boolean}
|
||||
*/
|
||||
static validJson(json) {
|
||||
return !!(json && ('Object/'+this.name.replace('Model', '') === json['@Object']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param {FetchJson} json
|
||||
* @returns {*Model}
|
||||
*/
|
||||
static reviveFromJson(json) {
|
||||
// Object/Attachment
|
||||
// Object/Contact
|
||||
// Object/Email
|
||||
// Object/Filter
|
||||
// Object/Folder
|
||||
// Object/Message
|
||||
// Object/Template
|
||||
return this.validJson(json) ? new this(json) : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue