add pending flag

This commit is contained in:
Felix Roos 2022-02-27 20:24:03 +01:00
parent f361b50f7f
commit 5f424e7113
2 changed files with 12 additions and 7 deletions

View file

@ -17,6 +17,7 @@ function useRepl({ tune, defaultSynth, autolink = true, onEvent, onDraw }: any)
const [activeCode, setActiveCode] = useState<string>();
const [log, setLog] = useState('');
const [error, setError] = useState<Error>();
const [pending, setPending] = useState(false);
const [hash, setHash] = useState('');
const [pattern, setPattern] = useState<Pattern>();
const dirty = code !== activeCode || error;
@ -24,9 +25,11 @@ function useRepl({ tune, defaultSynth, autolink = true, onEvent, onDraw }: any)
const activateCode = async (_code = code) => {
if (activeCode && !dirty) {
setError(undefined);
!cycle.started && cycle.start();
return;
}
try {
setPending(true);
const parsed = await evaluate(_code);
!cycle.started && cycle.start();
broadcast({ type: 'start', from: id });
@ -37,6 +40,7 @@ function useRepl({ tune, defaultSynth, autolink = true, onEvent, onDraw }: any)
setHash(generateHash());
setError(undefined);
setActiveCode(_code);
setPending(false);
} catch (err: any) {
err.message = 'evaluation error: ' + err.message;
console.warn(err);
@ -145,6 +149,7 @@ function useRepl({ tune, defaultSynth, autolink = true, onEvent, onDraw }: any)
};
return {
pending,
code,
setCode,
pattern,