Make MessageView.render() idempotent
Re-renders happen when we re-fetch messages from the database, and our previous technique for loading attachments resulted in a new attachment view added for every call to render() This change ensures that a second call to render() does not add any more attachment views. FREEBIE
This commit is contained in:
parent
25ebcc3131
commit
0e1b534d3c
1 changed files with 6 additions and 0 deletions
|
@ -261,6 +261,11 @@
|
||||||
this.$('.avatar').replaceWith(avatarView.render().$('.avatar'));
|
this.$('.avatar').replaceWith(avatarView.render().$('.avatar'));
|
||||||
},
|
},
|
||||||
loadAttachments: function() {
|
loadAttachments: function() {
|
||||||
|
if (this.loadedAttachments) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.loadedAttachments = [];
|
||||||
|
|
||||||
this.model.get('attachments').forEach(function(attachment) {
|
this.model.get('attachments').forEach(function(attachment) {
|
||||||
var view = new Whisper.AttachmentView({
|
var view = new Whisper.AttachmentView({
|
||||||
model: attachment,
|
model: attachment,
|
||||||
|
@ -274,6 +279,7 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
view.render();
|
view.render();
|
||||||
|
this.loadedAttachments.push(view);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue