Skip to content

Commit

Permalink
feat: add warning message if store id already exists (vuejs#1394)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zakhar Ausiyevich committed Jul 13, 2022
1 parent b638245 commit 3973748
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/pinia/src/store.ts
Expand Up @@ -50,6 +50,7 @@ import { setActivePinia, piniaSymbol, Pinia, activePinia } from './rootStore'
import { IS_CLIENT } from './env'
import { patchObject } from './hmr'
import { addSubscription, triggerSubscriptions, noop } from './subscriptions'
import { toastMessage } from './devtools/utils'

type _ArrayType<AT> = AT extends Array<infer T> ? T : never

Expand Down Expand Up @@ -866,6 +867,7 @@ export function defineStore(
options = idOrOptions
id = idOrOptions.id
}
// push id into stores array

function useStore(pinia?: Pinia | null, hot?: StoreGeneric): StoreGeneric {
const currentInstance = getCurrentInstance()
Expand Down Expand Up @@ -900,6 +902,11 @@ export function defineStore(
// @ts-expect-error: not the right inferred type
useStore._pinia = pinia
}
} else {
toastMessage(
`Store with id: ${id} already exists. Stores shoud have unique id.`,
'warn'
)
}

const store: StoreGeneric = pinia._s.get(id)!
Expand Down

0 comments on commit 3973748

Please sign in to comment.