svelte-persistent-store icon indicating copy to clipboard operation
svelte-persistent-store copied to clipboard

SetItem does not respect null

Open purzelrakete opened this issue 5 years ago • 1 comments

It seems that null does not survive a roundtrip, probably due to not using x: string | null.

purzelrakete avatar Nov 17 '19 16:11 purzelrakete

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...

SillyFreak avatar Jan 03 '21 09:01 SillyFreak