Closed scottdraves closed 8 years ago
Unfortunately bkHelper.loadList can't just do the "defined = undefined" trick because it has to be in force then the fetched code is evaluated which happens asynchronously. we could use the success/failure callbacks to reset it back but that means that while it's running other code would also be tricked.
it might help if the javascript plugin had list of URLs to load in its spec and it handled them automatically? if that works it would be great because it hides the use of loadList which is also too much for users, and more like setting up the classpath which is more well known.
also maybe we should just always have "define = undefined" in the user's javascript.
This is actually harder than that to do right. The problem is if you have a notebook that loads a random JS file, then uses that code say to create an interactive chart, then you share the notebook, it will not work on the sharing server. And if someone downloads the notebook from the sharing server, then it would not work for them until they download and install the dependency.
So I propose an "importJS" command that not only loads the JS properly, but actually stores it in the notebook (in the namespace). This is actually a general problem for notebooks, not only for loading JS file but other random files that might be read by the code in a notebook. in each language, in the beaker runtime, we can provide this wrapped load function that caches the result in the notebook. It should check the file modtime every time it runs, and if the original file has been modified it should read it again.
a complication with the above is if the loaded JS file recursively loads other JS files. ideally you would detect that and cache them all in the notebook namespace.
new plan: in the language manager have some GUI for finding libs (eg bower github file url). when found, include in the notebook, and then have them loaded and accessible to code run in JS cells.
See https://github.com/twosigma/beaker-notebook/issues/421
basically if JS in a cell calls loadJS or loadList, and the loaded code tries to define a module, it will fail to load.
probably these function should do the define = undefined trick.