0

So I'm working with some export in js and do not understand the way they interact...

I have those two files :

imported file

export var a = 0;

// getter on a
export function A() {
    return a;
}

// a custom evetn from a library, works on a trigger like usual js buttons
// triggers on a command base
register("command", (event) => {
    a = 1;
}).SetCriteria("test");

index file

import { a, A } from "./importedFile.js";

// a custom event from a library, works on a trigger like usual js buttons
// triggers on a clock base
register("tick", (event) => {
    console.log(a);
    console.log(A());
})

However whatever I do on the command trigger (that does fire, I've tested it) I do not get any output on the index file... It stays at zero

Any idea why, something I've missed on the way exports works?

Thanks :)

4
  • 2
    "...I do not get any output on the index file... It stays at zero..." I'm confused. Do you not get any output, or do you get output saying the value is 0? Commented Apr 1, 2024 at 15:41
  • If you're really using JavaScript modules (as shown), or your bundler accurately mimics them, you will definitely get 1 both for a and A() if you do the two console.logs you've shown after a has been updated in the source module; proof: stackblitz.com/edit/stackblitz-starters-ay4ha6?file=main.js. In JavaScript standard modules, exports are read-only live bindings, so you do see changes to exported variables if you look at them after they've changed. I suggest further isolating the problem (factor out the library, for instance), so you know what to debug. Commented Apr 1, 2024 at 15:43
  • They both stay at 0, no crash or error. Commented Apr 1, 2024 at 15:45
  • " read-only live bindings" was what I read online, that's why I'm confused indeed... I'll try exploring more around the triggers and the value of it. Ty Commented Apr 1, 2024 at 15:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.