-
-
Notifications
You must be signed in to change notification settings - Fork 29
Conversation
…th the support.observer functions
@@ -5,6 +5,10 @@ Support.CompositeView = function(options) { | |||
|
|||
_.extend(Support.CompositeView.prototype, Backbone.View.prototype, { | |||
leave: function() { | |||
if (this.onLeave) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a Template Method like this doesn't feel natural in the Backbone world of events. I think having a "leave" event to bind to would be more natural.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good. I'll make the change.
title: 'Model or Collection' | ||
}); | ||
|
||
it("calls the unbindFromAll method when leaving the view", function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't actually test that it ever binds to the event, does it? If you comment out line 3 of observer.js, do all the specs pass? This applies to the unbindFromAll spec below, as well as the specs for Observer
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you comment out line 3 of observer.js the observer_spec.js will fail because the test on line 45 checks if bind is called on the source object. The #unbindFromAll test will pass though because I don't test if bind is called. My thoughts were that this was something more in the domain of the observer_spec than the composite_view_spec but I can add a test to #unbindFromAll to check that bind is called on the source object if you think it needs one.
Thanks for putting this together. This is a good change overall, but I had a few comments on the diff. I'll go over this patch again once you've had a chance to look those over. |
…d when leave is called on the view
I made a few changes to the code per your suggestions and added them to the branch. |
@amkirwan looks good. I'd like to rename |
@jferris I agree the event makes more sense as 'leave' than 'onLeave' for Backbone. Thanks for your help. |
I'm really liking these helpers! I'm using them right now. |
@@ -164,4 +200,80 @@ describe("Support.CompositeView", function() { | |||
expect(view.children.size()).toEqual(1); | |||
}); | |||
}); | |||
|
|||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed that this spec is commented out. Should it be removed or uncommented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad this needs to be removed. That was from before we switched to using a leave event.
Sorry for the delay on this. I went through the pull request again and had a few more comments. |
… to Observer prototype
…s loads before the composite_view.js
@jferris let me know if you need anything else to merge the changes |
Thanks. I merged this into master. |
👍 |
Added some helpers for event cleanup when the view is removed. These are taken from the book and put into a mixin Support.Observer that is mixed into the Support.CompositeView. I have also added a callback function onLeave which will be called from the view if the user has implemented it before the view is removed from the DOM.