Show More
@@ -61,16 +61,15 b' var IPython = (function (IPython) {' | |||
|
61 | 61 | |
|
62 | 62 | CommManager.prototype.comm_open = function (msg) { |
|
63 | 63 | var content = msg.content; |
|
64 |
var |
|
|
65 |
if ( |
|
|
64 | var f = this.targets[content.target_name]; | |
|
65 | if (f === undefined) { | |
|
66 | 66 | console.log("No such target registered: ", content.target_name); |
|
67 | 67 | console.log("Available targets are: ", this.targets); |
|
68 | 68 | return; |
|
69 | 69 | } |
|
70 | 70 | var comm = new Comm(content.comm_id); |
|
71 | 71 | this.register_comm(comm); |
|
72 |
|
|
|
73 | comm.handle_open(msg); | |
|
72 | f(comm, msg); | |
|
74 | 73 | }; |
|
75 | 74 | |
|
76 | 75 | CommManager.prototype.comm_close = function (msg) { |
@@ -99,7 +98,7 b' var IPython = (function (IPython) {' | |||
|
99 | 98 | var Comm = function (comm_id, target_name) { |
|
100 | 99 | this.comm_id = comm_id || new IPython.utils.uuid(); |
|
101 | 100 | this.target_name = target_name; |
|
102 |
this._msg_callback |
|
|
101 | this._msg_callback = this._close_callback = null; | |
|
103 | 102 | }; |
|
104 | 103 | |
|
105 | 104 | // methods for sending messages |
@@ -133,10 +132,6 b' var IPython = (function (IPython) {' | |||
|
133 | 132 | this['_' + key + '_callback'] = callback; |
|
134 | 133 | }; |
|
135 | 134 | |
|
136 | Comm.prototype.on_open = function (callback) { | |
|
137 | this._register_callback('open', callback); | |
|
138 | }; | |
|
139 | ||
|
140 | 135 | Comm.prototype.on_msg = function (callback) { |
|
141 | 136 | this._register_callback('msg', callback); |
|
142 | 137 | }; |
@@ -152,10 +147,6 b' var IPython = (function (IPython) {' | |||
|
152 | 147 | if (callback) callback(msg); |
|
153 | 148 | }; |
|
154 | 149 | |
|
155 | Comm.prototype.handle_open = function (msg) { | |
|
156 | this._maybe_callback('open', msg); | |
|
157 | }; | |
|
158 | ||
|
159 | 150 | Comm.prototype.handle_msg = function (msg) { |
|
160 | 151 | this._maybe_callback('msg', msg); |
|
161 | 152 | }; |
@@ -43,10 +43,9 b' class Comm(LoggingConfigurable):' | |||
|
43 | 43 | def _topic_default(self): |
|
44 | 44 | return ('comm-%s' % self.comm_id).encode('ascii') |
|
45 | 45 | |
|
46 |
_open_data = Dict(help="data dict, if any, to be included in comm_ |
|
|
46 | _open_data = Dict(help="data dict, if any, to be included in comm_open") | |
|
47 | 47 | _close_data = Dict(help="data dict, if any, to be included in comm_close") |
|
48 | 48 | |
|
49 | _open_callback = Any() | |
|
50 | 49 | _msg_callback = Any() |
|
51 | 50 | _close_callback = Any() |
|
52 | 51 | |
@@ -61,7 +60,7 b' class Comm(LoggingConfigurable):' | |||
|
61 | 60 | super(Comm, self).__init__(**kwargs) |
|
62 | 61 | get_ipython().comm_manager.register_comm(self) |
|
63 | 62 | if self.primary: |
|
64 | # I am primary, open my peer | |
|
63 | # I am primary, open my peer. | |
|
65 | 64 | self.open(data) |
|
66 | 65 | |
|
67 | 66 | def _publish_msg(self, msg_type, data=None, **keys): |
@@ -99,14 +98,6 b' class Comm(LoggingConfigurable):' | |||
|
99 | 98 | self._publish_msg('comm_msg', data) |
|
100 | 99 | |
|
101 | 100 | # registering callbacks |
|
102 | def on_open(self, callback): | |
|
103 | """Register a callback for comm_open | |
|
104 | ||
|
105 | Will be called with the `data` of the open message. | |
|
106 | ||
|
107 | Call `on_open(None)` to disable an existing callback. | |
|
108 | """ | |
|
109 | self._open_callback = callback | |
|
110 | 101 | |
|
111 | 102 | def on_close(self, callback): |
|
112 | 103 | """Register a callback for comm_close |
@@ -128,12 +119,6 b' class Comm(LoggingConfigurable):' | |||
|
128 | 119 | |
|
129 | 120 | # handling of incoming messages |
|
130 | 121 | |
|
131 | def handle_open(self, msg): | |
|
132 | """Handle a comm_open message""" | |
|
133 | self.log.debug("handle_open[%s](%s)", self.comm_id, msg) | |
|
134 | if self._open_callback: | |
|
135 | self._open_callback(msg) | |
|
136 | ||
|
137 | 122 | def handle_close(self, msg): |
|
138 | 123 | """Handle a comm_close message""" |
|
139 | 124 | self.log.debug("handle_close[%s](%s)", self.comm_id, msg) |
@@ -136,9 +136,8 b' class CommManager(LoggingConfigurable):' | |||
|
136 | 136 | self.log.error("No such comm target registered: %s", target_name) |
|
137 | 137 | comm.close() |
|
138 | 138 | return |
|
139 | f(comm) | |
|
140 | comm.handle_open(msg) | |
|
141 | 139 | self.register_comm(comm) |
|
140 | f(comm, msg) | |
|
142 | 141 | |
|
143 | 142 | @with_output |
|
144 | 143 | def comm_msg(self, stream, ident, msg): |
General Comments 0
You need to be logged in to leave comments.
Login now