optimize infinite scroll widget instantiation. don't instantiate timeago widgets for StreamElement and Comment widgets

This commit is contained in:
Dan Hansen 2011-08-24 19:22:49 -05:00
parent ded85fb225
commit 121c0c97f8
3 changed files with 10 additions and 7 deletions

View file

@ -5,8 +5,7 @@
this.subscribe("widget/ready", function(evt, comment) { this.subscribe("widget/ready", function(evt, comment) {
$.extend(self, { $.extend(self, {
comment: comment, comment: comment,
deleteCommentLink: comment.find(".comment_delete"), deleteCommentLink: comment.find(".comment_delete")
timeAgo: self.instantiate("TimeAgo", comment.find("abbr.timeago"))
}); });
self.deleteCommentLink.click(self.removeComment); self.deleteCommentLink.click(self.removeComment);

View file

@ -10,13 +10,13 @@
commentStream: self.instantiate("CommentStream", element.find("ul.comments")), commentStream: self.instantiate("CommentStream", element.find("ul.comments")),
embedder: self.instantiate("Embedder", element.find("div.content")), embedder: self.instantiate("Embedder", element.find("div.content")),
likes: self.instantiate("Likes", element.find("div.likes_container")), likes: self.instantiate("Likes", element.find("div.likes_container")),
lightBox: self.instantiate("Lightbox", element), lightBox: self.instantiate("Lightbox", element)
timeAgo: self.instantiate("TimeAgo", element.find("abbr.timeago"))
}); });
self.globalSubscribe("post/" + self.postGuid + "/comment/added", function(evt, comment) { self.globalSubscribe("post/" + self.postGuid + "/comment/added", function(evt, comment) {
self.commentStream.publish("comment/added", comment); self.commentStream.publish("comment/added", comment);
}); });
self.globalSubscribe("commentStream/" + self.postGuid + "/loaded", function(evt) { self.globalSubscribe("commentStream/" + self.postGuid + "/loaded", function(evt) {
self.commentStream.instantiateCommentWidgets(); self.commentStream.instantiateCommentWidgets();
}); });

View file

@ -1,15 +1,19 @@
(function() { (function() {
var Stream = function() { var Stream = function() {
var self = this; var self = this;
this.streamElements = {};
this.subscribe("widget/ready", function(evt, stream) { this.subscribe("widget/ready", function(evt, stream) {
$.extend(self, { $.extend(self, {
stream: $(stream), stream: $(stream)
streamElements: {}
}); });
$.each(self.stream.find(".stream_element"), function() { $.each(self.stream.find(".stream_element"), function() {
self.addPost($(this)); var post = $(this);
if(typeof self.streamElements[post.attr("id")] === "undefined") {
self.addPost(post);
}
}); });
}); });