I have a module "a" which exports a variable initiated as null. This variable is imported into module "b".
Following some changes to the initial variable, I try to access it again from module "b", only to find I get the original null value.
Aren't these variables being imported as reference? Meaning, they should reflect any changes made to them at a later point in runtime.
// main.js
import * as a from './a.js'
import * as b from './b.js'
// a.js
let test = null
export default test
export function change() {
test = 'test'
console.log(['in a.js change()', test])
}
console.log(['in a.js global', test])
// b.js
import test, { change } from './a.js'
console.log(['in b.js, pre a.change()', test])
change()
console.log(['in b.js, post a.change()', test])
/*
output:
Array [ "in a.js global", null ]
Array [ "in b.js, pre a.change()", null ]
Array [ "in a.js change()", "test" ]
Array [ "in b.js, post a.change()", null ] WHY ISN'T THIS = "test" ?
*/