Conversation
This comment was marked as resolved.
This comment was marked as resolved.
| let value = valueof(element); | ||
| const inputted = () => change(valueof(element)); | ||
| const inputted = (event) => change(valueof(event.target)); |
There was a problem hiding this comment.
The fact that the initial value is valueof(element) while subsequent values are valueof(event.target) suggests that this may not be desirable. I see the benefit of being able to listen to a parent element, but in that case, how to determine the initial value of the generator? The generator would need to search within the container for an element that exposes a value. (And pick the first of multiple, arbitrarily?)
We could have the resize helper proxy the value of the returned element. Then you could say:
```js
const chart = resize((width) => scatterPlot(width));
const value = Generators.input(chart);
```
<div class="grid grid-cols-1">
<div class="card">${chart}</div>
</div>There was a problem hiding this comment.
Good remark, I hadn't thought about the initial value. I think I'd prefer the “search” approach because it would be easier to use — and also because it fits my mental model of an event that bubbles up (wants to be seen and useful).
Currently when you wrap an interactive element in a
div, maybe for aesthetic reasons, or because you want to add a title, use theresizehelper, etc., you can't useGenerators.inputto read the value — or you need to copy the value somehow to the top-level element, as we do in Plot with thefigureelement.This, even though the
inputevent bubbles up, which makesGenerators.inputslightly inconsistent.This change makes Generators.input read the value on the
inputevent’s target, making the most of theinputevent.Note: if there are several inputs inside the "chart", so that whichever input (chart) you're touching returns its value. To combine values, you still need to use Inputs.form (but maybe Inputs.form could benefit from the same treatment?)
(OP: #1806 (reply in thread))
Leaving as a draft as there may be unwanted consequences that I'm not seeing. Though I guess a developer should explicitly opt out of event bubbling if they don't want to expose the input up in the hierarchy?