patterns can now be async

This commit is contained in:
Felix Roos
2022-02-27 20:08:56 +01:00
parent 634d4f1099
commit 4f2f00ee62
5 changed files with 45 additions and 11 deletions
+4 -4
View File
@@ -21,15 +21,15 @@ function useRepl({ tune, defaultSynth, autolink = true, onEvent, onDraw }: any)
const [pattern, setPattern] = useState<Pattern>();
const dirty = code !== activeCode || error;
const generateHash = () => encodeURIComponent(btoa(code));
const activateCode = (_code = code) => {
!cycle.started && cycle.start();
broadcast({ type: 'start', from: id });
const activateCode = async (_code = code) => {
if (activeCode && !dirty) {
setError(undefined);
return;
}
try {
const parsed = evaluate(_code);
const parsed = await evaluate(_code);
!cycle.started && cycle.start();
broadcast({ type: 'start', from: id });
setPattern(() => parsed.pattern);
if (autolink) {
window.location.hash = '#' + encodeURIComponent(btoa(code));