From: Timo Zander Date: Mon, 18 Jan 2021 14:05:17 +0000 (+0100) Subject: fix: resilient _VUE_DEVTOOLS_TOAST_ (#334) X-Git-Tag: v2.0.0-alpha.7~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c0cacd2631d76d9d6de2b16d4106ad7decb51217;p=thirdparty%2Fvuejs%2Fpinia.git fix: resilient _VUE_DEVTOOLS_TOAST_ (#334) Co-authored-by: Eduardo San Martin Morote --- 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`) } ) }