FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Destroy backbone model on comm:close by SylvainCorlay · Pull Request #6438 · ipython/ipython · GitHub

Destroy backbone model on comm:close - #6438

Merged
jdfreder merged 3 commits into
ipython:masterfrom
SylvainCorlay:model_destroy_message
Sep 16, 2014
Merged

Destroy backbone model on comm:close#6438
jdfreder merged 3 commits into
ipython:masterfrom
SylvainCorlay:model_destroy_message

Conversation

Copy link
Copy Markdown
Member

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.

takluyver added this to the 3.0 milestone Sep 9, 2014
jasongrout mentioned this pull request Sep 11, 2014

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Totally, I moved this from somewhere else.

Copy link
Copy Markdown
Member Author

@jdfreder Corrected as per your comment.

Copy link
Copy Markdown
Contributor

@SylvainCorlay why trigger the "destroy" event ourselves instead of calling this.destroy() and let Backbone trigger the destroy event itself?

Copy link
Copy Markdown
Contributor

Ahh I think I see why, is it because the destroy method attempts to delete the model on the back-end?

Copy link
Copy Markdown
Member Author

Because this.destroy() also sends message to the server.

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Member Author

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.
I can look at the stropListening tonight.

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Member Author

Quiclky checking into backbone, I see the stopListening in remove, but not in destroy.

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Member Author

Indeed. you are right. I added the line to stop listening.

Copy link
Copy Markdown
Contributor

Awesome thanks @SylvainCorlay !

jdfreder added a commit that referenced this pull request Sep 16, 2014
jdfreder merged commit 589cc44 into ipython:master Sep 16, 2014
SylvainCorlay deleted the model_destroy_message branch September 16, 2014 20:12
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
ellisonbg assigned ellisonbg and unassigned jdfreder Dec 4, 2014
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL