title: Why use a factory for a custom store vs. just exporting an object
body: <p>I'm going through the Svelte tutorial and I'm on the custom store page (<a href="https://svelte.dev/tutorial/custom-stores" rel="nofollow noreferrer">https://svelte.dev/tutorial/custom-stores</a>). The sample code is written using a factory function <code>createCount</code> which is immediately called to create the store object that gets exported:</p>
  <pre><code>import { writable } from 'svelte/store';
  
  function createCount() {
      const { subscribe, set, update } = writable(0);
  
      return {
          subscribe,
          increment: () =&gt; update(n =&gt; n + 1),
          decrement: () =&gt; update(n =&gt; n - 1),
          reset: () =&gt; set(0)
      };
  }
  
  export const count = createCount();
  </code></pre>
  <p>What is the reason for doing it that way vs. just exporting the store object directly like this:</p>
  <pre><code>import { writable } from 'svelte/store';
  
  const { subscribe, set, update } = writable(0);
  
  export const count = {
      subscribe,
      increment: () =&gt; update(n =&gt; n + 1),
      decrement: () =&gt; update(n =&gt; n - 1),
      reset: () =&gt; set(0)
  };
  </code></pre>