Playground: Simplify settings passed to worker (#18763)
This commit is contained in:
1 parent
864fc4db40
commit
28b9898816
3 files changed
+69
-43
No files matched your search
@@ -10,23 +10,11 @@ function setup(props, { slots }) {
|
||||
};
|
||||
|
||||
const format = async () => {
|
||||
const {
|
||||
showAst: ast,
|
||||
showPreprocessedAst: preprocessedAst,
|
||||
showDoc: doc,
|
||||
showComments: comments,
|
||||
showSecondFormat: reformat,
|
||||
rethrowEmbedErrors,
|
||||
} = settings;
|
||||
|
||||
const result = await worker.format(props.code, toRaw(props.options), {
|
||||
ast,
|
||||
preprocessedAst,
|
||||
doc,
|
||||
comments,
|
||||
reformat,
|
||||
rethrowEmbedErrors,
|
||||
});
|
||||
const result = await worker.format(
|
||||
props.code,
|
||||
toRaw(props.options),
|
||||
toRaw(settings),
|
||||
);
|
||||
|
||||
Object.assign(state, result);
|
||||
};
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
/**
|
||||
@import {PlaygroundSettings} from "./playground-settings.js"
|
||||
@import {FormatMessage, MetaMessage} from "../../static/worker.mjs"
|
||||
*/
|
||||
|
||||
class WorkerApi {
|
||||
#worker = new Worker("/worker.mjs", { type: "module" });
|
||||
#counter = 0;
|
||||
@@ -35,11 +40,20 @@ class WorkerApi {
|
||||
}
|
||||
|
||||
getMetadata() {
|
||||
return this.#postMessage({ type: "meta" });
|
||||
/** @type {MetaMessage} */
|
||||
const message = { type: "meta" };
|
||||
return this.#postMessage(message);
|
||||
}
|
||||
|
||||
format(code, options, debug = {}) {
|
||||
return this.#postMessage({ type: "format", code, options, debug });
|
||||
/**
|
||||
* @param {FormatMessage["code"]} code
|
||||
* @param {FormatMessage["options"]} options
|
||||
* @param {FormatMessage["settings"]} settings
|
||||
*/
|
||||
format(code, options, settings) {
|
||||
/** @type {FormatMessage} */
|
||||
const message = { type: "format", code, options, settings };
|
||||
return this.#postMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user