fix: shove prebake eval out of react
This commit is contained in:
parent
29a3543918
commit
c16b300144
3 changed files with 11 additions and 19 deletions
|
|
@ -2,4 +2,4 @@ import { evaluate as _evaluate } from '@strudel/core';
|
||||||
import { transpiler } from './transpiler.mjs';
|
import { transpiler } from './transpiler.mjs';
|
||||||
export * from './transpiler.mjs';
|
export * from './transpiler.mjs';
|
||||||
|
|
||||||
export const evaluate = (code) => _evaluate(code, transpiler);
|
export const evaluate = (code, transpilerOptions) => _evaluate(code, transpiler, transpilerOptions);
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import { Compartment, EditorState, Prec } from '@codemirror/state';
|
||||||
import { drawSelection, EditorView, keymap } from '@codemirror/view';
|
import { drawSelection, EditorView, keymap } from '@codemirror/view';
|
||||||
import { logger } from '@strudel/core';
|
import { logger } from '@strudel/core';
|
||||||
import { basicSetup, flash, initTheme, extensions, parseBooleans, codemirrorSettings } from '@strudel/codemirror';
|
import { basicSetup, flash, initTheme, extensions, parseBooleans, codemirrorSettings } from '@strudel/codemirror';
|
||||||
|
import { evaluate } from '@strudel/transpiler';
|
||||||
|
|
||||||
export class PrebakeCodeMirror {
|
export class PrebakeCodeMirror {
|
||||||
constructor(initialCode, storePrebake, container) {
|
constructor(initialCode, storePrebake, container) {
|
||||||
|
|
@ -89,6 +90,7 @@ export class PrebakeCodeMirror {
|
||||||
async savePrebake() {
|
async savePrebake() {
|
||||||
flash(this.view);
|
flash(this.view);
|
||||||
this.storePrebake(this.code);
|
this.storePrebake(this.code);
|
||||||
|
evaluate(this.code, { addReturn: false }); // run prebake
|
||||||
logger('[prebake] prebake saved');
|
logger('[prebake] prebake saved');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,9 @@ Copyright (C) 2022 Strudel contributors - see <https://codeberg.org/uzu/strudel/
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { code2hash, getPerformanceTimeSeconds, logger, silence, evaluate } from '@strudel/core';
|
import { code2hash, getPerformanceTimeSeconds, logger, silence } from '@strudel/core';
|
||||||
import { getDrawContext } from '@strudel/draw';
|
import { getDrawContext } from '@strudel/draw';
|
||||||
import { transpiler } from '@strudel/transpiler';
|
import { transpiler, evaluate } from '@strudel/transpiler';
|
||||||
import {
|
import {
|
||||||
getAudioContextCurrentTime,
|
getAudioContextCurrentTime,
|
||||||
renderPatternAudio,
|
renderPatternAudio,
|
||||||
|
|
@ -43,8 +43,6 @@ import { debugAudiograph } from './audiograph';
|
||||||
const { latestCode, maxPolyphony, audioDeviceName, multiChannelOrbits } = settingsMap.get();
|
const { latestCode, maxPolyphony, audioDeviceName, multiChannelOrbits } = settingsMap.get();
|
||||||
let modulesLoading, presets, drawContext, clearCanvas, audioReady;
|
let modulesLoading, presets, drawContext, clearCanvas, audioReady;
|
||||||
|
|
||||||
const evaluateUserPrebake = (code) => evaluate(code, transpiler, { addReturn: false });
|
|
||||||
|
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
audioReady = initAudioOnFirstClick({
|
audioReady = initAudioOnFirstClick({
|
||||||
maxPolyphony,
|
maxPolyphony,
|
||||||
|
|
@ -88,12 +86,12 @@ export function useReplContext() {
|
||||||
pattern: silence,
|
pattern: silence,
|
||||||
drawTime,
|
drawTime,
|
||||||
drawContext,
|
drawContext,
|
||||||
prebake: async () =>
|
prebake: async () => {
|
||||||
Promise.all([modulesLoading, presets]).then(() => {
|
await Promise.all([modulesLoading, presets]);
|
||||||
if (prebakeScript?.length) {
|
if (prebakeScript) {
|
||||||
return evaluateUserPrebake(prebakeScript ?? '');
|
return evaluate(prebakeScript, { addReturn: false });
|
||||||
}
|
}
|
||||||
}),
|
},
|
||||||
onUpdateState: (state) => {
|
onUpdateState: (state) => {
|
||||||
setReplState({ ...state });
|
setReplState({ ...state });
|
||||||
},
|
},
|
||||||
|
|
@ -183,14 +181,6 @@ export function useReplContext() {
|
||||||
editorRef.current?.updateSettings(editorSettings);
|
editorRef.current?.updateSettings(editorSettings);
|
||||||
}, [_settings]);
|
}, [_settings]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
Promise.all([modulesLoading, presets]).then(() => {
|
|
||||||
if (prebakeScript?.length) {
|
|
||||||
return evaluateUserPrebake(prebakeScript ?? '');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, [prebakeScript]);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// UI Actions
|
// UI Actions
|
||||||
//
|
//
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue