]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
fix: resilient _VUE_DEVTOOLS_TOAST_ (#334)
authorTimo Zander <timo---zander@live.de>
Mon, 18 Jan 2021 14:05:17 +0000 (15:05 +0100)
committerGitHub <noreply@github.com>
Mon, 18 Jan 2021 14:05:17 +0000 (15:05 +0100)
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
src/devtools.ts

index 28d7f7a960f978bd44593c064d9cd81b7aa833e1..aa7ae35245d3f24b83f7db1a5010e72f7250e908 100644 (file)
@@ -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`)
     }
   )
 }