Published
Edited
Aug 7, 2021
1 fork
Importers
32 stars
Insert cell
Insert cell
function set(input, value) {
input.value = value;
input.dispatchEvent(new Event("input", { bubbles: true })); // Native events bubble, so we should too
}
Insert cell
Insert cell
MyInput = ({value = 0} = {}) => {

const output = htl.html`<output>`;

const node = htl.html`<div>
<button onclick=${() => set(node, value - 1)}>−</button>
<button onclick=${() => set(node, value + 1)}>+</button>
My value is ${output}
</div>`;

// Update the display whenever the value changes
Object.defineProperty(node, "value", {
get() {
return value;
},
set(v) {
output.value = value = +v;
}
});

// Set the initial value
node.value = value;

return node;
}
Insert cell
Insert cell
viewof example = MyInput()
Insert cell
Insert cell
example
Insert cell
Insert cell
Inputs.bind(Inputs.range([-10, 10], {step: 1}), viewof example)
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more