fix(settings): centralize draft normalization and use 60s query timeout
This commit is contained in:
16 files changed
+239
-360
No files matched your search
@@ -0,0 +1,17 @@
|
||||
import { ref } from "vue";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { applyEditorSettingsDraftToRefs } from "../applyEditorSettingsDraft";
|
||||
import type { EditorSettingsDraft } from "../editorSettingsDraft";
|
||||
|
||||
describe("applyEditorSettingsDraftToRefs", () => {
|
||||
it("applies only the requested keys and preserves custom transforms", () => {
|
||||
const fontSize = ref(12);
|
||||
const theme = ref("light");
|
||||
const draft = { fontSize: 16, theme: "dark" } as EditorSettingsDraft;
|
||||
|
||||
applyEditorSettingsDraftToRefs(draft, ["fontSize"], { fontSize, theme }, { fontSize: (value) => Number(value) + 1 });
|
||||
|
||||
expect(fontSize.value).toBe(17);
|
||||
expect(theme.value).toBe("light");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
import type { Ref } from "vue";
|
||||
import type { EditorSettingsDraft, EditorSettingsDraftKey } from "./editorSettingsDraft";
|
||||
|
||||
export type EditorSettingsDraftRefMap = Record<EditorSettingsDraftKey, Ref>;
|
||||
|
||||
export function applyEditorSettingsDraftToRefs(draft: EditorSettingsDraft, keys: readonly EditorSettingsDraftKey[], refs: EditorSettingsDraftRefMap, transform: Partial<Record<EditorSettingsDraftKey, (value: unknown) => unknown>> = {}) {
|
||||
for (const key of keys) {
|
||||
const target = refs[key];
|
||||
const value = draft[key] as unknown;
|
||||
target.value = transform[key] ? transform[key]!(value) : value;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user