It seems to me that we ought to be able to automatically convert notebooks to vanilla js.
// https://observablehq.com/@pentacular/es6-module-generation-test@16
export default function define(runtime, observer) {
const main = runtime.module();
main.variable(observer()).define(["md"], function(md){return( md`# ES6 Module Generation Test`)});
main.variable(observer("times")).define("times", function(){return( (a, b) => a * b)});
main.variable(observer()).define(["md","times"], function(md,times){return( md`3 times 4 is ${times(3, 4)}`)});
main.variable(observer("square")).define("square", ["times"], function(times){return( (x) => times(x, x))});
main.variable(observer()).define(["md","square"], function(md,square){return( md`The square of 4 is ${square(4)}`)});
return main;
}
into
const times = (a, b) => a * b;
const square = (x) => times(x, x);
which would allow the definitions in the notebook to be used with vanilla js outside of the observable framework.
This module wouldnât support redefinition, but thatâs not normally used with vanilla js.
Youâd also need to do a topological ordering of the definitions by dependency, but thatâs not particularly difficult.
md tags could be stripped or rewritten to call some hookable function, and side-effecting leaves could be dropped or gathered into a âmainâ function of some kind.
I havenât thought about imports within the module, but since the es6 imports are dynamic, it probably shouldnât be too hard.
I was considering just writing a converter, but I thought Iâd see if there are issues Iâve overlooked, or if this is already planned.
Thanks.