##// END OF EJS Templates
pass whole message to Comm handlers
MinRK -
Show More
@@ -70,7 +70,7 b' var IPython = (function (IPython) {'
70 70 var comm = new Comm(content.comm_id);
71 71 this.register_comm(comm);
72 72 callback(comm);
73 comm.handle_open(content.data);
73 comm.handle_open(msg);
74 74 };
75 75
76 76 CommManager.prototype.comm_close = function (msg) {
@@ -80,7 +80,7 b' var IPython = (function (IPython) {'
80 80 return;
81 81 }
82 82 delete this.comms[content.comm_id];
83 comm.handle_close(content.data);
83 comm.handle_close(msg);
84 84 };
85 85
86 86 CommManager.prototype.comm_msg = function (msg) {
@@ -89,16 +89,16 b' var IPython = (function (IPython) {'
89 89 if (comm === undefined) {
90 90 return;
91 91 }
92 comm.handle_msg(content.data);
92 comm.handle_msg(msg);
93 93 };
94 94
95 95 //-----------------------------------------------------------------------
96 96 // Comm base class
97 97 //-----------------------------------------------------------------------
98 98
99 var Comm = function (comm_id) {
99 var Comm = function (comm_id, target) {
100 100 this.comm_id = comm_id;
101 this.target = 'comm';
101 this.target = target || 'comm';
102 102 };
103 103
104 104 // methods for sending messages
@@ -129,16 +129,16 b' var IPython = (function (IPython) {'
129 129
130 130 // methods for handling incoming messages
131 131
132 Comm.prototype.handle_open = function (data) {
133 $([this]).trigger("comm_open", data);
132 Comm.prototype.handle_open = function (msg) {
133 $([this]).trigger("comm_open", msg);
134 134 };
135 135
136 Comm.prototype.handle_msg = function (data) {
137 $([this]).trigger("comm_msg", data);
136 Comm.prototype.handle_msg = function (msg) {
137 $([this]).trigger("comm_msg", msg);
138 138 };
139 139
140 Comm.prototype.handle_close = function (data) {
141 $([this]).trigger("comm_close", data);
140 Comm.prototype.handle_close = function (msg) {
141 $([this]).trigger("comm_close", msg);
142 142 };
143 143
144 144 IPython.CommManager = CommManager;
@@ -56,15 +56,12 b' class Comm(LoggingConfigurable):'
56 56
57 57 primary = Bool(True, help="Am I the primary or secondary Comm?")
58 58
59 def __init__(self, **kwargs):
59 def __init__(self, data=None, **kwargs):
60 60 super(Comm, self).__init__(**kwargs)
61 61 get_ipython().comm_manager.register_comm(self)
62 62 if self.primary:
63 63 # I am primary, open my peer
64 self.open()
65 else:
66 # I am secondary, handle creation
67 self.handle_open(self._open_data)
64 self.open(data)
68 65
69 66 def _publish_msg(self, msg_type, data=None, **keys):
70 67 """Helper for sending a comm message on IOPub"""
@@ -97,7 +94,7 b' class Comm(LoggingConfigurable):'
97 94 self._closed = True
98 95
99 96 def send(self, data=None):
100 """Update the frontend-side version of this comm"""
97 """Send a message to the frontend-side version of this comm"""
101 98 self._publish_msg('comm_msg', data)
102 99
103 100 # registering callbacks
@@ -130,23 +127,23 b' class Comm(LoggingConfigurable):'
130 127
131 128 # handling of incoming messages
132 129
133 def handle_open(self, data):
130 def handle_open(self, msg):
134 131 """Handle a comm_open message"""
135 self.log.debug("handle_open[%s](%s)", self.comm_id, data)
132 self.log.debug("handle_open[%s](%s)", self.comm_id, msg)
136 133 if self._open_callback:
137 self._open_callback(data)
134 self._open_callback(msg)
138 135
139 def handle_close(self, data):
136 def handle_close(self, msg):
140 137 """Handle a comm_close message"""
141 self.log.debug("handle_close[%s](%s)", self.comm_id, data)
138 self.log.debug("handle_close[%s](%s)", self.comm_id, msg)
142 139 if self._close_callback:
143 self._close_callback(data)
140 self._close_callback(msg)
144 141
145 def handle_msg(self, data):
142 def handle_msg(self, msg):
146 143 """Handle a comm_msg message"""
147 self.log.debug("handle_msg[%s](%s)", self.comm_id, data)
144 self.log.debug("handle_msg[%s](%s)", self.comm_id, msg)
148 145 if self._msg_callback:
149 self._msg_callback(data)
146 self._msg_callback(msg)
150 147
151 148
152 149 __all__ = ['Comm']
@@ -107,7 +107,6 b' class CommManager(LoggingConfigurable):'
107 107 comm = Comm(comm_id=comm_id,
108 108 shell=self.shell,
109 109 iopub_socket=self.iopub_socket,
110 _open_data=content['data'],
111 110 primary=False,
112 111 )
113 112 if callback is None:
@@ -115,6 +114,7 b' class CommManager(LoggingConfigurable):'
115 114 comm.close()
116 115 return
117 116 callback(comm)
117 comm.handle_open(msg)
118 118 self.register_comm(comm)
119 119
120 120 def comm_msg(self, stream, ident, msg):
@@ -125,7 +125,7 b' class CommManager(LoggingConfigurable):'
125 125 if comm is None:
126 126 # no such comm
127 127 return
128 comm.handle_msg(content['data'])
128 comm.handle_msg(msg)
129 129
130 130 def comm_close(self, stream, ident, msg):
131 131 """Handler for comm_close messages"""
@@ -135,8 +135,8 b' class CommManager(LoggingConfigurable):'
135 135 if comm is None:
136 136 # no such comm
137 137 return
138 comm.handle_close(content['data'])
139 138 del self.comms[comm_id]
139 comm.handle_close(msg)
140 140
141 141
142 142 __all__ = ['CommManager']
General Comments 0
You need to be logged in to leave comments. Login now