Skip to content

Easy way to serialize all host component attributes/props in JavaScript #104

Closed

Description

@zachleat

Notably you can use webc:root to re-use and merge host component attributes in a component definition in markup.

https://www.11ty.dev/docs/languages/webc/#attributes-and-webcroot

This would be the script alternative to this (for webc:type="js" or webc:type="render")

cc @ascorbic

Activity

  1. ascorbic commented on Feb 14, 2023

    @ascorbic

    Adding something like a "props" object that contains them all would be a big help here too, as it would at least let us do it manually. I tried using "this" but of course that has loads of other stuff on it so didn't work.

  2. added this to the WebC v0.9.0 milestone on Feb 16, 2023
  3. zachleat commented on Feb 16, 2023

    @zachleat
    MemberAuthor

    A new webc.attributes object and webc.renderAttributes() function will now be available to transforms (e.g. webc:type="js" and webc:type="render"). For consistency these will also be available (though less usefully) in dynamic attributes and @html/webc:if.

  4. zachleat commented on Feb 16, 2023

    @zachleat
    MemberAuthor

    Related test has a usage example, notably this will not render private props:

    https://github.com/11ty/webc/blob/06768af3fb20b1d416276f2f07ac3865a4f3a80c/test/issue-104-test.js
    https://github.com/11ty/webc/blob/06768af3fb20b1d416276f2f07ac3865a4f3a80c/test/stubs/issue-104/component.webc

    <script webc:type="js" webc:root="override">
    `<img ${webc.renderAttributes(webc.attributes)}>`
    </script>

    Will ship with WebC v0.9.0

  5. ascorbic commented on Feb 17, 2023

    @ascorbic

    Perfect! Thank you

  6. zachleat commented on Feb 22, 2023

    @zachleat
    MemberAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions