-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Pass the output area object in events specific to the output area. #2411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Also, add a new event triggered right before the output area is cleared. This is useful if an output renderer has cleanup work to do before the DOM element is removed off of the page.
It would be even better if the cell could keep track of the rendered values, and take an optional callback for when that rendered value would be cleared. But we can hack around that with an event like this. |
This looks like a good solution to me. Are there advantages to attaching event handlers to the output element vs. the output area? |
Thanks to @gnestor for this, from PR jupyter#2394.
I'm not sure I understand your question. We trigger on the output element because that is what has the jquery event system because it is a jquery object. The bubbling then goes up through the DOM, so you can listen to all of these events by doing something like |
This depends on jupyter/notebook#2411 to get all the corner cases. We left in various other event triggers to cover most cases even without that PR.
What I mean is Since the output element already has |
|
I also figured keeping the events on the output area instance was more backwards compatible.... |
CodeCell.prototype.clear_output = function (wait) { | ||
this.output_area.clear_output(wait); | ||
this.set_input_prompt(); | ||
CodeCell.prototype.clear_output = function (wait, ignore_queue) { |
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.
Should ignore_queue
have a default argument since prior calls to this would not have had an argument? Perhaps undefined
is ok to pass through to this.output_area.clear_output
?
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.
Good call. I'll check.
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.
It's fine the way it is. undefined
is treated as false
, which means things should proceed as normal in the clear_output
function.
@@ -942,7 +942,7 @@ define([ | |||
}; | |||
|
|||
|
|||
OutputArea.prototype.clear_output = function(wait, ignore_que) { | |||
OutputArea.prototype.clear_output = function(wait, ignore_clear_queue) { |
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.
Certainly better naming. 😄
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.
It took me a while of staring at it to figure out the double negative logic and what it was supposed to say :).
I prefer global events that are scoped too. |
I prefer that too, all else being equal, but was avoiding making too many huge changes, especially backwards-incompatible ones. |
Also, add a new event triggered right before the output area is cleared. This is useful if an output renderer has cleanup work to do before the DOM element is removed off of the page.
@gnestor and I both want to add mimebundle renderers that should have a method called when the rendered value needs to be cleaned up.
Passing the output area in also makes it easy to listen for this event at the notebook level once and perform some action on whatever output area triggers the event.