svelte-persistent-store
svelte-persistent-store copied to clipboard
SetItem does not respect null
It seems that null does not survive a roundtrip, probably due to not using x: string | null
.
this should have been fixed by #5. I tested like this (a little SSR setup because it was in a Sapper project):
<script>
import { writable } from 'svelte/store';
import * as local from 'svelte-persistent-store/dist/local';
const test =
process.browser
? local.writable('test', null)
: writable(null);
</script>
<style>
</style>
<p>
{JSON.stringify($test)}
{$test === null}
<!-- {$test === undefined} -->
<button on:click={() => test.set("foo")}>foo</button>
<button on:click={() => test.set(null)}>null</button>
<!-- <button on:click={() => test.set(undefined)}>undefined</button> -->
</p>
Note that "undefined"
is not valid JSON, so that does not work...