mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-11-14 11:44:54 +08:00
35 lines
920 B
JavaScript
35 lines
920 B
JavaScript
|
|
export class AbstractCollectionModel extends Array
|
|
{
|
|
constructor(props) {
|
|
/*
|
|
if (new.target === Parent) {
|
|
throw new Error("Can't instantiate abstract class!");
|
|
}
|
|
*/
|
|
super();
|
|
props && Object.entries(props).forEach(([key, value]) => '@' !== key[0] && (this[key] = value));
|
|
// props[@Count]
|
|
}
|
|
|
|
/**
|
|
* @static
|
|
* @param {FetchJson} json
|
|
* @returns {*CollectionModel}
|
|
*/
|
|
static reviveFromJson(json, itemCallback) {
|
|
// FolderCollectionModel => FolderCollection
|
|
// AttachmentCollectionModel => AttachmentCollection
|
|
// MessageCollectionModel => MessageCollection
|
|
if (json && 'Collection/'+this.name.replace('Model', '') === json['@Object']
|
|
&& Array.isArray(json['@Collection'])) {
|
|
const result = new this(json);
|
|
json['@Collection'].forEach(item => {
|
|
item && itemCallback && (item = itemCallback(item, result));
|
|
item && result.push(item);
|
|
});
|
|
return result;
|
|
}
|
|
}
|
|
|
|
}
|