1
00:00:02,270 --> 00:00:04,730
And with that, we're almost done.

2
00:00:04,730 --> 00:00:10,160
Now one important question might remain though, when you're working with modules and you have some code

3
00:00:10,490 --> 00:00:13,150
that runs inside of the module file,

4
00:00:13,190 --> 00:00:18,740
so which is not a class which you find on export but let's say here in project item, if we have a console

5
00:00:18,740 --> 00:00:24,100
log statement saying project item created,

6
00:00:24,310 --> 00:00:29,190
is this code executed or is only exported code executed?

7
00:00:29,200 --> 00:00:30,420
Well let's find out.

8
00:00:30,430 --> 00:00:34,370
This is my console log statement, here is my console,

9
00:00:34,380 --> 00:00:37,470
if I now reload, we see that output.

10
00:00:37,470 --> 00:00:45,360
So code in your modules runs when the module is imported and loaded for the first time and that's important,

11
00:00:45,600 --> 00:00:47,150
for the first time.

12
00:00:47,220 --> 00:00:53,220
If you have a module which is imported multiple times, like DOM helper which I imported in project item

13
00:00:53,280 --> 00:00:57,000
but also in project list, then it still only runs once.

14
00:00:57,000 --> 00:01:05,400
So if I go here into my DOM helper class and I add console log here, DOM helper executing,

15
00:01:08,320 --> 00:01:10,330
we'll see that this only gets printed once

16
00:01:10,330 --> 00:01:15,670
even though we import from this file twice but it only runs on the first import

17
00:01:15,700 --> 00:01:23,260
so to say. So if I reload here, we see DOM helper executing but it never runs thereafter.

18
00:01:23,350 --> 00:01:30,150
What if we have some code in a dynamically loaded file, like tooltip which we just dynamically loaded

19
00:01:30,340 --> 00:01:36,650
Well let's output something here, tooltip loading or running, whatever you want.

20
00:01:36,940 --> 00:01:38,090
Let's output this here,

21
00:01:38,230 --> 00:01:39,330
let's reload,

22
00:01:39,370 --> 00:01:43,150
of course we see no output initially because the file hasn't been loaded.

23
00:01:43,180 --> 00:01:48,250
If I click on more info, we see this but only for the first time, if I click on more info thereafter, it

24
00:01:48,250 --> 00:01:50,740
does not run again.

25
00:01:50,740 --> 00:01:58,600
So code in modules does execute and of course sometimes you want that, you need that behavior but it

26
00:01:58,690 --> 00:02:03,970
only executes once when a module is imported and used for the first time.

