Replies: 16 comments 5 replies
-
Slides - https://whimsical.com/dce-and-dsd-8QrsieiVLhEmmyAejnug78 |
Beta Was this translation helpful? Give feedback.
-
I answered this on the call, but the big benefit is that we might not need JS for the most simple "I want a shadow root with content, slots, and scoped styles". If users have JS, this implementation has a way to progressively support that (with the script tags that have lifecycle methods), but isn't required to get that first bit of rendering. |
Beta Was this translation helpful? Give feedback.
-
I didn't go into it here, but I think if we have a way to import HTML and parse that, that would be all that's required - this probably isn't 1-to-1 with any module implementation, rather just "can we add and parse HTML". Tram-Deco supports this today with a dedicated class call |
Beta Was this translation helpful? Give feedback.
-
There's definitely a "how do I import other JS, how do I handle some callback attributes, etc..." that isn't totally fleshed out here, and would be solved by injecting a class definition here. I'm not sure I love having to intermingle the DCE and class definitions together, but I'm not totally opposed to it. I still think the ergonomics of per-lifecycle method script tags is nicer, and classes can be a large hurdle for non-JS developers getting into web components, but that's totally a biased take 😄 |
Beta Was this translation helpful? Give feedback.
-
In part, I'm leaning hard on whatever the DOM Parts initiative comes up with. While reactivity with attribute templating would be really awesome, I feel like that's a separate initiative that doesn't have to come before DCE (and certainly shouldn't be exclusive to DCE). |
Beta Was this translation helpful? Give feedback.
-
I haven't thought through that, but I don't think there's a reason that a script tag couldn't have a custom lifecycle method (maybe that's a strong enough reason to have a more generic <template definitions>
<my-dce-modal>
<template shadowrootmode="open">
<dialog>My Dialog</dialog>
</template>
<script method="show">
this.shadowRoot.querySelector('dialog').show()
</script>
</my-dce-modal>
</template> |
Beta Was this translation helpful? Give feedback.
-
In the template each element definition contains its own lifecycle method scripts, e.g. <template definitions>
<my-foo>
<script connectedcallback>
console.log('my-foo created', this)
</script>
</my-foo>
<my-bar>
<script connectedcallback>
console.log('my-bar created', this)
</script>
</my-bar>
</template> This depends on the template parsing to know "associate the script with its parent element", which I hope is trivial, but admittedly, I don't know if we have a pattern of that in the standards. |
Beta Was this translation helpful? Give feedback.
-
Yeah, for sure - I think this represents the most simple first-step forward that I've been experimenting with, and all the feedback here is super valuable to expanding this POC out. I'd maybe push back on the light dom rendering and anything that isn't already possible in the Web Components API, since I would like this to be 1-to-1 with what's possible in class based definitions, but if we think that's something that could be possible in class based definitions, then I'd totally concede that we need a way to do it here as well. |
Beta Was this translation helpful? Give feedback.
-
I guess there is a larger question about where we allow definition templates, and how composable they can / should be. I haven't totally thought through that here. In Tram-Deco you specifically call out which templates to process, and maybe we could mimic that here (since creating custom registries requires JS anyways). E.g. in the example below, we intentionally omit the <template id="myCustomElements">
<callout-alert>
<!-- element definition stuff -->
</callout-alert>
</template>
<script>
myCustomElementRegistry.parse(myCustomElements)
</script> |
Beta Was this translation helpful? Give feedback.
-
I believe this is the same question that was asked live, but in general, I think this question is about what the expected behavior is if a template has both of these attributes. We have some pattern in the standards (specifically looking at script elements) where attributes are mutually exclusive, and I think this is a similar situation, where you can only have one or the other. |
Beta Was this translation helpful? Give feedback.
-
I believe this question was asked live, and was specifically asking what if you define multiple elements with the same name. I think we would want to emit some sort of warning, I don't imagine this problem is unique to this solution, or even DCE (although we have better options for end users to catch errors in JS-land than we do in HTML). The current implementation in Tram-Deco uses |
Beta Was this translation helpful? Give feedback.
-
Similar to the above question about duplicate children, there's probably a generic question on how these DCE implementations interact with In Tram-Deco this creates a class, but understandably that feels weird if JS isn't a requirement for these to process as expected. |
Beta Was this translation helpful? Give feedback.
-
There was a general comment live about this coupling the implementation of Declarative Shadow DOM to Custom Element definitions. Luckily the Tram-Deco solution doesn't expect anything special from DSD, rather it consumes it sorta as-is - since we don't have any attribute templates or anything like that, we copy the created shadow DOM with all of it's attributes and clone it on construction. I think that this won't need any modifications on the existing DSD API. This does tie the custom element definition to look for DSD and pick it up for Component creation. Potentially we could just pick up any non-script elements instead (if they are DSD, copy that, if they are light DOM elements, copy that) - but that feels very non-web-component API. As it is, I believe that you can create a web component with a DSD template inside it, and it automatically knows to use that template, so this feels similar to that interface. |
Beta Was this translation helpful? Give feedback.
-
The current implementation in Tram-Deco blows up with whatever error you would get from I think this problem isn't unique to this implementation, although there may be a special frustration if you can't include other kinds of DOM (like comments) in the element definition template. I'm pretty sure the check I have in Tram-Deco only looks for children elements though, so that should be relatively safe. I think, like the duplicate elements issues, we need some way to safely warn / blow up on the user when they would try to define an invalid element (whether that's because it is already defined, doesn't have hyphens, or whatever). |
Beta Was this translation helpful? Give feedback.
-
The goal here is finding the absolute shortest path to DCE, so I think leaning on the existing pattern for templates with attributes feels fine. It is possible to introspect the elements that have been defined using If you have examples of advance introspection you are doing in any DCE solution, would be happy to investigate here and see if there is a solution here as well! |
Beta Was this translation helpful? Give feedback.
-
The idea here is to tap into the existing supported API for DSD. That means also consuming attributes like |
Beta Was this translation helpful? Give feedback.
-
As presented on 18 March to the WCCG,
tram-deco
is a proposed approach to declarative custom elements by @JRJurman.Links to slides TK as available.
Further discussion and questions below.
Beta Was this translation helpful? Give feedback.
All reactions