minor fixes

This commit is contained in:
Ilya Kantor 2021-02-02 10:37:28 +03:00
parent 0c8a4fe995
commit 0806399c51
2 changed files with 13 additions and 5 deletions

View file

@ -1,4 +1,4 @@
# Logical operators # Logical operators: ||, && and !
There are four logical operators in JavaScript: `||` (OR), `&&` (AND), `!` (NOT), '??' (Nullish Coalescing). There are four logical operators in JavaScript: `||` (OR), `&&` (AND), `!` (NOT), '??' (Nullish Coalescing).

View file

@ -337,13 +337,19 @@ auth/
... ...
``` ```
We'd like to expose the package functionality via a single entry point, the "main file" `auth/index.js`, to be used like this: We'd like to expose the package functionality via a single entry point.
In other words, a person who would like to use our package, should import only from the "main file" `auth/index.js`.
Like this:
```js ```js
import {login, logout} from 'auth/index.js' import {login, logout} from 'auth/index.js'
``` ```
The idea is that outsiders, developers who use our package, should not meddle with its internal structure, search for files inside our package folder. We export only what's necessary in `auth/index.js` and keep the rest hidden from prying eyes. The "main file", `auth/index.js` exports all the functionality that we'd like to provide in our package.
The idea is that outsiders, other programmers who use our package, should not meddle with its internal structure, search for files inside our package folder. We export only what's necessary in `auth/index.js` and keep the rest hidden from prying eyes.
As the actual exported functionality is scattered among the package, we can import it into `auth/index.js` and export from it: As the actual exported functionality is scattered among the package, we can import it into `auth/index.js` and export from it:
@ -366,14 +372,16 @@ The syntax `export ... from ...` is just a shorter notation for such import-expo
```js ```js
// 📁 auth/index.js // 📁 auth/index.js
// import login/logout and immediately export them // re-export login/logout
export {login, logout} from './helpers.js'; export {login, logout} from './helpers.js';
// import default as User and export it // re-export the default export as User
export {default as User} from './user.js'; export {default as User} from './user.js';
... ...
``` ```
The notable difference of `export ... from` compared to `import/export` is that re-exported modules aren't available in the current file. So inside the above example of `auth/index.js` we can't use re-exported `login/logout` functions.
### Re-exporting the default export ### Re-exporting the default export
The default export needs separate handling when re-exporting. The default export needs separate handling when re-exporting.