Created
August 5, 2023 13:00
-
-
Save pferreirafabricio/283b7a6ae4b96c7c72c9b259abb8a4b0 to your computer and use it in GitHub Desktop.
π Basic logic to reset all Pinia stores at same time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment