That is problematic, because whenever I re-evaluate that cell, it creates a new bit of WASM code, which means that in the end we have tons of loops trying to paint to the same Canvas.
What I need is something that automatically closes this kind of loop when a cell gets re-evaluated. Is there a good general technique for that?
(this is also the only thing stopping me from just importing a textarea from @jashkenas’ input notebook and recreating the Walt Explorer in a notebook)
You’re very welcome, and there’s really no need for the attribution. And to nitpick my own code: the function should actually be called “stop” or “pause”, because you can always call run() afterwards to resume.
Credit where credit is due: I didn’t even know requestAnimationFrame returns a cancellable ID until I saw it in one of @mbostock’s notebooks.
I was curious what the fix was, but unfortunately the above link no longer shows the diff between the old version of the notebook and mootari’s version. After fooling around a bit with the version numbers using mootari’s other helpful notebook, I think I found a permalink for the original suggestion. Here it is, for future visitors: https://beta.observablehq.com/compare/68a39e4424361cdd@172...8391cfe751bca050@174
Presumably such version-pinned compare links will be easier to generate as more “history” features are added to Observable…
Oh come on, you linked to an solution that I could merge with the click of a button, of course you deserve attribution for that. If it makes you feel better: it felt a bit weird without context so I moved it to a code comment above the line showing it. Now you only see the attribution when expanding the cell