Skip to content

Instantly share code, notes, and snippets.

@pferreirafabricio
Created August 5, 2023 13:00
Show Gist options
  • Select an option

  • Save pferreirafabricio/283b7a6ae4b96c7c72c9b259abb8a4b0 to your computer and use it in GitHub Desktop.

Select an option

Save pferreirafabricio/283b7a6ae4b96c7c72c9b259abb8a4b0 to your computer and use it in GitHub Desktop.

Revisions

  1. pferreirafabricio created this gist Aug 5, 2023.
    12 changes: 12 additions & 0 deletions reset-pinia.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    import { defineStore, getActivePinia } from "pinia";

    const activePinia = getActivePinia();
    if (!activePinia) return;

    Object.entries(activePinia.state.value).forEach(([storeName, state]) => {
    console.debug("Resetting store", storeName);

    const storeDefinition = defineStore(storeName, state);
    const store = storeDefinition(activePinia);
    store.$reset();
    });