repl reset default dict

+ add mechanism to get a module by name from dynamic imports
This commit is contained in:
Felix Roos
2024-02-29 04:54:03 +01:00
parent d4eebf1a77
commit 305715277c
3 changed files with 13 additions and 4 deletions
+1
View File
@@ -22,6 +22,7 @@ export const evalScope = async (...args) => {
globalThis[name] = value;
});
});
return modules;
};
function safeEval(str, options = {}) {
+2
View File
@@ -5,3 +5,5 @@ export * from './tonal.mjs';
export * from './voicings.mjs';
import './ireal.mjs';
export const packageName = '@strudel/tonal';
+10 -4
View File
@@ -48,6 +48,14 @@ if (typeof window !== 'undefined') {
isIframe = window.location !== window.parent.location;
}
async function getModule(name) {
if (!modulesLoading) {
return;
}
const modules = await modulesLoading;
return modules.find((m) => m.packageName === name);
}
export function Repl({ embedded = false }) {
const isEmbedded = embedded || isIframe;
const { panelPosition, isZen } = useSettings();
@@ -163,6 +171,7 @@ export function Repl({ embedded = false }) {
};
const resetEditor = async () => {
(await getModule('@strudel/tonal'))?.resetVoicings();
resetGlobalEffects();
clearCanvas();
resetLoadedSounds();
@@ -188,10 +197,7 @@ export function Repl({ embedded = false }) {
logger(`[repl] ✨ loading random tune "${patternData.id}"`);
setActivePattern(patternData.id);
setViewingPatternData(patternData);
clearCanvas();
resetLoadedSounds();
resetGlobalEffects();
await prebake(); // declare default samples
await resetEditor();
editorRef.current.setCode(code);
editorRef.current.repl.evaluate(code);
};