Support specifying requirejs modules for comm targets

pull/37/head
Thomas Kluyver 12 years ago
parent 031530da42
commit a77b5e8e31

@ -65,20 +65,40 @@ define([
CommManager.prototype.comm_open = function (msg) {
var content = msg.content;
var f = this.targets[content.target_name];
if (f === undefined) {
console.log("No such target registered: ", content.target_name);
console.log("Available targets are: ", this.targets);
return;
}
var comm = new Comm(content.target_name, content.comm_id);
this.register_comm(comm);
try {
f(comm, msg);
} catch (e) {
console.log("Exception opening new comm:", e, e.stack, msg);
comm.close();
this.unregister_comm(comm);
var that = this;
var instantiate_comm = function(target) {
var comm = new Comm(content.target_name, content.comm_id);
that.register_comm(comm);
try {
target(comm, msg);
} catch (e) {
console.log("Exception opening new comm:", e, e.stack, msg);
comm.close();
that.unregister_comm(comm);
}
};
if (content.target_module) {
// Load requirejs module for comm target
require([content.target_module], function(mod) {
var target = mod[content.target_name];
if (target !== undefined) {
instantiate_comm(target)
} else {
console.log("Comm target " + content.target_name +
" not found in module " + content.target_module);
}
}, function(err) { console.log(err); });
} else {
// No requirejs module specified: look for target in registry
var f = this.targets[content.target_name];
if (f === undefined) {
console.log("No such target registered: ", content.target_name);
console.log("Available targets are: ", this.targets);
return;
}
instantiate_comm(f)
}
};

Loading…
Cancel
Save