using import...with to inject viewof / mutable cells

Consider the following notebook, which tests using the import…with syntax to inject views:

My guess is that “Example 2” is the right way to do this sort of thing, although it’s a little confusing to me still.

However, there is an inconsistency between the behavior on observablehq.com and an embedded version of that notebook.

2 Likes

Here’s a more concrete suggestion.

The code in the v3 runtime ES module at api.observablehq.com that is generated for this:

import { viewof a as a2, b as b2 } with {
  viewof myA as a
} from '8135ff976018a995'

is currently:

const child2 = runtime.module(define1).derive([{name: "myA", alias: "a"}], main);
main.import("viewof a", "viewof a2", child2);
main.import("a", "a2", child2);
main.import("b", "b2", child2);

I think it should be:

const child2 = runtime.module(define1).derive([{name: "viewof myA", alias: "viewof a"},{name: "myA", alias: "a"}], main);
main.import("viewof a", "viewof a2", child2);
main.import("a", "a2", child2);
main.import("b", "b2", child2);

instead, to match the behavior on observablehq.com. (And something similar for mutable cells.)

1 Like

Your suggestion sounds correct to me. I’ll investigate.

1 Like

This has been fixed. Thank you for the report!

2 Likes