ITADN

Add persistentJSON

#61Opend8corp 创建于 2026-01-26
D
d8corpcommented
Add `persistentJSON` function. I'm sure 99% developers create the function for there projects, so it will be nice to have in the repo. ```ts export function persistentJSON<T> (name: string, initial: T, opts?: PersistentSimpleOptions) { return persistentAtom<T>(name, initial, { encode: JSON.stringify, decode: JSON.parse, ...opts, }) } ``` With optional initial value, but I'm not sure it's a good idea. ```ts export function persistentJSON<T> (name: string, initial: T, opts?: PersistentSimpleOptions): WritableAtom<T> export function persistentJSON<T> (name: string, initial?: undefined, opts?: PersistentSimpleOptions): WritableAtom<T | undefined> export function persistentJSON<T> (name: string, initial?: T, opts?: PersistentSimpleOptions) { return persistentAtom<T>(name, initial as T, { encode: JSON.stringify, decode: JSON.parse, ...opts, }) } ```
4 条评论