From 275b2c957f5674a15d94592e80c4ab61234ca1fe Mon Sep 17 00:00:00 2001 From: Timo Zander Date: Fri, 15 Jan 2021 16:50:47 +0100 Subject: [PATCH 1/3] fix: Error when _VUE_DEVTOOLS_TOAST_ is undefined --- src/devtools.ts | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/devtools.ts b/src/devtools.ts index 28d7f7a960..ac84bc5522 100644 --- a/src/devtools.ts +++ b/src/devtools.ts @@ -15,6 +15,24 @@ function formatDisplay(display: string) { } } +function outputMessage( + message: string, + type?: 'normal' | 'error' | 'warning' | undefined +) { + if (__VUE_DEVTOOLS_TOAST__) { + __VUE_DEVTOOLS_TOAST__(message, type) + return + } + + if (type === 'error') { + console.error(message) + } else if (type === 'warning') { + console.warn(message) + } else { + console.log(message) + } +} + let isAlreadyInstalled: boolean | undefined export function addDevtools(app: App, store: GenericStore) { @@ -116,10 +134,7 @@ export function addDevtools(app: App, store: GenericStore) { options: formatStoreForInspectorState(store), } } else { - __VUE_DEVTOOLS_TOAST__( - `🍍 store "${payload.nodeId}" not found`, - 'error' - ) + outputMessage(`🍍 store "${payload.nodeId}" not found`, 'error') } } }) @@ -127,7 +142,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`) + outputMessage(`🍍 "${store.$id}" store installed`) } ) } From f80668088eceea62063c87b634c270b798b945dc Mon Sep 17 00:00:00 2001 From: Timo Zander Date: Sun, 17 Jan 2021 11:14:31 +0100 Subject: [PATCH 2/3] style: implement review changes --- src/devtools.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/devtools.ts b/src/devtools.ts index ac84bc5522..6a649a7636 100644 --- a/src/devtools.ts +++ b/src/devtools.ts @@ -15,21 +15,20 @@ function formatDisplay(display: string) { } } -function outputMessage( +function toastMessage( message: string, type?: 'normal' | 'error' | 'warning' | undefined ) { - if (__VUE_DEVTOOLS_TOAST__) { - __VUE_DEVTOOLS_TOAST__(message, type) - return - } + const piniaMessage = '🍍' + message - if (type === 'error') { - console.error(message) + if (typeof __VUE_DEVTOOLS_TOAST__ !== 'undefined') { + __VUE_DEVTOOLS_TOAST__(piniaMessage, type) + } else if (type === 'error') { + console.error(piniaMessage) } else if (type === 'warning') { - console.warn(message) + console.warn(piniaMessage) } else { - console.log(message) + console.log(piniaMessage) } } @@ -134,7 +133,7 @@ export function addDevtools(app: App, store: GenericStore) { options: formatStoreForInspectorState(store), } } else { - outputMessage(`🍍 store "${payload.nodeId}" not found`, 'error') + toastMessage(`store "${payload.nodeId}" not found`, 'error') } } }) @@ -142,7 +141,7 @@ export function addDevtools(app: App, store: GenericStore) { // trigger an update so it can display new registered stores // @ts-ignore api.notifyComponentUpdate() - outputMessage(`🍍 "${store.$id}" store installed`) + toastMessage(`"${store.$id}" store installed`) } ) } From a3d5a8d06a1d76e4e87d76c0bbe4bd8ab0da1b52 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Mon, 18 Jan 2021 15:03:15 +0100 Subject: [PATCH 3/3] Apply suggestions from code review --- src/devtools.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/devtools.ts b/src/devtools.ts index 6a649a7636..aa7ae35245 100644 --- a/src/devtools.ts +++ b/src/devtools.ts @@ -19,9 +19,9 @@ function toastMessage( message: string, type?: 'normal' | 'error' | 'warning' | undefined ) { - const piniaMessage = '🍍' + message + const piniaMessage = '🍍 ' + message - if (typeof __VUE_DEVTOOLS_TOAST__ !== 'undefined') { + if (typeof __VUE_DEVTOOLS_TOAST__ === 'function') { __VUE_DEVTOOLS_TOAST__(piniaMessage, type) } else if (type === 'error') { console.error(piniaMessage)