vanilla-repl-cm6: add flash effect
This commit is contained in:
parent
f069f53fae
commit
4b921c47f5
2 changed files with 52 additions and 16 deletions
|
|
@ -1,14 +1,24 @@
|
|||
// moved from sandbox: https://codesandbox.io/s/vanilla-codemirror-strudel-2wb7yw?file=/index.html:114-186
|
||||
|
||||
import { initEditor, highlightHaps } from './codemirror';
|
||||
import { initEditor, highlightHaps, flash } from './codemirror';
|
||||
import { initStrudel } from './strudel';
|
||||
import { Highlighter } from './highlighter';
|
||||
import { bumpStreet } from './tunes';
|
||||
let code = bumpStreet;
|
||||
const repl = initStrudel();
|
||||
|
||||
const view = initEditor({
|
||||
initialCode: code,
|
||||
onChange: (v) => {
|
||||
code = v.state.doc.toString();
|
||||
},
|
||||
onEvaluate,
|
||||
onStop,
|
||||
});
|
||||
|
||||
async function onEvaluate() {
|
||||
const { evaluate, scheduler } = await repl;
|
||||
flash(view);
|
||||
if (!scheduler.started) {
|
||||
scheduler.stop();
|
||||
await evaluate(code);
|
||||
|
|
@ -24,15 +34,6 @@ async function onStop() {
|
|||
highlighter.stop();
|
||||
}
|
||||
|
||||
const view = initEditor({
|
||||
initialCode: code,
|
||||
onChange: (v) => {
|
||||
code = v.state.doc.toString();
|
||||
},
|
||||
onEvaluate,
|
||||
onStop,
|
||||
});
|
||||
|
||||
let highlighter = new Highlighter((haps) => highlightHaps(view, haps));
|
||||
|
||||
document.getElementById('play').addEventListener('click', () => onEvaluate());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue