Skip to content

Instantly share code, notes, and snippets.

View arxpoetica's full-sized avatar
🌼
Hope for a better world

Robert Hall arxpoetica

🌼
Hope for a better world
View GitHub Profile
{
"errors": [
{
"message": "Assignment to constant variable.",
"locations": [
{
"line": 2,
"column": 3
}
],
/* global localStorage */
import { writable } from 'svelte/store'
const storage = typeof localStorage !== 'undefined' ? localStorage : {
removeItem: key => { if (storage[key]) { delete storage[key] } },
}
/**
* Tracks storage both in `localStorage` and in svelte's `writable` stores
* Usage: `const name = storable('name', 'arxpoetica')`
@arxpoetica
arxpoetica / example-usage.svelte.ts
Created October 19, 2024 15:43
Naive Storage Sync
import { getStorage, storageSync } from '$shared/state-utils.svelte';
const SYNC_KEY = 'some_synced_var';
class SomeSvelteClass {
some_synced_var = $state(getStorage(SYNC_KEY) || 'foo');
constructor() {
storageSync(SYNC_KEY, () => this.some_synced_var);
}
}