Skip to content

Commit

Permalink
Finish decoupling of the manager
Browse files Browse the repository at this point in the history
  • Loading branch information
jdfreder committed Aug 27, 2015
1 parent 3a60031 commit b8424bb
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions ipywidgets/static/widgets/js/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ define([
options = options || {};
options.root = true; // This element is being displayed not as a child of another.

return this.create_view(model, options).then((function(view) {
return this.create_view(model, options).then(_.bind(function(view) {
return this.display_view(msg, view, options);
}).bind(this)).catch(utils.reject('Could not create view', true));
}, this)).catch(utils.reject('Could not create view', true));
};

ManagerBase.prototype.display_view = function(msg, view, options) {
Expand Down Expand Up @@ -366,7 +366,7 @@ define([
// WidgetManager class
//--------------------------------------------------------------------
var WidgetManager = function (comm_manager, notebook) {
WidgetManager.apply(this, comm_manager, notebook);
ManagerBase.apply(this);
WidgetManager._managers.push(this);

// Attach a comm manager to the
Expand All @@ -375,7 +375,7 @@ define([
this.comm_manager = comm_manager;

// Register with the comm manager.
this.comm_manager.register_target(this.comm_target_name, _.bind(this.handle_comm_open, this));
this.comm_manager.register_target(this.comm_target_name, _.bind(this.handle_comm_open.bind,this));

// Load the initial state of the widget manager if a load callback was
// registered.
Expand All @@ -399,11 +399,27 @@ define([
}
});
};
WidgetManager.prototype = Object.create(WidgetManager.prototype);
WidgetManager.prototype = Object.create(ManagerBase.prototype);

WidgetManager._managers = []; /* List of widget managers */
WidgetManager._load_callback = null;
WidgetManager._save_callback = null;


WidgetManager.register_widget_model = function (model_name, model_type) {
/**
* Registers a widget model by name.
*/
return ManagerBase.register_widget_model.apply(this, arguments);
};

WidgetManager.register_widget_view = function (view_name, view_type) {
/**
* Registers a widget view by name.
*/
return ManagerBase.register_widget_view.apply(this, arguments);
};

WidgetManager.set_state_callbacks = function (load_callback, save_callback, options) {
/**
* Registers callbacks for widget state persistence.
Expand Down Expand Up @@ -503,7 +519,7 @@ define([
} else {
if (options.cell.widgetarea) {
var that = this;
return options.cell.widgetarea.display_widget_view(view).then(function(view) {
return options.cell.widgetarea.display_widget_view(Promise.resolve(view)).then(function(view) {
that._handle_display_view(view);
return view;
}).catch(utils.reject('Could not display view', true));
Expand Down

0 comments on commit b8424bb

Please sign in to comment.