MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / hydrateAllStores

Function hydrateAllStores

src/plugins/backendPersist.ts:83–99  ·  view source on GitHub ↗
(prefs: Preferences)

Source from the content-addressed store, hash-verified

81 * Hydrate all registered stores from backend preferences data.
82 */
83export function hydrateAllStores(prefs: Preferences): void {
84 for (const [, { store, config }] of stores) {
85 const source = config.key
86 ? (prefs as unknown as Record<string, unknown>)[config.key]
87 : (prefs as unknown as Record<string, unknown>)
88 if (!source || typeof source !== 'object') continue
89
90 const patch: Record<string, unknown> = {}
91 for (const field of config.pick) {
92 const val = (source as Record<string, unknown>)[field]
93 if (val !== undefined) patch[field] = val
94 }
95 if (Object.keys(patch).length > 0) {
96 store.$patch(patch)
97 }
98 }
99}
100
101export const backendPersistPlugin: PiniaPlugin = ({ store, options }) => {
102 const config = options.backendPersist

Callers 1

initPreferencesSyncFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected