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
pull/749/head
Scott Nonnenberg 8 years ago
parent 25ebcc3131
commit 0e1b534d3c

@ -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…
Cancel
Save