-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[declarative-custom-elements] how does the class get associated with the definition #884
Comments
I'll assume that the proposal was missing the What happens if there are multiple script tags? <definition name="my-element">
<template>....</template>
<script type="module">
export default class MyElement extends HTMLElement {
// ...
}
</script>
<script type="module">
export default class MyOtherElement extends HTMLElement {
// ...
}
</script>
</definition> Should the Maybe the following is for another spec, but it seems there should be a way, in general, to grab the exports of a type=module script tag, f.e. <script type="module">
export default class MyOtherElement extends HTMLElement {
// ...
}
</script>
<script>
const s = document.querySelector('[type=module]')
// Similar to ES import():
s.import().then(m => console.log(m.default)) // logs MyOtherElement class
</script> Or maybe also something like <script type="module" name="MyOtherElement">
export default class MyOtherElement extends HTMLElement {
// ...
}
</script>
<script>
const s = document.querySelector('[type=module]')
// Using ES import():
import('script:MyOtherElement').then(m => console.log(m.default)) // logs MyOtherElement class
</script> |
The class should indeed be
I think we can easily say that only the first of last module is used. |
I just wanted to throw out the possibility that we could morph server rendered HTML that is rendered into the live DOM tree into a "template" for a web component that could be used by other single tags. An example of how this could be useful: A server-rendered side nav component used for the hamburger menu. Then it could "progressively" be used to define the web component. Another example would be a slide show web component, where we want to display the initial slide before all the dependencies have been loaded. POC here. I think the performance would be better, especially if the JavaScript may have numerous dependencies that need to load before the web component could become active. |
It would also allow streaming to be utilized for the first instance of the declarative web component. |
Something to note: This solution does not require that the developer write any JavaScript, not even defining a class! Just specify prop names, which can be set via attributes, which template instantiation (especially template instantiation that uses comments for placeholders ) could fill in. Basically, do as much as possible with JSON definitions (which I believe could cover a large chunk of declarative web components). |
DCE does not have to use JS and IMO the "pure" DCE would be JS-less. The class would be created by the browser and use the native templating for content rendering. The element life cycle events and callbacks can be assigned either as inline
or
The |
@trusktr , |
WCCG had their spring F2F in which this was discussed. You can read the full notes of the discussion (WCCG had their spring F2F) in which this was discussed, heading entitled "Declarative Templating & Custom Elements". This was briefly discussed as part of that topic. The consensus from present members of the WCCG was that more use cases need to be captured around this area, in order to clarify what these proposals solve. |
In the following,
how does the engine know to define the
<my-element>
element using theMyElement
class?How does
type="module"
come into play here? What happens if type=module were not included?What happens if I write two classes in the script tag? F.e.
Or is the example in the proposal missing an
export
? Should it be?
Happy to propose changes to the proposal file once this is cleared up.
The text was updated successfully, but these errors were encountered: