refactor: Make persisted() values raw state
The getter handed out a deep $state proxy, so in-place mutation of a persisted array/record would update the UI while silently never being written to localStorage. All consumers already replace .value wholesale; $state.raw makes that the only semantics and drops the per-read proxy overhead. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
d2f067a540
commit
c253054916
@@ -37,8 +37,10 @@ export interface Persisted<T> {
|
||||
}
|
||||
|
||||
// A localStorage-backed reactive value. Reads on init, writes on every set.
|
||||
// Raw state: replace `value` wholesale to change it. With a deep proxy,
|
||||
// in-place mutation would update the UI without ever being persisted.
|
||||
export const persisted = <T>(key: string, initial: T): Persisted<T> => {
|
||||
let value = $state<T>(readJSON(key, initial));
|
||||
let value = $state.raw<T>(readJSON(key, initial));
|
||||
return {
|
||||
get value() {
|
||||
return value;
|
||||
|
||||
Reference in New Issue
Block a user