frohzinn/bcbsma-storage / llama.cpp /tools /ui /src /lib /stores /persisted.svelte.ts
frohzinn's picture
download
raw
877 Bytes
import { browser } from '$app/environment';
type PersistedValue<T> = {
get value(): T;
set value(newValue: T);
};
export function persisted<T>(key: string, initialValue: T): PersistedValue<T> {
let value = initialValue;
if (browser) {
try {
const stored = localStorage.getItem(key);
if (stored !== null) {
value = JSON.parse(stored) as T;
}
} catch (error) {
console.warn(`Failed to load ${key}:`, error);
}
}
const persist = (next: T) => {
if (!browser) {
return;
}
try {
if (next === null || next === undefined) {
localStorage.removeItem(key);
return;
}
localStorage.setItem(key, JSON.stringify(next));
} catch (error) {
console.warn(`Failed to persist ${key}:`, error);
}
};
return {
get value() {
return value;
},
set value(newValue: T) {
value = newValue;
persist(newValue);
}
};
}

Xet Storage Details

Size:
877 Bytes
·
Xet hash:
e90953cf5c5d36bbfe3ecda3adeb97c8d9b131a7a819df71cc79f6950623b833

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.