Improve docs for custom elements, destructors · Issue #688 · unpoly/unpoly · GitHub
Skip to content

Improve docs for custom elements, destructors #688

Open

Description

@bdavidxyz

URL where to find the error

There is no error.

I need a better understanding of

https://unpoly.com/loading-indicators#custom-loading-indicators

Which section should be improved

I have found this excerpt here to raise new concepts that are not enlightened elsewhere in the docs:

<loading-indicator>Please wait!</loading-indicator>
up.compiler('loading-indicator', function(indicator) {
  function show() { up.element.show(indicator) }
  function hide() { up.element.hide(indicator) }

  hide()

  return [
    up.on('up:network:late', show),
    up.on('up:network:recover', hide)
  ]
})

How should this section be improved?

Here are my questions :

  • So Unpoly allows to define custom HTML elements (here the loading-indicator)? Is there another parts of the docs that talks about it?
  • the return [] of an array seems undocumented elsewhere. The compiler is supposed to return a function, where you can clean up/destroy things when the element is un-mouunted. Is there other parts of the docs that talks about it ?

Thanks!

Activity

  1. changed the title [-]Docs : custom components and compiler[/-] [+]Improve docs for custom elements, destructors[/+] on Dec 16, 2024
  2. triskweline commented on Dec 16, 2024

    @triskweline
    Contributor

    Good catch, all of this needs to be documented.

    So Unpoly allows to define custom HTML elements (here the loading-indicator)?

    You can compile arbitrary CSS selectors so it works on your own custom elements, too. Can be ergonimic way if you just need to initialize some JS. If you need to do more (e.g. open a shadow root or attach element internals), the canonical customElements.define() will work, too.

    I'm make a guide page for that. Also how to have custom form fields participate in form submissions etc.

    the return [] of an array seems undocumented elsewhere. The compiler is supposed to return a function, where you can clean up/destroy things when the element is un-mouunted. Is there other parts of the docs that talks about it ?

    You can also return an array of functions. Useful when you need to undo multiple things. I'm going to make a pass over the destructor docs.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions