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) {
$.extend(self, {
comment: comment,
deleteCommentLink: comment.find(".comment_delete"),
timeAgo: self.instantiate("TimeAgo", comment.find("abbr.timeago"))
deleteCommentLink: comment.find(".comment_delete")
});
self.deleteCommentLink.click(self.removeComment);

View file

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

View file

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