Skip to content

docs: Document :bind attribute in html-syntax.md #19

@tormnator

Description

@tormnator

The :bind attribute is a useful feature for spreading object properties directly onto child components, but it has no dedicated documentation section in html-syntax.md.

What :bind does

Instead of passing individual named props, :bind spreads an object's keys directly as flat properties on the receiving component — so the child can reference them by name without any wrapper object.

Suggested addition

Add a new Binding objects section in docs/html-syntax.md, inserted right after the Conditionals section, covering:

  • Basic usage: <component :bind="obj"/> spreads all keys of obj as props
  • Shorthand for looping: <product-card :each="item in products" :bind="item"/>
  • Using { this } to spread the current component's own data
  • Reactivity: when the bound object is replaced, the child re-renders

Real-world example (from blog.html)

<author :bind="authors[author || authors.default]"/>

<author class="author row">
  <img src="{ img }">
  <h3>{ name }</h3>
  <a href="//x.com/{ username }">@{ username }</a>
</author>

The authors[...] object is spread, so img, name, and username are accessible flat inside <author>.

References

  • Implementation: packages/nuedom/src/dom/node.js (getAttrData function)
  • Tests: packages/nuedom/test/component.test.js (:bind and :bind this)

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions