(prefs: Preferences)
| 81 | * Hydrate all registered stores from backend preferences data. |
| 82 | */ |
| 83 | export 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 | |
| 101 | export const backendPersistPlugin: PiniaPlugin = ({ store, options }) => { |
| 102 | const config = options.backendPersist |
no outgoing calls
no test coverage detected