refactor: Optimize current character initialization in stores.ts

This commit is contained in:
kwaroran
2024-06-24 01:38:24 +09:00
parent 5f59349b84
commit 6e9940df2d

View File

@@ -2,6 +2,7 @@ import { get, writable, type Writable } from "svelte/store";
import { DataBase, type Chat, type character, type groupChat } from "./storage/database"; import { DataBase, type Chat, type character, type groupChat } from "./storage/database";
import { isEqual } from "lodash"; import { isEqual } from "lodash";
import type { simpleCharacterArgument } from "./parser"; import type { simpleCharacterArgument } from "./parser";
import { sleep } from "./util";
function updateSize(){ function updateSize(){
SizeStore.set({ SizeStore.set({
@@ -70,6 +71,8 @@ function createSimpleCharacter(char:character|groupChat){
} }
async function preInit(){
await sleep(1)
function updateCurrentCharacter(){ function updateCurrentCharacter(){
const db = get(DataBase) const db = get(DataBase)
@@ -163,7 +166,9 @@ CurrentChat.subscribe((chat) => {
CurrentVariablePointer.set(currentState) CurrentVariablePointer.set(currentState)
} }
}) })
}
updateSize() updateSize()
window.addEventListener("resize", updateSize); window.addEventListener("resize", updateSize);
preInit()