viperHTML / viperhtml.github.io

Showcase of the ${hyper,viper,native}HTML family
ISC License
27 stars 11 forks source link

Add Vue input list bindings example. #16

Closed albertosantini closed 6 years ago

albertosantini commented 6 years ago

This example shows a list of inputs.

The template is tricky and the casual user can implement it in a different way with different results: from wrong rendering to runtime errors.

The follow-up is not straightforward from the basic input binding example: indeed there is a getWire using an integer instead of an object, (the wire parameter).

I didn't modify js/index.js, providing a live demo, because the snippets are in webreflection context. I am afraid you need to add it yourself.

Fix #11

WebReflection commented 6 years ago

I think you are complicating your life with that getWire() ... the id is there to help these cases:

const App = {
  html: hyperHTML.bind(document.querySelector("#app")),
  data: {inputs: ["a", "b", "c"]},
  onInput(event, index) {
    this.data.inputs[index] = event.target.value;
    this.render();
  },
  render() {
    this.html`${this.data.inputs.map(
      (inp, index) => hyperHTML.wire(this, ':' + index)`
      <input value=${inp} oninput=${e => this.onInput(e, index)}><br>`
    )}${JSON.stringify(this.data.inputs)}`;
  }
};
App.render();
albertosantini commented 6 years ago

Agreed. Removed.