Skip to content

Commit

Permalink
fix: resilient _VUE_DEVTOOLS_TOAST_ (#334)
Browse files Browse the repository at this point in the history
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
  • Loading branch information
timozander and posva committed Jan 18, 2021
1 parent 8e0474f commit c0cacd2
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/devtools.ts
Expand Up @@ -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) {
Expand Down Expand Up @@ -116,18 +133,15 @@ 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')
}
}
})

// 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`)
}
)
}
Expand Down

0 comments on commit c0cacd2

Please sign in to comment.