RunestoneInteractive / RunestoneComponents

Packaging of the Runestone tools for publishing educational materials using github pages
http://runestoneinteractive.org
Other
101 stars 225 forks source link

Scratch ActiveCode errors on any page without an activecode #1223

Closed bnmnetp closed 3 years ago

bnmnetp commented 3 years ago

@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...

bjones1 commented 3 years ago

I would think window.runestoneComponents.runestone_import("activecode").then(ACFactory.toggleScratchActiveCode);. The async resolves after the dynamic load finishes.

bjones1 commented 3 years ago

Or await window.runestoneComponents.runestone_import("activecode"); ACFactory.toggleScratchActiveCode().

bnmnetp commented 3 years ago

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.

bjones1 commented 3 years ago

I agree -- yes, let's mark runestone_import as async.

bnmnetp commented 3 years ago

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.

bjones1 commented 3 years ago

I agree -- that was definitely a mistake / oversight on my part.