Skip to content
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

Question on code comment: 'This loop will terminate when the queue is empty.' #12

Open
conradlo opened this issue Jul 30, 2018 · 1 comment

Comments

@conradlo
Copy link

Thanks so much for this simple example!
It really revealed the 'magic' behind javascript bundler for me.

There is a point I'm not quite understand though.

Regarding the for .. of loop in the createGraph function

minipack/src/minipack.js

Lines 115 to 117 in ce3b1b5

// only has one asset but as we iterate it we will push additional new assets
// into the queue. This loop will terminate when the queue is empty.
for (const asset of queue) {

To my understanding, the loop will terminate when

  1. there are no more child asset being pushed to the end of query
  2. the code reached the end of query

which also means the the dependency graph was completed.
Hence the query will never be empty (there is at least one asset: the entry/main asset)
Or did I misunderstand something here?

@matheus1lva
Copy link

Yes, you are totally right. The loop will only stop when it reachs the leaf of the tree, in a better scenario, it has only main.js. In the worst scenario it has to go through all the tree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants