Skip to content

Commit 40ef206

Browse files
committed
Inject users key of choice and then use a function to inject, might fix
several other issues related to getorCreateVM()
1 parent 5760c04 commit 40ef206

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/components/BToast/plugin.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,20 @@ export class ToastController {
179179

180180
// default global inject key to fetch the controller
181181
const injectkey = Symbol()
182+
const fetchKey = Symbol()
183+
182184
const rootkey = 'root' // TODO: I guess this variable is not used in any place...
183185

184186
const defaults = {
185187
container: undefined,
186188
toasts: [],
187189
root: false,
188190
}
191+
192+
export function getKey(): any {
193+
return inject(fetchKey)
194+
}
195+
189196
export function useToast(): ToastInstance | undefined
190197
export function useToast(vm: {id: symbol}, key?: symbol): ToastInstance | undefined
191198
export function useToast(
@@ -195,7 +202,7 @@ export function useToast(
195202

196203
export function useToast(vm?: any, key: symbol = injectkey): ToastInstance | undefined {
197204
//let's get our controller to fetch the toast instance
198-
const controller = inject(key !== null ? key : injectkey) as ToastController
205+
const controller = inject(getKey()) as ToastController
199206

200207
// not parameters passed, use root if defined
201208
if (!vm) {
@@ -211,6 +218,7 @@ export function useToast(vm?: any, key: symbol = injectkey): ToastInstance | und
211218

212219
export const BToastPlugin: Plugin = {
213220
install: (app: App, options: BootstrapVueOptions = {}) => {
221+
app.provide(fetchKey, options?.BToast?.injectkey ?? injectkey)
214222
app.provide(options?.BToast?.injectkey ?? injectkey, new ToastController())
215223
},
216224
}

0 commit comments

Comments
 (0)