Question about components (not web components)
See original GitHub issueI 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
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:
- Created 2 years ago
- Comments:12 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
then I believe custom elements are the primitive you’re looking for … see uce, ube, or p-cool elements
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.