Skip to content

Instantly share code, notes, and snippets.

@pushkar100
Created October 6, 2020 06:30
Show Gist options
  • Save pushkar100/94edee9544f28d0c9d0cd6810fd05650 to your computer and use it in GitHub Desktop.
Save pushkar100/94edee9544f28d0c9d0cd6810fd05650 to your computer and use it in GitHub Desktop.
Side effects and Live bindings example
// 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