I have been trying to adapt these first 3 cells from the Synchronized Inputs documentation to work in notebook 2.0, but without success:
function set(input, value) {
input.value = value;
input.dispatchEvent(new Event("input", {bubbles: true}));
}
viewof x = Inputs.range([0, 100], {step: 1})
Inputs.button([
["Set to 0", () => set(viewof x, 0)],
["Set to 100", () => set(viewof x, 100)]
])
What should replace viewof x inside set(viewof x, 0) or is there a better 2.0 pattern for programmatic control of reactive values? I often used Inputs.input in my 1.0 notebooks with this set() function.
You are asking how to implement synchronized inputs in Vanilla JavaScript (rather than Observable JavaScript), right?
The main thing is that you need to separate the input (the range slider; the interface control) from the reactive input value (which in Observable is expressed as a Generator). This means you need to define two top-level variables: