Skip to content

Commit

Permalink
feat: disposePinia
Browse files Browse the repository at this point in the history
  • Loading branch information
EliteDev9472 committed Oct 17, 2023
1 parent ac8d144 commit a648caa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/pinia/src/createPinia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,18 @@ export function createPinia(): Pinia {

return pinia
}

/**
* Dispose a Pinia instance by stopping its effectScope and removing the state, plugins and stores. This is mostly
* useful in tests, with both a testing pinia or a regular pinia and in applications that use multiple pinia instances.
*
* @param pinia - pinia instance
*/
export function disposePinia(pinia: Pinia) {
pinia._e.stop()
pinia._s.clear()
pinia._p.splice(0)
pinia.state.value = {}
// @ts-expect-error: non valid
pinia._a = null
}
2 changes: 1 addition & 1 deletion packages/pinia/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @module pinia
*/
export { setActivePinia, getActivePinia } from './rootStore'
export { createPinia } from './createPinia'
export { createPinia, disposePinia } from './createPinia'
export type {
Pinia,
// TODO: remove in next release
Expand Down

0 comments on commit a648caa

Please sign in to comment.