mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-11 13:48:40 +00:00
fix: drawer performance issue
This commit is contained in:
parent
624affe092
commit
a9dc0912d0
@ -126,6 +126,7 @@ export class StrudelMirror {
|
||||
this.miniLocations = [];
|
||||
this.widgets = [];
|
||||
this.painters = [];
|
||||
this.drawTime = drawTime;
|
||||
this.onDraw = onDraw;
|
||||
const self = this;
|
||||
this.id = id || s4();
|
||||
@ -151,6 +152,7 @@ export class StrudelMirror {
|
||||
onToggle: (started) => {
|
||||
replOptions?.onToggle?.(started);
|
||||
if (started) {
|
||||
this.adjustDrawTime();
|
||||
this.drawer.start(this.repl.scheduler);
|
||||
// stop other repls when this one is started
|
||||
document.dispatchEvent(
|
||||
@ -177,6 +179,7 @@ export class StrudelMirror {
|
||||
updateWidgets(this.editor, this.widgets);
|
||||
updateMiniLocations(this.editor, this.miniLocations);
|
||||
replOptions?.afterEval?.(options);
|
||||
this.adjustDrawTime();
|
||||
this.drawer.invalidate();
|
||||
},
|
||||
});
|
||||
@ -212,6 +215,11 @@ export class StrudelMirror {
|
||||
};
|
||||
document.addEventListener('start-repl', this.onStartRepl);
|
||||
}
|
||||
// adjusts draw time depending on if there are painters
|
||||
adjustDrawTime() {
|
||||
// when no painters are set, [0,0] is enough (just highlighting)
|
||||
this.drawer.setDrawTime(!!this.painters.length ? this.drawTime : [0, 0]);
|
||||
}
|
||||
async drawFirstFrame() {
|
||||
if (!this.onDraw) {
|
||||
return;
|
||||
|
||||
@ -145,6 +145,9 @@ export class Drawer {
|
||||
},
|
||||
);
|
||||
}
|
||||
setDrawTime(drawTime) {
|
||||
this.drawTime = drawTime;
|
||||
}
|
||||
invalidate(scheduler = this.scheduler, t) {
|
||||
if (!scheduler) {
|
||||
return;
|
||||
|
||||
@ -57,10 +57,7 @@ export function Repl2({ embedded = false }) {
|
||||
const shouldDraw = true;
|
||||
|
||||
const init = useCallback(({ shouldDraw }) => {
|
||||
// TODO: find way to make spiral & punchcard work (if there's any)
|
||||
// upping the 2nd value leads to slow eval times
|
||||
// because Drawer.invalidate might query alot at one time
|
||||
const drawTime = [0, 0];
|
||||
const drawTime = [-2, 2];
|
||||
const drawContext = shouldDraw ? getDrawContext() : null;
|
||||
let onDraw;
|
||||
if (shouldDraw) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user