From e9b2bb616912176106025521ba7c0d00043bfae9 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Mon, 7 Feb 2022 22:24:16 +0100 Subject: [PATCH 1/3] fix input error handling --- repl/src/App.tsx | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/repl/src/App.tsx b/repl/src/App.tsx index 52d8bf82..5e1c216c 100644 --- a/repl/src/App.tsx +++ b/repl/src/App.tsx @@ -53,31 +53,26 @@ function App() { }, [pattern] ), - onSchedule: useCallback( - (_events, cycle) => { - // console.log('schedule', _events, cycle); - logCycle(_events, cycle); - }, - [pattern] - ), + onSchedule: useCallback((_events, cycle) => logCycle(_events, cycle), [pattern]), ready: !!pattern, }); // parse pattern when code changes useEffect(() => { try { - let _pattern; + let _pattern: Pattern; try { _pattern = h(code); setMode('pegjs'); // haskell mode does not recognize quotes, pegjs looks ok by accident.. - // console.log('h _pattern', _pattern); } catch (err) { setMode('javascript'); // code is not haskell like _pattern = parse(code); - // console.log('not haskell..', _pattern); + if (_pattern?.constructor?.name !== 'Pattern') { + const message = `got "${typeof _pattern}" instead of pattern`; + throw new Error(message + (typeof _pattern === 'function' ? 'did you foget to call a function?' : '')); + } } - setPattern(_pattern); - // cycle.query(cycle.activeCycle()); // reschedule active cycle + setPattern(() => _pattern); // need arrow function here! otherwise if user returns a function, react will think it's a state reducer setError(undefined); } catch (err: any) { console.warn(err); From 92103dbb066b9891ec9e2ed2f3facc3456a25249 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Mon, 7 Feb 2022 22:28:25 +0100 Subject: [PATCH 2/3] build for root dir --- docs/dist/App.js | 10 ++++++---- docs/dist/logo.svg.proxy.js | 2 +- docs/index.html | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/dist/App.js b/docs/dist/App.js index 86d580ab..98d2a884 100644 --- a/docs/dist/App.js +++ b/docs/dist/App.js @@ -43,9 +43,7 @@ function App() { return []; } }, [pattern]), - onSchedule: useCallback((_events, cycle2) => { - logCycle(_events, cycle2); - }, [pattern]), + onSchedule: useCallback((_events, cycle2) => logCycle(_events, cycle2), [pattern]), ready: !!pattern }); useEffect(() => { @@ -57,8 +55,12 @@ function App() { } catch (err) { setMode("javascript"); _pattern = parse(code); + if (_pattern?.constructor?.name !== "Pattern") { + const message = `got "${typeof _pattern}" instead of pattern`; + throw new Error(message + (typeof _pattern === "function" ? "did you foget to call a function?" : "")); + } } - setPattern(_pattern); + setPattern(() => _pattern); setError(void 0); } catch (err) { console.warn(err); diff --git a/docs/dist/logo.svg.proxy.js b/docs/dist/logo.svg.proxy.js index 73f6fe7f..aed9da04 100644 --- a/docs/dist/logo.svg.proxy.js +++ b/docs/dist/logo.svg.proxy.js @@ -1 +1 @@ -export default "/strudel/dist/logo.svg"; \ No newline at end of file +export default "/dist/logo.svg"; \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 507724ce..0e7db17b 100644 --- a/docs/index.html +++ b/docs/index.html @@ -2,8 +2,8 @@ - - + + Strudel REPL @@ -11,6 +11,6 @@
- + From 4dadcbcb49cd12012b1a02d307975f604b4e43d4 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Mon, 7 Feb 2022 22:38:10 +0100 Subject: [PATCH 3/3] fix typo --- repl/src/App.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repl/src/App.tsx b/repl/src/App.tsx index 5e1c216c..faad502a 100644 --- a/repl/src/App.tsx +++ b/repl/src/App.tsx @@ -69,7 +69,7 @@ function App() { _pattern = parse(code); if (_pattern?.constructor?.name !== 'Pattern') { const message = `got "${typeof _pattern}" instead of pattern`; - throw new Error(message + (typeof _pattern === 'function' ? 'did you foget to call a function?' : '')); + throw new Error(message + (typeof _pattern === 'function' ? ', did you forget to call a function?' : '.')); } } setPattern(() => _pattern); // need arrow function here! otherwise if user returns a function, react will think it's a state reducer