mirror of
https://github.com/jupyter/notebook.git
synced 2025-02-05 12:19:58 +08:00
handle display-updates as updates
This commit is contained in:
parent
4439a19d24
commit
0c90391f8a
@ -448,7 +448,7 @@ define([
|
||||
this.element.append(toinsert);
|
||||
}
|
||||
} catch(err) {
|
||||
console.log(err);
|
||||
console.error(err);
|
||||
// Create an actual output_area and output_subarea, which creates
|
||||
// the prompt area and the proper indentation.
|
||||
var toinsert = this.create_output_area();
|
||||
@ -585,45 +585,40 @@ define([
|
||||
|
||||
OutputArea.prototype.append_display_data = function (json, handle_inserted) {
|
||||
var oa = this;
|
||||
var update_targets;
|
||||
var targets;
|
||||
var display_id = (json.transient || {}).display_id;
|
||||
var is_update = (json.transient || {})._is_update;
|
||||
if (is_update) {
|
||||
// consume _is_update marker
|
||||
delete json.transient._is_update;
|
||||
}
|
||||
var record = !is_update;
|
||||
if (display_id) {
|
||||
// it has a display_id;
|
||||
update_targets = this._display_id_targets[display_id];
|
||||
if (update_targets) {
|
||||
targets = this._display_id_targets[display_id];
|
||||
if (targets) {
|
||||
// we've seen it before, update output data
|
||||
update_targets.map(function (target) {
|
||||
targets.map(function (target) {
|
||||
oa.outputs[target.index] = json;
|
||||
});
|
||||
} else {
|
||||
// not seen before, create and record new output area
|
||||
update_targets = this._display_id_targets[display_id] = [{
|
||||
index: this.outputs.length,
|
||||
element: null,
|
||||
}];
|
||||
targets = this._display_id_targets[display_id] = [];
|
||||
}
|
||||
}
|
||||
if (update_targets) {
|
||||
// updating multiple
|
||||
update_targets.map(function (target) {
|
||||
var toinsert = oa.create_output_area();
|
||||
if (oa.append_mime_type(json, toinsert, handle_inserted)) {
|
||||
oa._safe_append(toinsert, target.element);
|
||||
}
|
||||
target.element = toinsert;
|
||||
});
|
||||
} else {
|
||||
var toinsert = this.create_output_area();
|
||||
if (oa.append_mime_type(json, toinsert, handle_inserted)) {
|
||||
oa._safe_append(toinsert);
|
||||
}
|
||||
targets = [];
|
||||
}
|
||||
if (record) {
|
||||
// if it's a display and not an update, add a new output
|
||||
targets.push({
|
||||
index: this.outputs.length,
|
||||
element: null,
|
||||
});
|
||||
}
|
||||
// updating multiple
|
||||
targets.map(function (target) {
|
||||
var toinsert = oa.create_output_area();
|
||||
if (oa.append_mime_type(json, toinsert, handle_inserted)) {
|
||||
oa._safe_append(toinsert, target.element);
|
||||
}
|
||||
target.element = toinsert;
|
||||
});
|
||||
// If we just output latex, typeset it.
|
||||
if ((json.data[MIME_LATEX] !== undefined) ||
|
||||
(json.data[MIME_HTML] !== undefined) ||
|
||||
|
@ -860,6 +860,7 @@ define([
|
||||
var callbacks = this._msg_callbacks[msg_id];
|
||||
var kernel = this;
|
||||
// clear display_id:msg_id map for display_ids associated with this msg_id
|
||||
if (!callbacks) return;
|
||||
callbacks.display_ids.map(function (display_id) {
|
||||
var msg_ids = kernel._display_id_targets[display_id];
|
||||
if (msg_ids) {
|
||||
@ -1086,12 +1087,16 @@ define([
|
||||
var target_msg_ids = this._display_id_targets[display_id];
|
||||
if (target_msg_ids) {
|
||||
// we've seen it before, update existing outputs with same id
|
||||
// by handling display_data as update_display_data
|
||||
var update_msg = $.extend(true, {}, msg);
|
||||
update_msg.header.msg_type = 'update_display_data';
|
||||
|
||||
target_msg_ids.map(function (target_msg_id) {
|
||||
var callbacks = that.get_callbacks_for_msg(target_msg_id);
|
||||
if (!callbacks) return;
|
||||
var callback = callbacks.iopub.output;
|
||||
if (callback) {
|
||||
callback(msg);
|
||||
callback(update_msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1109,7 +1114,9 @@ define([
|
||||
this._display_id_targets[display_id].push(msg_id);
|
||||
}
|
||||
// and in callbacks for cleanup on clear_callbacks_for_msg
|
||||
callbacks.display_ids.push(display_id);
|
||||
if (callbacks && callbacks.display_ids.indexOf(display_id) === -1) {
|
||||
callbacks.display_ids.push(display_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user