tidy normalized store hydration
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { batch } from "solid-js"
|
||||||
import { createStore, produce, reconcile } from "solid-js/store"
|
import { createStore, produce, reconcile } from "solid-js/store"
|
||||||
import type { SetStoreFunction } from "solid-js/store"
|
import type { SetStoreFunction } from "solid-js/store"
|
||||||
import type { ClientPart, MessageInfo } from "../../types/message"
|
import type { ClientPart, MessageInfo } from "../../types/message"
|
||||||
@@ -361,22 +362,24 @@ export function createInstanceMessageStore(instanceId: string): InstanceMessageS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setState("messages", (prev) => ({ ...prev, ...nextMessages }))
|
batch(() => {
|
||||||
setState("messageInfoVersion", (prev) => ({ ...prev, ...nextMessageInfoVersion }))
|
setState("messages", () => nextMessages)
|
||||||
setState("pendingParts", () => nextPendingParts)
|
setState("messageInfoVersion", () => nextMessageInfoVersion)
|
||||||
setState("permissions", "byMessage", (prev) => ({ ...prev, ...nextPermissionsByMessage }))
|
setState("pendingParts", () => nextPendingParts)
|
||||||
|
setState("permissions", "byMessage", () => nextPermissionsByMessage)
|
||||||
|
|
||||||
if (usageState) {
|
if (usageState) {
|
||||||
setState("usage", sessionId, usageState)
|
setState("usage", sessionId, usageState)
|
||||||
}
|
}
|
||||||
|
|
||||||
setState("sessions", sessionId, (session) => ({
|
setState("sessions", sessionId, (session) => ({
|
||||||
...session,
|
...session,
|
||||||
messageIds: incomingIds,
|
messageIds: incomingIds,
|
||||||
updatedAt: Date.now(),
|
updatedAt: Date.now(),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
bumpSessionRevision(sessionId)
|
bumpSessionRevision(sessionId)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function insertMessageIntoSession(sessionId: string, messageId: string) {
|
function insertMessageIntoSession(sessionId: string, messageId: string) {
|
||||||
|
|||||||
@@ -121,10 +121,6 @@ function handleMessageUpdate(instanceId: string, event: MessageUpdateEvent | Mes
|
|||||||
|
|
||||||
applyPartUpdateV2(instanceId, part)
|
applyPartUpdateV2(instanceId, part)
|
||||||
|
|
||||||
withSession(instanceId, sessionId, () => {
|
|
||||||
/* trigger reactivity for legacy consumers */
|
|
||||||
})
|
|
||||||
|
|
||||||
updateSessionInfo(instanceId, sessionId)
|
updateSessionInfo(instanceId, sessionId)
|
||||||
refreshPermissionsForSession(instanceId, sessionId)
|
refreshPermissionsForSession(instanceId, sessionId)
|
||||||
} else if (event.type === "message.updated") {
|
} else if (event.type === "message.updated") {
|
||||||
@@ -165,10 +161,6 @@ function handleMessageUpdate(instanceId: string, event: MessageUpdateEvent | Mes
|
|||||||
|
|
||||||
upsertMessageInfoV2(instanceId, info, { status: "complete", bumpRevision: true })
|
upsertMessageInfoV2(instanceId, info, { status: "complete", bumpRevision: true })
|
||||||
|
|
||||||
withSession(instanceId, sessionId, () => {
|
|
||||||
/* ensure reactivity for legacy session observers */
|
|
||||||
})
|
|
||||||
|
|
||||||
updateSessionInfo(instanceId, sessionId)
|
updateSessionInfo(instanceId, sessionId)
|
||||||
refreshPermissionsForSession(instanceId, sessionId)
|
refreshPermissionsForSession(instanceId, sessionId)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user