Skip to content

Commit

Permalink
Merge pull request #7 from felixroos/main
Browse files Browse the repository at this point in the history
fixed editor crash
  • Loading branch information
yaxu committed Feb 7, 2022
2 parents 6f9c51d + 4dadcbc commit 5ecbcff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
10 changes: 6 additions & 4 deletions docs/dist/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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);
Expand Down
19 changes: 7 additions & 12 deletions repl/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 forget 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);
Expand Down

0 comments on commit 5ecbcff

Please sign in to comment.