question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question about components (not web components)

See original GitHub issue

I have recently been approaching the lib coming from vdom based libs.

I see I can simply declare components like

const li = v => html`<li class="test">${v}</li>`

const ul = list => html`<ul class="test">${list.map(li)}</ul>`

Is there a way to attache an event listerner to a component (the result of the function) and be able intercept only events from that component? Try to explain the API I would like to obtain

const isolate =  component => {
   //...
   return {
       component: ...,
       on: selector => event => callback => {
         // .... return unsubsribe
         }
   }
}

const LI = v => html`<li class="test">${v}</li>`

const UL = list => html`<ul class="test"><li>ADD</li>${list.map(isolate(LI))}</ul>`

const {ul, on} = isolate(UL)

on('li')('click')(console.log)

Then the delegate (on the UL? and if I have other siblings?) would act on events on the first

  • but not on other because owned by different components.

    Any suggestion on how to obtain something similar? I think I can hack the template strings and add ref=“” to root elements to react to element creations and mark root elements of components in some way. Or there are better solutions?

  • Issue Analytics

    • State:closed
    • Created 2 years ago
    • Comments:12 (6 by maintainers)

    github_iconTop GitHub Comments

    1reaction
    WebReflectioncommented, Nov 4, 2021

    then I believe custom elements are the primitive you’re looking for … see uce, ube, or p-cool elements

    0reactions
    FbNcommented, Nov 4, 2021

    Thank you I will give a look, so many projects. Sorry I found only now the discussion thread (https://github.com/WebReflection/discussions/discussions) that would be a better place to ask than this issue. I’ll close it and open a discussion if I have other questions. Thank you very much for your support.

    Read more comments on GitHub >

    github_iconTop Results From Across the Web

    Practical Questions around Web Components
    Do Custom Element names bring any benefit? Can we progressively enhance Web Components? Can we render Web Components on the client and server?...
    Read more >
    Web Components - MDN Web Docs - Mozilla
    Web Components is a suite of different technologies allowing you to create reusable custom elements — with their functionality encapsulated ...
    Read more >
    A Complete Introduction to Web Components in 2022 - Kinsta
    Web Components are a standard way to create reusable and modular HTML elements without using a JavaScript framework.
    Read more >
    The problem with web components - Adam Silver
    Web components are becoming increasingly popular but they have a number of drawbacks. In this article I'll explain what those are and what...
    Read more >
    What happened to web components? - LogRocket Blog
    One of the most asked questions about web components is where or how to find them. Currently, web components don't have a distinct...
    Read more >

    github_iconTop Related Medium Post

    No results found

    github_iconTop Related StackOverflow Question

    No results found

    github_iconTroubleshoot Live Code

    Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
    Start Free

    github_iconTop Related Reddit Thread

    No results found

    github_iconTop Related Hackernoon Post

    No results found

    github_iconTop Related Tweet

    No results found

    github_iconTop Related Dev.to Post

    No results found

    github_iconTop Related Hashnode Post

    No results found