mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Debounce mathjax rendering to avoid stalling (#3827)
* move change-timer to editable * debounce mathjax rendering
This commit is contained in:
parent
e373b0ed9b
commit
8ec139f62a
3 changed files with 10 additions and 4 deletions
|
@ -38,25 +38,31 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import { pageTheme } from "$lib/sveltelib/theme";
|
import { pageTheme } from "$lib/sveltelib/theme";
|
||||||
|
|
||||||
import { convertMathjax, unescapeSomeEntities } from "./mathjax";
|
import { convertMathjax, unescapeSomeEntities } from "./mathjax";
|
||||||
|
import { ChangeTimer } from "./change-timer";
|
||||||
|
|
||||||
export let mathjax: string;
|
export let mathjax: string;
|
||||||
export let block: boolean;
|
export let block: boolean;
|
||||||
export let fontSize: number;
|
export let fontSize: number;
|
||||||
|
|
||||||
let converted: string, title: string;
|
let converted: string, title: string;
|
||||||
|
|
||||||
|
const debouncedMathjax = writable(mathjax);
|
||||||
|
const debouncer = new ChangeTimer();
|
||||||
|
$: debouncer.schedule(() => debouncedMathjax.set(mathjax), 500);
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
const cache = getCache($pageTheme.isDark, fontSize);
|
const cache = getCache($pageTheme.isDark, fontSize);
|
||||||
const entry = cache.get(mathjax);
|
const entry = cache.get($debouncedMathjax);
|
||||||
if (entry) {
|
if (entry) {
|
||||||
[converted, title] = entry;
|
[converted, title] = entry;
|
||||||
} else {
|
} else {
|
||||||
const entry = convertMathjax(
|
const entry = convertMathjax(
|
||||||
unescapeSomeEntities(mathjax),
|
unescapeSomeEntities($debouncedMathjax),
|
||||||
$pageTheme.isDark,
|
$pageTheme.isDark,
|
||||||
fontSize,
|
fontSize,
|
||||||
);
|
);
|
||||||
[converted, title] = entry;
|
[converted, title] = entry;
|
||||||
cache.set(mathjax, entry);
|
cache.set($debouncedMathjax, entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$: empty = title === "MathJax";
|
$: empty = title === "MathJax";
|
||||||
|
|
|
@ -57,7 +57,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
type ImageLoadedEvent,
|
type ImageLoadedEvent,
|
||||||
resetIOImage,
|
resetIOImage,
|
||||||
} from "../routes/image-occlusion/mask-editor";
|
} from "../routes/image-occlusion/mask-editor";
|
||||||
import { ChangeTimer } from "./change-timer";
|
import { ChangeTimer } from "../editable/change-timer";
|
||||||
import { clearableArray } from "./destroyable";
|
import { clearableArray } from "./destroyable";
|
||||||
import DuplicateLink from "./DuplicateLink.svelte";
|
import DuplicateLink from "./DuplicateLink.svelte";
|
||||||
import EditorToolbar from "./editor-toolbar";
|
import EditorToolbar from "./editor-toolbar";
|
||||||
|
|
Loading…
Reference in a new issue