square / svelte-store

528 stars 35 forks source link

Documentation: asyncWritable initial value? #12

Closed sanderjson closed 2 years ago

sanderjson commented 2 years ago

How do I set an initial value in an asyncWritable?

I have read in the docs:

asyncWritable

Our first two arguments work just like an asyncDerived store--we can pass any number of stores and we can use their values to set the value of the store once the parents have loaded.

asyncDerived

However, while regular derived stores will invoke that function whenever any of the parent values changes (including initialization) an asyncDerived store will only do so after all of the parents have finished loading.

Intended use:

{#await my_store.load() then}
    <ul>
        {#each $my_store as val}
          <li>
            {...val}
          </li>
        {/each}
    </ul>
{/await}

And sometimes getting the error Uncaught (in promise) Error: {#each} only iterates over array-like objects.