runed PersistedState hydrates raw stored JSON without merging defaults, so any field added after a user's first session is undefined rather than its default value. Apply a shallow spread (defaults → stored) in the custom serializer for badges, leads, and pres_mgmt stores so new fields always fall back to defaults for existing sessions — without disrupting any previously saved preferences. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
26 lines
1021 B
TypeScript
26 lines
1021 B
TypeScript
/**
|
|
* ae_events_stores__badges.svelte.ts
|
|
*
|
|
* Svelte 5 PersistedState store for Badge module local config.
|
|
* Replaces the `events_loc.badges` sub-object from the Svelte 4 persisted store.
|
|
*
|
|
* localStorage key: 'ae_badges_loc'
|
|
* Version gate: AE_BADGES_LOC_VERSION in store_versions.ts
|
|
*
|
|
* Usage:
|
|
* import { badges_loc } from '$lib/stores/ae_events_stores__badges.svelte';
|
|
* badges_loc.current.fulltext_search_qry_str // read
|
|
* badges_loc.current.search_version++ // write
|
|
*/
|
|
import { PersistedState } from 'runed';
|
|
import { badges_loc_defaults } from './ae_events_stores__badges_defaults';
|
|
|
|
// Custom deserializer merges stored JSON with defaults so that new fields added
|
|
// after a user's first session get their default values rather than undefined.
|
|
export const badges_loc = new PersistedState('ae_badges_loc', badges_loc_defaults, {
|
|
serializer: {
|
|
serialize: JSON.stringify,
|
|
deserialize: (raw: string) => ({ ...badges_loc_defaults, ...JSON.parse(raw) })
|
|
}
|
|
});
|