Skip to content

Commit 27601ac

Browse files
author
Guillaume Chau
committed
this.$inspect + some code improvement
1 parent 2377cab commit 27601ac

File tree

6 files changed

+34
-16
lines changed

6 files changed

+34
-16
lines changed

shells/chrome/src/devtools-background.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ chrome.contextMenus.onClicked.addListener(onContextMenu)
5555

5656
function onContextMenu (info, tab) {
5757
if (info.menuItemId === 'vue-inspect-instance') {
58-
const src = `window.__VUE_DEVTOOLS_CONTEXT_MENU_HAS_TARGET`
58+
const src = `window.__VUE_DEVTOOLS_CONTEXT_MENU_HAS_TARGET__`
5959

6060
chrome.devtools.inspectedWindow.eval(src, function (res, err) {
6161
if (err) {
@@ -104,7 +104,7 @@ function onPanelLoad () {
104104

105105
function toast (message, type = 'normal') {
106106
const src = `(function() {
107-
__VUE_DEVTOOLS_TOAST(\`${message}\`, '${type}');
107+
__VUE_DEVTOOLS_TOAST__(\`${message}\`, '${type}');
108108
})()`
109109

110110
chrome.devtools.inspectedWindow.eval(src, function (res, err) {

shells/dev/target/Target.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<button class="remove" @click="rm">Remove</button>
1010
<input v-model="localMsg">
1111
<other v-for="item in items" :key="item"></other>
12+
<button @click="inspect">Inspect component</button>
1213
</div>
1314
</template>
1415

@@ -48,6 +49,9 @@ export default {
4849
},
4950
rm () {
5051
this.items.pop()
52+
},
53+
inspect () {
54+
this.$inspect()
5155
}
5256
}
5357
}

src/backend/hook.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ export function installHook (window) {
6666

6767
hook.once('init', Vue => {
6868
hook.Vue = Vue
69+
70+
Vue.prototype.$inspect = function () {
71+
const fn = window.__VUE_DEVTOOLS_INSPECT__
72+
fn && fn(this)
73+
}
6974
})
7075

7176
hook.once('vuex:init', store => {
@@ -89,12 +94,12 @@ export function installHook (window) {
8994
}
9095
const instance = el.__vue__
9196
if (instance) {
92-
window.__VUE_DEVTOOLS_CONTEXT_MENU_HAS_TARGET = true
93-
window.__VUE_DEVTOOLS_CONTEXT_MENU_TARGET = instance
97+
window.__VUE_DEVTOOLS_CONTEXT_MENU_HAS_TARGET__ = true
98+
window.__VUE_DEVTOOLS_CONTEXT_MENU_TARGET__ = instance
9499
return
95100
}
96101
}
97-
window.__VUE_DEVTOOLS_CONTEXT_MENU_HAS_TARGET = null
98-
window.__VUE_DEVTOOLS_CONTEXT_MENU_TARGET = null
102+
window.__VUE_DEVTOOLS_CONTEXT_MENU_HAS_TARGET__ = null
103+
window.__VUE_DEVTOOLS_CONTEXT_MENU_TARGET__ = null
99104
})
100105
}

src/backend/index.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ function connect () {
8181

8282
// Get the instance id that is targeted by context menu
8383
bridge.on('get-context-menu-target', () => {
84-
const instance = window.__VUE_DEVTOOLS_CONTEXT_MENU_TARGET
84+
const instance = window.__VUE_DEVTOOLS_CONTEXT_MENU_TARGET__
8585

86-
window.__VUE_DEVTOOLS_CONTEXT_MENU_TARGET = null
87-
window.__VUE_DEVTOOLS_CONTEXT_MENU_HAS_TARGET = false
86+
window.__VUE_DEVTOOLS_CONTEXT_MENU_TARGET__ = null
87+
window.__VUE_DEVTOOLS_CONTEXT_MENU_HAS_TARGET__ = false
8888

8989
if (instance) {
9090
const id = instance.__VUE_DEVTOOLS_UID__
9191
if (id) {
92-
return bridge.send('context-menu-target', id)
92+
return bridge.send('inspect-instance', id)
9393
}
9494
}
9595

@@ -108,6 +108,8 @@ function connect () {
108108
// events
109109
initEventsBackend(hook.Vue, bridge)
110110

111+
window.__VUE_DEVTOOLS_INSPECT__ = inspectInstance
112+
111113
bridge.log('backend ready.')
112114
bridge.send('ready', hook.Vue.version)
113115
console.log(
@@ -643,6 +645,11 @@ function getUniqueId (instance) {
643645
* @param {any} message HTML content
644646
*/
645647
export function toast (message, type = 'normal') {
646-
const fn = window.__VUE_DEVTOOLS_TOAST
648+
const fn = window.__VUE_DEVTOOLS_TOAST__
647649
fn && fn(message, type)
648650
}
651+
652+
export function inspectInstance (instance) {
653+
const id = instance.__VUE_DEVTOOLS_UID__
654+
id && bridge.send('inspect-instance', id)
655+
}

src/backend/toast.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function installToast (window) {
88
error: '#DB2600'
99
}
1010

11-
window.__VUE_DEVTOOLS_TOAST = (message, type) => {
11+
window.__VUE_DEVTOOLS_TOAST__ = (message, type) => {
1212
const color = colors[type] || colors.normal
1313
console.log(`%c vue-devtools %c ${message} %c `,
1414
'background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff',

src/devtools/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import App from './App.vue'
33
import store from './store'
44
import { parse } from '../util'
55

6-
let panelShown = false
6+
const isChrome = typeof chrome !== 'undefined' && chrome.devtools
7+
8+
let panelShown = !isChrome
79
let pendingAction = null
810

911
// Capture and log devtool errors when running as actual extension
1012
// so that we can debug it by inspecting the background page.
1113
// We do want the errors to be thrown in the dev shell though.
12-
if (typeof chrome !== 'undefined' && chrome.devtools) {
14+
if (isChrome) {
1315
Vue.config.errorHandler = (e, vm) => {
1416
bridge.send('ERROR', {
1517
message: e.message,
@@ -81,7 +83,7 @@ function initApp (shell) {
8183
bridge.send('vuex:toggle-recording', store.state.vuex.enabled)
8284
bridge.send('events:toggle-recording', store.state.events.enabled)
8385

84-
if (typeof chrome !== 'undefined' && chrome.devtools) {
86+
if (isChrome) {
8587
chrome.runtime.sendMessage('vue-panel-load')
8688
}
8789
})
@@ -116,7 +118,7 @@ function initApp (shell) {
116118
}
117119
})
118120

119-
bridge.on('context-menu-target', id => {
121+
bridge.on('inspect-instance', id => {
120122
ensurePaneShown(() => {
121123
inspectInstance(id)
122124
})

0 commit comments

Comments
 (0)