So I was thinking it would be quite easy for me to create some small WASM functions using Walt. The output would be really small binary blobs. But the notebook in question would have to download the whole Walt toolchain.
So if I import the function into another notebook - effectively just a single cell in said notebook - would that fetch just that cell, or the whole notebook + dependencies?
Put another way: lots of JS libraries have a minified distribution version. Do notebooks support something similar?
Yes, importing a cell from a notebook in Observable does import all of its dependencies. Consider for example the tutorial notebook itself:
The imported charts / graphics each use their own independent copies of d3. In particular, the d3 = require("https://d3js.org/d3.v5.min.js") cell at the bottom is actually unused (you can check this by commenting out the cell and observing that the notebook still works).
Also, according to that tutorial:
You can import the same notebook multiple times and references will resolve exactly.
The same should hold true for their dependencies, so I think this means you won’t have to worry about creating multiple copies of require statements when importing from the same notebook.
Importing a notebook fetches the code for the imported notebook in its entirety, and then runs the cells that were explicitly imported along with their transitive dependencies.
If you import a single cell from a notebook, and that cell depends on other cells in that notebook, the imported cell and all its dependencies are run. However, other cells in that notebook that are not depended upon by the imported cells are not run.
(Eventually, we may optimize the import implementation so that it only fetches the necessary subset of the code, too. And maybe we’ll even minify…)