repl reset default dict
+ add mechanism to get a module by name from dynamic imports
This commit is contained in:
parent
d4eebf1a77
commit
305715277c
3 changed files with 13 additions and 4 deletions
|
|
@ -22,6 +22,7 @@ export const evalScope = async (...args) => {
|
||||||
globalThis[name] = value;
|
globalThis[name] = value;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
return modules;
|
||||||
};
|
};
|
||||||
|
|
||||||
function safeEval(str, options = {}) {
|
function safeEval(str, options = {}) {
|
||||||
|
|
|
||||||
|
|
@ -5,3 +5,5 @@ export * from './tonal.mjs';
|
||||||
export * from './voicings.mjs';
|
export * from './voicings.mjs';
|
||||||
|
|
||||||
import './ireal.mjs';
|
import './ireal.mjs';
|
||||||
|
|
||||||
|
export const packageName = '@strudel/tonal';
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,14 @@ if (typeof window !== 'undefined') {
|
||||||
isIframe = window.location !== window.parent.location;
|
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 }) {
|
export function Repl({ embedded = false }) {
|
||||||
const isEmbedded = embedded || isIframe;
|
const isEmbedded = embedded || isIframe;
|
||||||
const { panelPosition, isZen } = useSettings();
|
const { panelPosition, isZen } = useSettings();
|
||||||
|
|
@ -163,6 +171,7 @@ export function Repl({ embedded = false }) {
|
||||||
};
|
};
|
||||||
|
|
||||||
const resetEditor = async () => {
|
const resetEditor = async () => {
|
||||||
|
(await getModule('@strudel/tonal'))?.resetVoicings();
|
||||||
resetGlobalEffects();
|
resetGlobalEffects();
|
||||||
clearCanvas();
|
clearCanvas();
|
||||||
resetLoadedSounds();
|
resetLoadedSounds();
|
||||||
|
|
@ -188,10 +197,7 @@ export function Repl({ embedded = false }) {
|
||||||
logger(`[repl] ✨ loading random tune "${patternData.id}"`);
|
logger(`[repl] ✨ loading random tune "${patternData.id}"`);
|
||||||
setActivePattern(patternData.id);
|
setActivePattern(patternData.id);
|
||||||
setViewingPatternData(patternData);
|
setViewingPatternData(patternData);
|
||||||
clearCanvas();
|
await resetEditor();
|
||||||
resetLoadedSounds();
|
|
||||||
resetGlobalEffects();
|
|
||||||
await prebake(); // declare default samples
|
|
||||||
editorRef.current.setCode(code);
|
editorRef.current.setCode(code);
|
||||||
editorRef.current.repl.evaluate(code);
|
editorRef.current.repl.evaluate(code);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue