Created
October 6, 2020 06:30
-
-
Save pushkar100/94edee9544f28d0c9d0cd6810fd05650 to your computer and use it in GitHub Desktop.
Side effects and Live bindings example
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 = () => { | |
console.log('B', i) | |
i += 10 | |
} | |
/* ./main.js */ | |
// ... | |
// Assume the following loads 1st: | |
import(/* webpackExports: "A" */ './file1.js') | |
.then(module => { | |
module.A() | |
}) | |
// ... | |
// Assume the following loads 2nd: | |
import(/* webpackExports: "B" */ './file1.js') | |
.then(module => { | |
module.B() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment