Clear all stores #693
Answered
by
posva
Lord-Y
asked this question in
Help and Questions
Clear all stores
#693
-
Hi there, I'd like to know it there is a global way to clear all stores when a user is disconnecting?
|
Beta Was this translation helpful? Give feedback.
Answered by
posva
Sep 29, 2021
Replies: 1 comment 1 reply
-
There is no way to do it directly as most of the time a user disconnecting doesn't mean all stores to get You can however create a plugin that holds a reference to every store created within a map or array and expose a function that removes them: let stores = []
pinia.use(({ store }) => {
stores.push(store)
})
function resetAllStores() {
stores.forEach(store => {
store.$reset()
})
stores = []
}) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Lord-Y
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is no way to do it directly as most of the time a user disconnecting doesn't mean all stores to get
$reset()
and some setup based stores cannot be$reset()
.You can however create a plugin that holds a reference to every store created within a map or array and expose a function that removes them: