mirror of
https://github.com/jupyter/notebook.git
synced 2024-12-21 04:10:17 +08:00
General cleanup of base.js, including indentation fixes and adding view callbacks to the save options dictionary.
This commit is contained in:
parent
747b219771
commit
a8c8c2a5fd
@ -37,7 +37,6 @@ function(widget_manager, underscore, backbone){
|
||||
comm.model = this;
|
||||
|
||||
// Hook comm messages up to model.
|
||||
var that = this;
|
||||
comm.on_close($.proxy(this._handle_comm_closed, this));
|
||||
comm.on_msg($.proxy(this._handle_comm_msg, this));
|
||||
}
|
||||
@ -87,6 +86,7 @@ function(widget_manager, underscore, backbone){
|
||||
this.set(key, state[key]);
|
||||
}
|
||||
}
|
||||
//TODO: are there callbacks that make sense in this case? If so, attach them here as an option
|
||||
this.save();
|
||||
} finally {
|
||||
this.updating = false;
|
||||
@ -96,9 +96,7 @@ function(widget_manager, underscore, backbone){
|
||||
|
||||
_handle_status: function (msg, callbacks) {
|
||||
//execution_state : ('busy', 'idle', 'starting')
|
||||
if (this.comm !== undefined) {
|
||||
if (msg.content.execution_state ==='idle') {
|
||||
|
||||
if (this.comm !== undefined && msg.content.execution_state ==='idle') {
|
||||
// Send buffer if this message caused another message to be
|
||||
// throttled.
|
||||
if (this.msg_buffer !== null &&
|
||||
@ -107,13 +105,11 @@ function(widget_manager, underscore, backbone){
|
||||
this.comm.send(data, callbacks);
|
||||
this.msg_buffer = null;
|
||||
} else {
|
||||
|
||||
// Only decrease the pending message count if the buffer
|
||||
// doesn't get flushed (sent).
|
||||
--this.pending_msgs;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@ -154,7 +150,7 @@ function(widget_manager, underscore, backbone){
|
||||
}
|
||||
|
||||
var data = {method: 'backbone', sync_method: method, sync_data: send_json};
|
||||
this.comm.send(data, this.callbacks);
|
||||
this.comm.send(data, options.callbacks);
|
||||
this.pending_msgs++;
|
||||
}
|
||||
}
|
||||
@ -181,10 +177,13 @@ function(widget_manager, underscore, backbone){
|
||||
},
|
||||
|
||||
update: function(){
|
||||
// update thyself to be consistent with this.model
|
||||
// update view to be consistent with this.model
|
||||
// triggered on model change
|
||||
},
|
||||
|
||||
child_view: function(comm_id, view_name) {
|
||||
// create and return a child view, given a comm id for a model and (optionally) a view name
|
||||
// if the view name is not given, it defaults to the model's default view attribute
|
||||
var child_model = this.comm_manager.comms[comm_id].model;
|
||||
var child_view = this.widget_manager.create_view(child_model, view_name, this.cell);
|
||||
this.child_views.push(child_view);
|
||||
@ -192,23 +191,21 @@ function(widget_manager, underscore, backbone){
|
||||
},
|
||||
|
||||
render: function(){
|
||||
// render thyself
|
||||
// render the view. By default, this is only called the first time the view is created
|
||||
},
|
||||
send: function (content) {
|
||||
this.model.send(content, this.cell_callbacks(this.cell));
|
||||
this.model.send(content, this._callbacks());
|
||||
},
|
||||
|
||||
touch: function () {
|
||||
this.model.callbacks = this.cell_callbacks();
|
||||
this.model.save(this.model.changedAttributes(), {patch: true});
|
||||
this.model.save(this.model.changedAttributes(), {patch: true, callbacks: this._callbacks()});
|
||||
},
|
||||
|
||||
cell_callbacks: function () {
|
||||
_callbacks: function () {
|
||||
// callback handlers specific to this view's cell
|
||||
var callbacks = {};
|
||||
var cell = this.cell;
|
||||
if (cell !== null) {
|
||||
|
||||
// Try to get output handlers
|
||||
var handle_output = null;
|
||||
var handle_clear_output = null;
|
||||
@ -225,7 +222,7 @@ function(widget_manager, underscore, backbone){
|
||||
clear_output : handle_clear_output,
|
||||
|
||||
status : function (msg) {
|
||||
that.model._handle_status(msg, that.cell_callbacks());
|
||||
that.model._handle_status(msg, that._callbacks());
|
||||
},
|
||||
|
||||
// Special function only registered by widget messages.
|
||||
@ -244,7 +241,7 @@ function(widget_manager, underscore, backbone){
|
||||
|
||||
var WidgetView = BaseWidgetView.extend({
|
||||
initialize: function (options) {
|
||||
// TODO: make changes more granular
|
||||
// TODO: make changes more granular (e.g., trigger on visible:change)
|
||||
this.model.on('change', this.update, this);
|
||||
BaseWidgetView.prototype.initialize.apply(this, arguments);
|
||||
},
|
||||
@ -309,6 +306,7 @@ function(widget_manager, underscore, backbone){
|
||||
|
||||
IPython.WidgetModel = WidgetModel;
|
||||
IPython.WidgetView = WidgetView;
|
||||
IPython.BaseWidgetView = BaseWidgetView;
|
||||
|
||||
return widget_manager;
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user