diff --git a/assets/providers/ijulia_setup.js b/assets/providers/ijulia_setup.js index fc8a48e4..7821ef2d 100644 --- a/assets/providers/ijulia_setup.js +++ b/assets/providers/ijulia_setup.js @@ -6,15 +6,23 @@ // Register a "target" so that Julia can create a Comm // to communicate. - commManager.register_target("webio_comm", - function (comm) { - WebIO.triggerConnected(); - WebIO.sendCallback = function (msg) { comm.send(msg); } - comm.on_msg(function (msg) { - WebIO.dispatch(msg.content.data); - }); - } - ); + commManager.register_target("webio_comm", function (comm) { }) + + // Create a comm -- this will be receprocated by Julia, and will trigger the + // method IJulia.CommManager.register_comm(Comm{:webio_comm}, x) which will + // set up forwarding of messages + var comm = commManager.new_comm("webio_comm", {}) + + // Set how WebIO communicates with Julia + WebIO.sendCallback = function (msg) { comm.send(msg) } + + // dispatch messages from Julia to WebIO + comm.on_msg(function (msg) { + WebIO.dispatch(msg.content.data) + }); + + // Get existing Scopes ready + WebIO.triggerConnected() } $(document).ready(function() { diff --git a/src/providers/ijulia.jl b/src/providers/ijulia.jl index cfc4d7c4..f2f3d805 100644 --- a/src/providers/ijulia.jl +++ b/src/providers/ijulia.jl @@ -13,6 +13,14 @@ Base.isopen(c::IJuliaConnection) = haskey(IJulia.CommManager.comms, c.comm.id) WebIO.register_renderable(T::Type, ::Val{:ijulia}) = nothing +function IJulia.CommManager.register_comm(comm::IJulia.CommManager.Comm{:webio_comm}, x) + conn = IJuliaConnection(comm) + comm.on_msg = function (msg) + data = msg.content["data"] + WebIO.dispatch(conn, data) + end +end + function main() if !IJulia.inited # If IJulia has not been initialized and connected to Jupyter itself, @@ -48,14 +56,6 @@ function main() \$('.js-collapse-script').parent('.output_subarea').css('padding', '0'); """)) - - comm = IJulia.CommManager.Comm(:webio_comm) - conn = IJuliaConnection(comm) - comm.on_msg = function (msg) - data = msg.content["data"] - WebIO.dispatch(conn, data) - end - nothing end WebIO.setup_provider(::Val{:ijulia}) = main() # calling setup_provider(Val(:ijulia)) will display the setup javascript