The `.value` is a lie.🎂 (on viewof'ed inputs at least)

Think of viewof as a macro that produces an additional Runtime Variable (internal represenation of a cell) for your viewof cell, so that you end up with two Variables:

  • viewof box, the cell that you originally defined,
  • box, which is a generator cell that listens to changes in viewof box via Generators.input and yields the new value.

Generators.input has some “magic” for inputs. Depending on the input type, it will:

  • listen to different events (e.g. “click” for checkboxes),
  • cast the value (e.g. via .valueAsNumber() for number and range inputs).

You can find the implementation details here:

In general I find that looking at a notebook’s generated source can give some insight into the underlying logic, e.g.:
https://api.observablehq.com/@observablehq/introduction-to-views.js?v=3

2 Likes