Playground: reduce format calls (#18764)
This commit is contained in:
1 parent
26c4d35d61
commit
add95ce916
2 files changed
+24
-17
No files matched your search
@@ -22,22 +22,29 @@ function setup(props, { slots }) {
|
||||
const render = () => slots.default(state);
|
||||
|
||||
onMounted(componentDidMount);
|
||||
watch(
|
||||
() => [
|
||||
props.code,
|
||||
props.options,
|
||||
settings.showAst,
|
||||
settings.showPreprocessedAst,
|
||||
settings.showDoc,
|
||||
settings.showComments,
|
||||
settings.showSecondFormat,
|
||||
settings.rethrowEmbedErrors,
|
||||
],
|
||||
() => {
|
||||
format();
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
watch(() => props.code, format);
|
||||
watch(() => props.options, format, { deep: true });
|
||||
|
||||
// Should not trigger format when these changes
|
||||
const ignoredKeys = new Set(["showSidebar", "showInput"]);
|
||||
for (const key of Object.keys(settings).filter(
|
||||
(key) => !ignoredKeys.has(key),
|
||||
)) {
|
||||
watch(
|
||||
() => settings[key],
|
||||
(newValue, oldValue) => {
|
||||
// Always triggers format
|
||||
if (key === "rethrowEmbedErrors" && newValue !== oldValue) {
|
||||
return format();
|
||||
}
|
||||
// Only if set to true
|
||||
if (newValue) {
|
||||
return format();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return render;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@ import * as storage from "../storage.js";
|
||||
|
||||
const defaultSettings = {
|
||||
showSidebar: window.innerWidth > window.innerHeight,
|
||||
showInput: true,
|
||||
showAst: false,
|
||||
showPreprocessedAst: false,
|
||||
showDoc: false,
|
||||
showComments: false,
|
||||
showSecondFormat: false,
|
||||
showInput: true,
|
||||
showOutput: true,
|
||||
rethrowEmbedErrors: false,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user