diff --git a/IPython/html/static/notebook/js/comm.js b/IPython/html/static/notebook/js/comm.js
index c141df5..e903dc8 100644
--- a/IPython/html/static/notebook/js/comm.js
+++ b/IPython/html/static/notebook/js/comm.js
@@ -70,7 +70,7 @@ var IPython = (function (IPython) {
var comm = new Comm(content.comm_id);
this.register_comm(comm);
callback(comm);
- comm.handle_open(content.data);
+ comm.handle_open(msg);
};
CommManager.prototype.comm_close = function (msg) {
@@ -80,7 +80,7 @@ var IPython = (function (IPython) {
return;
}
delete this.comms[content.comm_id];
- comm.handle_close(content.data);
+ comm.handle_close(msg);
};
CommManager.prototype.comm_msg = function (msg) {
@@ -89,16 +89,16 @@ var IPython = (function (IPython) {
if (comm === undefined) {
return;
}
- comm.handle_msg(content.data);
+ comm.handle_msg(msg);
};
//-----------------------------------------------------------------------
// Comm base class
//-----------------------------------------------------------------------
- var Comm = function (comm_id) {
+ var Comm = function (comm_id, target) {
this.comm_id = comm_id;
- this.target = 'comm';
+ this.target = target || 'comm';
};
// methods for sending messages
@@ -129,16 +129,16 @@ var IPython = (function (IPython) {
// methods for handling incoming messages
- Comm.prototype.handle_open = function (data) {
- $([this]).trigger("comm_open", data);
+ Comm.prototype.handle_open = function (msg) {
+ $([this]).trigger("comm_open", msg);
};
- Comm.prototype.handle_msg = function (data) {
- $([this]).trigger("comm_msg", data);
+ Comm.prototype.handle_msg = function (msg) {
+ $([this]).trigger("comm_msg", msg);
};
- Comm.prototype.handle_close = function (data) {
- $([this]).trigger("comm_close", data);
+ Comm.prototype.handle_close = function (msg) {
+ $([this]).trigger("comm_close", msg);
};
IPython.CommManager = CommManager;
diff --git a/IPython/kernel/comm/comm.py b/IPython/kernel/comm/comm.py
index 1c4f7b9..00b839a 100644
--- a/IPython/kernel/comm/comm.py
+++ b/IPython/kernel/comm/comm.py
@@ -56,15 +56,12 @@ class Comm(LoggingConfigurable):
primary = Bool(True, help="Am I the primary or secondary Comm?")
- def __init__(self, **kwargs):
+ def __init__(self, data=None, **kwargs):
super(Comm, self).__init__(**kwargs)
get_ipython().comm_manager.register_comm(self)
if self.primary:
# I am primary, open my peer
- self.open()
- else:
- # I am secondary, handle creation
- self.handle_open(self._open_data)
+ self.open(data)
def _publish_msg(self, msg_type, data=None, **keys):
"""Helper for sending a comm message on IOPub"""
@@ -97,7 +94,7 @@ class Comm(LoggingConfigurable):
self._closed = True
def send(self, data=None):
- """Update the frontend-side version of this comm"""
+ """Send a message to the frontend-side version of this comm"""
self._publish_msg('comm_msg', data)
# registering callbacks
@@ -130,23 +127,23 @@ class Comm(LoggingConfigurable):
# handling of incoming messages
- def handle_open(self, data):
+ def handle_open(self, msg):
"""Handle a comm_open message"""
- self.log.debug("handle_open[%s](%s)", self.comm_id, data)
+ self.log.debug("handle_open[%s](%s)", self.comm_id, msg)
if self._open_callback:
- self._open_callback(data)
+ self._open_callback(msg)
- def handle_close(self, data):
+ def handle_close(self, msg):
"""Handle a comm_close message"""
- self.log.debug("handle_close[%s](%s)", self.comm_id, data)
+ self.log.debug("handle_close[%s](%s)", self.comm_id, msg)
if self._close_callback:
- self._close_callback(data)
+ self._close_callback(msg)
- def handle_msg(self, data):
+ def handle_msg(self, msg):
"""Handle a comm_msg message"""
- self.log.debug("handle_msg[%s](%s)", self.comm_id, data)
+ self.log.debug("handle_msg[%s](%s)", self.comm_id, msg)
if self._msg_callback:
- self._msg_callback(data)
+ self._msg_callback(msg)
__all__ = ['Comm']
diff --git a/IPython/kernel/comm/manager.py b/IPython/kernel/comm/manager.py
index 47ac845..1908cad 100644
--- a/IPython/kernel/comm/manager.py
+++ b/IPython/kernel/comm/manager.py
@@ -107,7 +107,6 @@ class CommManager(LoggingConfigurable):
comm = Comm(comm_id=comm_id,
shell=self.shell,
iopub_socket=self.iopub_socket,
- _open_data=content['data'],
primary=False,
)
if callback is None:
@@ -115,6 +114,7 @@ class CommManager(LoggingConfigurable):
comm.close()
return
callback(comm)
+ comm.handle_open(msg)
self.register_comm(comm)
def comm_msg(self, stream, ident, msg):
@@ -125,7 +125,7 @@ class CommManager(LoggingConfigurable):
if comm is None:
# no such comm
return
- comm.handle_msg(content['data'])
+ comm.handle_msg(msg)
def comm_close(self, stream, ident, msg):
"""Handler for comm_close messages"""
@@ -135,8 +135,8 @@ class CommManager(LoggingConfigurable):
if comm is None:
# no such comm
return
- comm.handle_close(content['data'])
del self.comms[comm_id]
+ comm.handle_close(msg)
__all__ = ['CommManager']