Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't assume a global WebIO instance in JS code (fix JupyterLab). #288

Merged
merged 1 commit into from
Aug 6, 2019

Conversation

twavv
Copy link
Contributor

@twavv twavv commented Aug 6, 2019

This is a fix for now. In the short run, we should expose a way to load this kind of thing from within handlers (possibly via existing Asset stuff - but we'd need a way to do it synchronously probably).

Changes

  • Mark the built JS file as binary to exclude it from command line diffs :^)
  • Change the output target to be UMD module so that it is importable via SystemJS (this makes the export ... bits work)
  • Call the JS init function on scope mount with the current WebIO instance (it's available in onimport but not as part of the global scope).

Fixes JuliaGizmos/WebIO.jl#339.

@sglyon
Copy link
Member

sglyon commented Aug 6, 2019

Thanks @travigd -- I appreciate your continued help here.

The js code that I have been attaching to WebIO really doesn't need to be there. My goal is only to define a couple js functions that don't lean on WebIO in any way so that I can reference them in callbacks from the Julia side.

Can you think of a better way to make that happen across all platforms?

@twavv
Copy link
Contributor Author

twavv commented Aug 6, 2019

At this time, no - I think this is going to be the best workaround. What I'd like to do is make our existing asset-loading also include a synchronous (i.e. non-promise-based) API.

Currently, you can do this:

using WebIO
mybundle = Asset("./path/to/bundle.js")
# Setup the nodes and whatnot
onjs(foo, js"""
async function() {
  const bundle = await $mybundle;
  // Assuming bundle exports a function called foo
  bundle.foo();
}
""")

The issue is that it currently has to be async - which isn't the end of the world, but we could probably (I have to look into SystemJS internals to guarantee this) expose a synchronous API (it would throw an error if the asset hasn't already been loaded). Something like

onjs(foo, js"""
function bar() {
  const bundle = WebIO.loadSync($mybundle);
  bundle.foo();
}
""")

For right now, I think adding onto the WebIO instance is a good stopgap until we implement something like the above.

@sglyon sglyon merged commit e81fcc0 into JuliaPlots:master Aug 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PlotlyJS shows an emptycell in jupyterlab with no error
2 participants