Polight / lego

🚀 Low-Tech Web-Components Made Lightweight & Future-Proof.
https://lego.js.org
MIT License
123 stars 19 forks source link

Enable hyphened attribute to state #29

Closed vinyll closed 2 years ago

vinyll commented 2 years ago

Today attribute must be one word:

<my-user firstname="John"></my-user>

We may need to consider hyphened attributes, which are HTML compliant:

<my-user first-name="John"></my-user>

A proposal would be to access this property in camelCase:

bricks/my-user.html

<script>
  <template>
    <p :if="state.firstName">Hello ${state.firstName}</p>
  </template>
  init() {
    this.state = { firstName: "" }
  }
</script>

It might need to be set in the setAttribute() extended function if it the __attributesToState() is not enough.

vinyll commented 2 years ago

fixed in 1.7.0.

passing an attribute as <x-user first-name="John"></x-user> will make it reactively available to state as state.firstName.