From c0cacd2631d76d9d6de2b16d4106ad7decb51217 Mon Sep 17 00:00:00 2001 From: Timo Zander Date: Mon, 18 Jan 2021 15:05:17 +0100 Subject: [PATCH] fix: resilient _VUE_DEVTOOLS_TOAST_ (#334) Co-authored-by: Eduardo San Martin Morote --- src/devtools.ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/devtools.ts b/src/devtools.ts index 28d7f7a9..aa7ae352 100644 --- a/src/devtools.ts +++ b/src/devtools.ts @@ -15,6 +15,23 @@ function formatDisplay(display: string) { } } +function toastMessage( + message: string, + type?: 'normal' | 'error' | 'warning' | undefined +) { + const piniaMessage = '🍍 ' + message + + if (typeof __VUE_DEVTOOLS_TOAST__ === 'function') { + __VUE_DEVTOOLS_TOAST__(piniaMessage, type) + } else if (type === 'error') { + console.error(piniaMessage) + } else if (type === 'warning') { + console.warn(piniaMessage) + } else { + console.log(piniaMessage) + } +} + let isAlreadyInstalled: boolean | undefined export function addDevtools(app: App, store: GenericStore) { @@ -116,10 +133,7 @@ export function addDevtools(app: App, store: GenericStore) { options: formatStoreForInspectorState(store), } } else { - __VUE_DEVTOOLS_TOAST__( - `🍍 store "${payload.nodeId}" not found`, - 'error' - ) + toastMessage(`store "${payload.nodeId}" not found`, 'error') } } }) @@ -127,7 +141,7 @@ export function addDevtools(app: App, store: GenericStore) { // trigger an update so it can display new registered stores // @ts-ignore api.notifyComponentUpdate() - __VUE_DEVTOOLS_TOAST__(`🍍 "${store.$id}" store installed`) + toastMessage(`"${store.$id}" store installed`) } ) } -- 2.47.3