Cleaner CollectionModel code

This commit is contained in:
djmaze 2020-10-18 19:36:57 +02:00
parent ddc866735c
commit 76648f04ae
2 changed files with 19 additions and 20 deletions

View file

@ -10,14 +10,15 @@ export class AttachmentCollectionModel extends AbstractCollectionModel
* @returns {AttachmentCollectionModel}
*/
static reviveFromJson(items) {
let result = new AttachmentCollectionModel;
items = this.getFromJSON(items, 'AttachmentCollection') || items;
Array.isArray(items) && items.forEach(attachment => {
attachment = AttachmentModel.newInstanceFromJson(attachment);
if (attachment) {
result.push(attachment);
}
});
let cb = attachment => AttachmentModel.newInstanceFromJson(attachment),
result = super.reviveFromJson(items, cb);
if (!result) {
result = new AttachmentCollectionModel;
Array.isArray(items) && items.forEach(attachment => {
attachment = cb(attachment);
attachment && result.push(attachment);
});
}
return result;
}