-
Notifications
You must be signed in to change notification settings - Fork 113
Export and import #121
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
Export and import #121
Conversation
Hey, Ana! Could you join all commits in only 1? |
Btw, did you check if the english version had changes? Some pt-br articles are way back... https://github.com/javascript-tutorial/en.javascript.info |
Of course! No problem.
I didn't, to be honest. But I'll check that and the above comment and return, okay? |
No problem! Let me know when you're done and I'll review your PR. |
It's done. Thank you! |
Right! I'll review it. Wouldn't you like to become a maintainer? Ask iliakan in an issue in the main repository and he will grant you permission. |
Ana, in your commit there is a change to 1-js/01-getting-started/2-manuals-and-specifications/article.md → 1-js/01-getting-started/2-manuals-specifications/article.md. Could you remove it? I think you added it by mistake. |
|
||
# Export and Import | ||
As diretivas Export e import tem diversas variantes de sintaxe. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we leave export in lowercase aswell?
``` | ||
...Then the optimizer will automatically detect it and totally remove the other functions from the bundled code, thus making the build smaller. That is called "tree-shaking". | ||
...Então o otimizador vai ver isso e remover as outras funções nã utilizadas nó código, tornando o build menor. Isso é chamado de "tree-shaking". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There're two minor typos "nã" and "nó" código.
``` | ||
...Then the optimizer will automatically detect it and totally remove the other functions from the bundled code, thus making the build smaller. That is called "tree-shaking". | ||
...Então o otimizador vai ver isso e remover as outras funções nã utilizadas nó código, tornando o build menor. Isso é chamado de "tree-shaking". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing the "from the bundled code" part.
2. Explicitly listing what to import gives shorter names: `sayHi()` instead of `lib.sayHi()`. | ||
3. Explicit imports give better overview of the code structure: what is used and where. It makes code support and refactoring easier. | ||
2. Listar explicitamente o que importar nos fornece nomes mais curtos: `sayHi()` ao invés de `say.sayHi()`. | ||
3. Uma lista explícita do que importar fornecem uma visão geral melhor da estrutura do código: o que é usado e onde. Torna o código fácil de prover suporte e de refatorar. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor typo: "Uma lista ... fornece" and not "fornecem".
|
||
new User('John'); | ||
``` | ||
|
||
Imports without curly braces look nicer. A common mistake when starting to use modules is to forget curly braces at all. So, remember, `import` needs curly braces for named imports and doesn't need them for the default one. | ||
Imports sem chaves parecem mais agradáveis. Um erro comum quando se começa a usar módulos é esquecer das chaves. Então, lembre-se, `import` precisa de chaves para import nomeados e não precisa para os imports default. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it would be better to use "imports nomeados (named imports)". What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with that.
|
||
Usually, to avoid that and keep the code consistent, there's a rule that imported variables should correspond to file names, e.g: | ||
Geralmente, para evitar isso e manter o código consistente, existe uma regra que as variáveis importadas deve corresponder ao nome dos arquivos, por exemplo: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor typo: "variáveis importadas deve" -> "variáveis importadas devem"
@@ -306,133 +305,152 @@ import func from '/path/to/func.js'; | |||
... | |||
``` | |||
|
|||
Another solution would be to use named exports everywhere. Even if only a single thing is exported, it's still exported under a name, without `default`. | |||
Ainda assim, algumas equipes consideram isso uma séria desvantagem dos exports default. Então, eles preferem usar sempre exports com nomes. Mesmo se apenas uma coisa é exportada, ele ainda será exportada com um nome, sem `default`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it not be "ela ainda será" ?
|
||
Now, as the actual exported functionality is scattered among the package, we can gather and "re-export" it in `auth/index.js`: | ||
Como as funcionalidade exportadas estão espalhadas pelo pacote, podemos importá-las em `auth / index.js` e exportá-las neles: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor typo: "exportá-las neles" -> "exportá-las nele"
} | ||
``` | ||
|
||
...But what if we really need to import something conditionally? Or at the right time? Like, load a module upon request, when it's really needed? | ||
... Mas e se realmente precisarmos importar algo condicionalmente? Ou na hora certa? Como carregar um módulo mediante solicitação, quando é realmente necessário? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you missed a comma after "Como". With a comma, the following becomes an example rather than a question How.
Please make the requested changes. After it, add a comment "/done". |
/done |
|
||
# Export and Import | ||
As diretivas export e import tem diversas variantes de sintaxe. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, Ana, I missed this one: "As diretivas ... têm" <- circumflex
Please make the requested changes. After it, add a comment "/done". |
/done |
No description provided.