-
Notifications
You must be signed in to change notification settings - Fork 20
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
How come we don't need to register a component when we import it? #4
Comments
Hi Luca! I don't have my book handy right now, but I'm looking over the source code in this repo.
You might be thinking that, "well, we're only importing the class, so this code wouldn't get run", but that's not true! Any code in a module will run, and it's called a module "side effect". Try just putting a Again, haven't looked at this code in ages, but honestly I'm not seeing a need to use the full import as I wrote it: It could really be: The reason for that is that all we need is for those side effects to run. We're not using the Anyway, it's pretty typical for a Web Component to self-define by using the module side effects like this. And yes! I think you are correct on that last point:
Hope that helps! |
That's exactly what I was thinking! Ahah Thanks for the explanation Ben, now all is clear. I didn't know about "import side effects" and I didn't think about the console.log experiment. By the way, I like the way you do experiments in the book also. I am trying to learn from your approach. |
So glad you're enjoying! Thanks for the compliments 😊 |
Hi Ben,
I did not expect listing 5.7 to work, because in
strings.js
we are not registering the componentWebHarpString
. We are importingWebHarpString
but we are not registering it
Instead it works! How?
For example, when in
index.html
we runwe are "importing" the entire
app.js
code, which include the registration of theWebHarpApp
component,so, in
index.html
I would expectto work just fine. While the code in☺️
strings.js
so far for me, it's magicPS: not important: in
app.js
I don't think we need toexport default
the classWebHarpApp
since with the script tag in
index.html
we are taking in the entire module, right?
The text was updated successfully, but these errors were encountered: