Closed bnmnetp closed 3 years ago
I would think window.runestoneComponents.runestone_import("activecode").then(ACFactory.toggleScratchActiveCode);
. The async resolves after the dynamic load finishes.
Or await window.runestoneComponents.runestone_import("activecode"); ACFactory.toggleScratchActiveCode()
.
That is what I was working on trying, but it seems that the import function should be declared as async so that we know it has async behavior.
I agree -- yes, let's mark runestone_import
as async
.
OK, I pushed a fix so now scratch activecodes are working regardless of whether there is another activecode on the page.
But, I think we should make coding rule that any function that does something async (regardless of whether it calls await) should be declared as async so we don't have to experiment to figure it out.
I agree -- that was definitely a mistake / oversight on my part.
@bjones, without reverting to always loading activecode, what is the best way to ensure that the scratch activecode popup works?
It seems that the runestone_import is async (although not declared as such) so calling that from a function and then immediately calling
ACFactory.toggleScratchActiveCode()
fails with ACFactory undefined....after a short wait ACFactory is defined...