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.
