Skip to content

Commit c0cacd2

Browse files
timozanderposva
andauthored
fix: resilient _VUE_DEVTOOLS_TOAST_ (#334)
Co-authored-by: Eduardo San Martin Morote <[email protected]>
1 parent 8e0474f commit c0cacd2

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/devtools.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ function formatDisplay(display: string) {
1515
}
1616
}
1717

18+
function toastMessage(
19+
message: string,
20+
type?: 'normal' | 'error' | 'warning' | undefined
21+
) {
22+
const piniaMessage = '🍍 ' + message
23+
24+
if (typeof __VUE_DEVTOOLS_TOAST__ === 'function') {
25+
__VUE_DEVTOOLS_TOAST__(piniaMessage, type)
26+
} else if (type === 'error') {
27+
console.error(piniaMessage)
28+
} else if (type === 'warning') {
29+
console.warn(piniaMessage)
30+
} else {
31+
console.log(piniaMessage)
32+
}
33+
}
34+
1835
let isAlreadyInstalled: boolean | undefined
1936

2037
export function addDevtools(app: App, store: GenericStore) {
@@ -116,18 +133,15 @@ export function addDevtools(app: App, store: GenericStore) {
116133
options: formatStoreForInspectorState(store),
117134
}
118135
} else {
119-
__VUE_DEVTOOLS_TOAST__(
120-
`🍍 store "${payload.nodeId}" not found`,
121-
'error'
122-
)
136+
toastMessage(`store "${payload.nodeId}" not found`, 'error')
123137
}
124138
}
125139
})
126140

127141
// trigger an update so it can display new registered stores
128142
// @ts-ignore
129143
api.notifyComponentUpdate()
130-
__VUE_DEVTOOLS_TOAST__(`🍍 "${store.$id}" store installed`)
144+
toastMessage(`"${store.$id}" store installed`)
131145
}
132146
)
133147
}

0 commit comments

Comments
 (0)