Skip to content

How come we don't need to register a component when we import it? #4

@luc4leone

Description

@luc4leone

Hi Ben,

I did not expect listing 5.7 to work, because in strings.js we are not registering the component WebHarpString. We are importing WebHarpString

import WebHarpString from "../string/string.js";

but we are not registering it

customElements.define('webharp-string', WebHarpString);

Instead it works! How?

For example, when in index.html we run

<script type="module" src="./components/app/app.js"></script>

we are "importing" the entire app.js code, which include the registration of the WebHarpApp component,

customElements.define("webharp-app", WebHarpApp);

so, in index.html I would expect

<webharp-app strings="8"></webharp-app>

to work just fine. While the code in strings.js so far for me, it's magic ☺️


PS: not important: in app.js I don't think we need to export default the class WebHarpApp

export default class WebHarpApp extends HTMLElement { //...

since with the script tag in index.html

<script type="module" src="./components/app/app.js"></script>

we are taking in the entire module, right?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions