refactor: Optimize current character initialization in stores.ts
This commit is contained in:
@@ -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()
|
||||||
Reference in New Issue
Block a user