##// END OF EJS Templates
s/target/target_name
MinRK -
Show More
@@ -24,7 +24,7 b' var IPython = (function (IPython) {'
24 24
25 25 var CommManager = function (kernel) {
26 26 this.comms = {};
27 this.targets = {comm : Comm};
27 this.targets = {};
28 28 if (kernel !== undefined) {
29 29 this.init_kernel(kernel);
30 30 }
@@ -40,9 +40,9 b' var IPython = (function (IPython) {'
40 40 }
41 41 };
42 42
43 CommManager.prototype.register_target = function (target, constructor) {
44 // Register a constructor for a given target key
45 this.targets[target] = constructor;
43 CommManager.prototype.register_target = function (target_name, f) {
44 // Register a target function for a given target name
45 this.targets[target_name] = f;
46 46 };
47 47
48 48 CommManager.prototype.register_comm = function (comm) {
@@ -61,9 +61,9 b' var IPython = (function (IPython) {'
61 61
62 62 CommManager.prototype.comm_open = function (msg) {
63 63 var content = msg.content;
64 var callback = this.targets[content.target];
64 var callback = this.targets[content.target_name];
65 65 if (callback === undefined) {
66 console.log("No such target registered: ", content.target);
66 console.log("No such target registered: ", content.target_name);
67 67 console.log("Available targets are: ", this.targets);
68 68 return;
69 69 }
@@ -96,9 +96,9 b' var IPython = (function (IPython) {'
96 96 // Comm base class
97 97 //-----------------------------------------------------------------------
98 98
99 var Comm = function (comm_id, target) {
99 var Comm = function (comm_id, target_name) {
100 100 this.comm_id = comm_id || new IPython.utils.uuid();
101 this.target = target || 'comm';
101 this.target_name = target_name;
102 102 this._msg_callback = this._open_callback = this._close_callback = null;
103 103 };
104 104
@@ -106,7 +106,7 b' var IPython = (function (IPython) {'
106 106 Comm.prototype.open = function (data, callbacks) {
107 107 var content = {
108 108 comm_id : this.comm_id,
109 target : this.target,
109 target_name : this.target_name,
110 110 data : data || {},
111 111 };
112 112 return this.kernel.send_shell_message("comm_open", content, callbacks);
@@ -37,7 +37,7 b' class Comm(LoggingConfigurable):'
37 37 return
38 38 return self.shell.kernel.session
39 39
40 target = Unicode('comm')
40 target_name = Unicode('comm')
41 41
42 42 topic = Bytes()
43 43 def _topic_default(self):
@@ -82,7 +82,7 b' class Comm(LoggingConfigurable):'
82 82 """Open the frontend-side version of this comm"""
83 83 if data is None:
84 84 data = self._open_data
85 self._publish_msg('comm_open', data, target=self.target)
85 self._publish_msg('comm_open', data, target_name=self.target_name)
86 86
87 87 def close(self, data=None):
88 88 """Close the frontend-side version of this comm"""
@@ -76,8 +76,8 b' class CommManager(LoggingConfigurable):'
76 76
77 77 # Public APIs
78 78
79 def register_target(self, target, f):
80 """Register a callable f for a given target
79 def register_target(self, target_name, f):
80 """Register a callable f for a given target name
81 81
82 82 f will be called with a Comm object as its only argument
83 83 when a comm_open message is received with `target`.
@@ -87,7 +87,7 b' class CommManager(LoggingConfigurable):'
87 87 if isinstance(f, basestring):
88 88 f = import_item(f)
89 89
90 self.targets[target] = f
90 self.targets[target_name] = f
91 91
92 92 def register_comm(self, comm):
93 93 """Register a new comm"""
@@ -125,18 +125,18 b' class CommManager(LoggingConfigurable):'
125 125 """Handler for comm_open messages"""
126 126 content = msg['content']
127 127 comm_id = content['comm_id']
128 target = content['target']
129 callback = self.targets.get(target, None)
128 target_name = content['target_name']
129 f = self.targets.get(target_name, None)
130 130 comm = Comm(comm_id=comm_id,
131 131 shell=self.shell,
132 132 iopub_socket=self.iopub_socket,
133 133 primary=False,
134 134 )
135 if callback is None:
136 self.log.error("No such comm target registered: %s", target)
135 if f is None:
136 self.log.error("No such comm target registered: %s", target_name)
137 137 comm.close()
138 138 return
139 callback(comm)
139 f(comm)
140 140 comm.handle_open(msg)
141 141 self.register_comm(comm)
142 142
General Comments 0
You need to be logged in to leave comments. Login now