be less agressive when re-rendering on feedback actions

This commit is contained in:
danielgrippi 2012-02-20 22:05:50 -08:00
parent 3cab4d348a
commit 3db133a3a7
5 changed files with 27 additions and 2 deletions

View file

@ -41,6 +41,7 @@ app.models.Post = Backbone.Model.extend({
var self = this;
this.participations.create({}, {success : function(resp){
self.set(resp.attributes.post)
self.trigger('feedback', self)
}});
},
@ -50,6 +51,8 @@ app.models.Post = Backbone.Model.extend({
participationModel.destroy();
this.set({ user_participation : null });
this.trigger('feedback', this)
},
toggleLike : function() {
@ -65,6 +68,7 @@ app.models.Post = Backbone.Model.extend({
var self = this;
this.likes.create({}, {success : function(resp){
self.set(resp.attributes.post)
self.trigger('feedback', self)
}});
},
@ -74,5 +78,6 @@ app.models.Post = Backbone.Model.extend({
likeModel.destroy();
this.set({ user_like : null });
this.trigger('feedback', this)
}
});

View file

@ -12,7 +12,7 @@ app.pages.PostViewer = app.views.Base.extend({
postView : function(){
return new app.views.Post({
model : this.model,
className : "dd",
className : "loaded",
templateName : "post-viewer/content/" + this.options.postTemplateName
})
},

View file

@ -10,7 +10,11 @@ app.views.Base = Backbone.View.extend({
setupRenderEvents : function(){
this.model.bind('remove', this.remove, this);
this.model.bind('change', this.render, this);
// this line is too generic. we usually only want to re-render on
// feedback changes as the post content, author, and time do not change.
//
// this.model.bind('change', this.render, this);
},
defaultPresenter : function(){

View file

@ -10,6 +10,14 @@ app.views.Feedback = app.views.Base.extend({
"click .reshare_action": "resharePost"
},
initialize : function() {
this.model.bind('feedback', this.render, this);
},
postRenderTemplate : function(){
console.log('fuck')
},
presenter : function() {
return _.extend(this.defaultPresenter(), {
userCanReshare : this.userCanReshare()

View file

@ -16,6 +16,14 @@ describe("app.views.Feedback", function(){
});
describe("triggers", function() {
it('re-renders when the model triggers feedback', function(){
spyOn(this.view, "postRenderTemplate")
this.view.model.trigger("feedback")
expect(this.view.postRenderTemplate).toHaveBeenCalled()
})
})
describe(".render", function(){
beforeEach(function(){
this.link = function(){ return this.view.$(".like_action"); }