thebe icon indicating copy to clipboard operation
thebe copied to clipboard

Unable to listen to thebelab.events triggers

Open joelachance opened this issue 5 years ago • 4 comments

I'm attempting to run custom code in Thebelab, given the example in the docs:

thebelab.events.on("request-kernel")((kernel) => {
    // Find any cells with an initialization tag and ask ThebeLab to run them when ready
    kernel.requestExecute({code: "import numpy"})
}

I'm finding a couple of things here:

  1. There are syntax errors here. We need a closing bracket at the end of the code block in both examples in the docs
  2. thebelab.events.on() does not return a function

I assumed that the on function wanted a callback, but that also did not work.

Events code:

// events

export const events = $({}); // This is undefined when run in the browser, given we have jQuery as `$`
export const on = function() {
  events.on.apply(events, arguments); // since the above is undefined, this doesn't work
};
export const one = function() {
  events.one.apply(events, arguments);
};
export const off = function() {
  events.off.apply(events, arguments);
};

I don't fully understand what is happening above since I'm expecting events to have an on function assigned to it somewhere. I assume the on, one, and off functions might be getting added to the events object in another file?

I'd be happy to submit a PR to fix some of this, but I'm not sure what the original intention was for the events feature. If there's any insight into how this should work, I propose the following:

  • [ ] Update the events code
  • [ ] Add some unit tests
  • [ ] Update documentation

joelachance avatar Apr 01 '20 15:04 joelachance

As a general rule, I think that folks are friendly to PRs, though I believe the core maintainers (particularly @minrk ) are pretty unavailable right now due to lots of other work-related fires that have popped up. Just a note to set expectations around timing etc :-) I would review your PR, but I don't think I have the javascript chops to make substantive contributions there

choldgraf avatar Apr 03 '20 16:04 choldgraf

also in case it's helpful, I have code that does something similar to what you're trying here: https://github.com/jupyter/jupyter-book/blob/master/jupyter_book/book_template/_includes/js/thebelab.html#L65 perhaps that can be used as inspiration?

choldgraf avatar Apr 03 '20 16:04 choldgraf

@choldgraf , understood! I'm going to try and put some effort into this in the coming weeks, and hopefully all we need are some light code changes so a PR isn't so scary to merge.

Thanks for the response!

joelachance avatar Apr 06 '20 14:04 joelachance

That would be great - I'd be happy to see some love put into Thebelab ✨

choldgraf avatar Apr 06 '20 15:04 choldgraf