Skip to content

Commit

Permalink
Make MessageView.render() idempotent
Browse files Browse the repository at this point in the history
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
  • Loading branch information
scottnonnenberg committed Jun 1, 2017
1 parent 25ebcc3 commit 0e1b534
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions js/views/message_view.js
Expand Up @@ -261,6 +261,11 @@
this.$('.avatar').replaceWith(avatarView.render().$('.avatar'));
},
loadAttachments: function() {
if (this.loadedAttachments) {
return;
}
this.loadedAttachments = [];

this.model.get('attachments').forEach(function(attachment) {
var view = new Whisper.AttachmentView({
model: attachment,
Expand All @@ -274,6 +279,7 @@
}
});
view.render();
this.loadedAttachments.push(view);
}.bind(this));
}
});
Expand Down

0 comments on commit 0e1b534

Please sign in to comment.