| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
I'm a little bit confused, why this.comm.model? Isn't that just this in the context that this method is called in? In other words, won't this.trigger('destroy', this) work?
Sorry, something went wrong.
There was a problem hiding this comment.
Totally, I moved this from somewhere else.
Sorry, something went wrong.
|
@jdfreder Corrected as per your comment. |
Sorry, something went wrong.
|
@SylvainCorlay why trigger the "destroy" event ourselves instead of calling this.destroy() and let Backbone trigger the destroy event itself? |
Sorry, something went wrong.
|
Ahh I think I see why, is it because the destroy method attempts to delete the model on the back-end? |
Sorry, something went wrong.
|
Because this.destroy() also sends message to the server. |
Sorry, something went wrong.
|
Do you think it would also make sense to call this.stopListening() since backbone does that in its clean-up code inside destroy()? That method doesn't seem to call back to the back-end. |
Sorry, something went wrong.
|
In any case we need an event, which we use that event in Javascript Link widget PR and the PR on hiding the widget area. Backbone propagates it to the children models and all, which can be useful in the future. |
Sorry, something went wrong.
|
I agree, I'll merge this after you take a quick look at stopListening() and tell me if you agree that it makes sense to call it here. I'm just trying to make sure the model is in the same state as it would be if if backbone itself triggered the destroy event. From it's docstring, stopListening() just removes all of the event listeners to/from the current model which seems like it would be important in reducing ref count... It may be a bug that we aren't calling it already. |
Sorry, something went wrong.
|
Quiclky checking into backbone, I see the stopListening in remove, but not in destroy. |
Sorry, something went wrong.
|
Isn't this it: https://github.com/jashkenas/backbone/blob/master/backbone.js#L527 ? Lines 526, 527, and 544. Maybe you were looking in another destroy? |
Sorry, something went wrong.
|
Indeed. you are right. I added the line to stop listening. |
Sorry, something went wrong.
Destroy backbone model on comm:close
Destroy backbone model on comm:close
| Back | FazBrowse Home | New Git URL |
Trigger the destroy event in backbone.js before deleting the model.
Some other objects may still hold references to the model because they have registered to its events. In the implementation of backbone models, one can register an on('destroy') handler.