This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ./simple-arithmetic.js */ | |
export const add = (a, b) => a + b | |
export const subtract = (a, b) => a - b | |
/* ./complex-arithmetic.js */ | |
export const multiply = (a, b) => a * b | |
export const divide = (a, b) => a / b | |
const power = (a, b) => Math.pow(a, b) | |
export default power |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import( | |
/* webpackChunkName: "my-chunk-name" */ | |
/* webpackMode: "lazy" */ | |
'module' | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// (A) What happens when you try to load dynamic chunks: | |
/* ./utilities.js */ | |
export const add = (a, b) => a + b | |
export const subtract = (a, b) => a - b | |
export const multiply = (a, b) => a * b | |
export const divide = (a, b) => a / b | |
const power = (a, b) => Math.pow(a, b) | |
export default power |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// (B) What you need to manually do to import only A from the dynamic chunk: | |
/* ./utilities.js */ | |
export const add = (a, b) => a + b | |
export const subtract = (a, b) => a - b | |
export const multiply = (a, b) => a * b | |
export const divide = (a, b) => a / b | |
const power = (a, b) => Math.pow(a, b) | |
export default power |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use an array to fetch multiple names exports: | |
import(/* webpackExports: ["named1", "named2"] */ "module") | |
// Use the "default" keyword to fetch the default export as well: | |
import(/* webpackExports: ["named1", "named2", "default"] */ "module") | |
// Array is not necessary to fetch a single export: | |
import(/* webpackExports: "named1" */ "module") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ./utilities.js */ | |
export const add = (a, b) => a + b | |
export const subtract = (a, b) => a - b | |
export const multiply = (a, b) => a * b | |
export const divide = (a, b) => a / b | |
const power = (a, b) => Math.pow(a, b) | |
export default power | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Side effect & live binding example: | |
/* ./file1.js */ | |
console.log('Loaded module') // Illustates side effect | |
let i = 0 // Illustrates live binding | |
export const A = () => { | |
console.log('A', i) | |
i += 5 | |
} | |
export const B = () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* What will happen if state is duplicated (i.e maintains two states which is wrong!) */ | |
// Console output: | |
Loaded module | |
A 0 | |
Loaded module | |
B 0 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getLogMetaData = () => ({ | |
source: 'www' | |
}) | |
class Greetings extends React.Component { | |
state = {}; | |
componentDidMount() { | |
this.setState({ | |
meta: getLogMetaData() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getLogMetaData = () => ({ | |
source: 'www' | |
}) | |
const useLogger = () => { | |
const [meta, setMeta] = useState({}); | |
const logger = (id, event) => { | |
console.log(`id: ${id} | event: ${event}`); | |
console.log(`source: ${meta.source}`); | |
}; |
OlderNewer