Merge branch 'master' into readstories

* master:
  Fixing view destroy for comments.
  Fixing a number of big memory leaks.
  Fixing story intelligence trainer.
This commit is contained in:
Samuel Clay 2013-12-19 12:59:00 -08:00
commit 939a487ebb
9 changed files with 77 additions and 8 deletions

View file

@ -2276,6 +2276,9 @@
}
if (feed) {
if (NEWSBLUR.app.story_unread_counter) {
NEWSBLUR.app.story_unread_counter.destroy();
}
NEWSBLUR.app.story_unread_counter = new NEWSBLUR.Views.UnreadCount({
model: feed
}).render();
@ -2287,6 +2290,9 @@
} else {
collection = folder.folder_view.collection;
}
if (NEWSBLUR.app.story_unread_counter) {
NEWSBLUR.app.story_unread_counter.destroy();
}
NEWSBLUR.app.story_unread_counter = new NEWSBLUR.Views.UnreadCount({
collection: collection
}).render();
@ -4945,6 +4951,14 @@
self.open_feed_intelligence_modal(1, feed_id, false);
}
});
$.targetIs(e, { tagSelector: '.NB-menu-manage-story-train' }, function($t, $p){
e.preventDefault();
if (!$t.hasClass('NB-disabled')) {
var feed_id = $t.parents('.NB-menu-manage').data('feed_id');
var story_id = $t.parents('.NB-menu-manage').data('story_id');
self.open_story_trainer(story_id, feed_id);
}
});
$.targetIs(e, { tagSelector: '.NB-menu-manage-feed-recommend' }, function($t, $p){
e.preventDefault();
var feed_id = $t.parents('.NB-menu-manage').data('feed_id');

View file

@ -171,6 +171,9 @@ NEWSBLUR.Views.FeedTitleView = Backbone.View.extend({
},
render_counts: function() {
if (this.counts_view) {
this.counts_view.destroy();
}
this.counts_view = new NEWSBLUR.Views.UnreadCount({model: this.model}).render();
this.$('.feed_counts').html(this.counts_view.el);
if (this.options.type == 'story') {

View file

@ -217,6 +217,9 @@ NEWSBLUR.Views.Folder = Backbone.View.extend({
});
}
if (this.folder_count) {
this.folder_count.destroy();
}
this.folder_count = new NEWSBLUR.Views.UnreadCount({
collection: this.collection
}).render();

View file

@ -60,9 +60,13 @@ NEWSBLUR.Views.Sidebar = Backbone.View.extend({
show_counts: function(options) {
var $header = NEWSBLUR.reader.$s.$river_blurblogs_header;
var $counts = new NEWSBLUR.Views.UnreadCount({
if (this.unread_count) {
this.unread_count.destroy();
}
this.unread_count = new NEWSBLUR.Views.UnreadCount({
collection: NEWSBLUR.assets.social_feeds
}).render().$el;
}).render();
var $counts = this.unread_count.$el;
if (this.options.feedbar) {
this.$('.NB-story-title-indicator-count').html($counts.clone());

View file

@ -24,6 +24,10 @@ NEWSBLUR.Views.StoryCommentsView = Backbone.View.extend({
return this;
},
destroy: function() {
this.remove();
},
render_teaser: function() {
if (!this.model.get('share_count')) return;

View file

@ -252,7 +252,8 @@ NEWSBLUR.Views.StoryDetailView = Backbone.View.extend({
var $original_comments = this.$('.NB-feed-story-comments-container,.NB-feed-story-comments');
var $original_shares = this.$('.NB-feed-story-shares-container,.NB-feed-story-shares');
if (this.model.get("comment_count") || this.model.get("share_count")) {
var $comments = new NEWSBLUR.Views.StoryCommentsView({model: this.model}).render().el;
this.comments_view = new NEWSBLUR.Views.StoryCommentsView({model: this.model}).render();
var $comments = this.comments_view.el;
$original_comments.replaceWith($comments);
var $shares = $('.NB-story-comments-shares-teaser-wrapper', $comments);
$original_shares.replaceWith($shares);
@ -263,9 +264,13 @@ NEWSBLUR.Views.StoryDetailView = Backbone.View.extend({
},
destroy: function() {
// console.log(["destroy story detail", this.model.get('story_title')]);
clearTimeout(this.truncate_delay_function);
this.images_to_load = null;
this.model.unbind(null, null, this);
if (this.collection) this.collection.unbind(null, null, this);
// this.sideoptions_view.destroy();
if (this.comments_view) this.comments_view.destroy();
delete this.model.inline_story_detail_view;
this.remove();
},

View file

@ -88,6 +88,19 @@ NEWSBLUR.Views.StoryTitleView = Backbone.View.extend({
}
},
destroy: function() {
// console.log(["destroy story title", this.model.get('story_title')]);
if (this.text_view) {
this.text_view.destroy();
}
if (this.story_detail) {
this.story_detail.destroy();
}
this.model.unbind(null, null, this);
this.collection.unbind(null, null, this);
this.remove();
},
destroy_inline_story_detail: function() {
if (this.story_detail) {
this.story_detail.destroy();

View file

@ -16,6 +16,7 @@ NEWSBLUR.Views.StoryTitlesView = Backbone.View.extend({
this.collection.bind('no_more_stories', this.check_premium_river, this);
this.collection.bind('no_more_stories', this.check_premium_search, this);
NEWSBLUR.reader.$s.$story_titles.scroll(this.scroll);
this.stories = [];
},
// ==========
@ -23,13 +24,18 @@ NEWSBLUR.Views.StoryTitlesView = Backbone.View.extend({
// ==========
render: function() {
this.clear();
NEWSBLUR.reader.$s.$story_titles.scrollTop(0);
var collection = this.collection;
var $stories = this.collection.map(function(story) {
var stories = this.collection.map(function(story) {
return new NEWSBLUR.Views.StoryTitleView({
model: story,
collection: collection
}).render().el;
}).render();
});
this.stories = stories;
var $stories = _.map(stories, function(story) {
return story.el;
});
this.$el.html($stories);
this.end_loading();
@ -39,19 +45,27 @@ NEWSBLUR.Views.StoryTitlesView = Backbone.View.extend({
add: function(options) {
var collection = this.collection;
if (options.added) {
var $stories = _.compact(_.map(this.collection.models.slice(-1 * options.added), function(story) {
var stories = _.compact(_.map(this.collection.models.slice(-1 * options.added), function(story) {
if (story.story_title_view) return;
return new NEWSBLUR.Views.StoryTitleView({
model: story,
collection: collection
}).render().el;
}).render();
}));
this.stories = this.stories.concat(stories);
var $stories = _.map(stories, function(story) {
return story.el;
});
this.$el.append($stories);
}
this.end_loading();
this.fill_out();
},
clear: function() {
_.invoke(this.stories, 'destroy');
},
append_river_premium_only_notification: function() {
var $notice = $.make('div', { className: 'NB-feed-story-premium-only' }, [
$.make('div', { className: 'NB-feed-story-premium-only-text'}, [

View file

@ -48,6 +48,15 @@ NEWSBLUR.Views.UnreadCount = Backbone.View.extend({
return this;
},
destroy: function() {
if (this.model) {
this.model.unbind(null, null, this);
} else if (this.collection) {
this.collection.unbind(null, null, this);
}
this.remove();
},
template: _.template('\
<div class="<%= unread_class %>">\
<span class="unread_count unread_count_positive <% if (ps) { %>unread_count_full<% } else { %>unread_count_empty<% } %>">\