Skip to content

Commit

Permalink
bind instance to console on select
Browse files Browse the repository at this point in the history
change console label color
  • Loading branch information
bartlomieju authored and yyx990803 committed Nov 8, 2016
1 parent 7566420 commit a09035e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
34 changes: 29 additions & 5 deletions src/backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const rootInstances = []
const propModes = ['default', 'sync', 'once']

const instanceMap = window.__VUE_DEVTOOLS_INSTANCE_MAP__ = new Map()
const instanceMap = window.__VUE_DEVTOOLS_INSTANCE_MAP__ = new Map()
let consoleBoundInstances = Array(5)
let currentInspectedId
let bridge
let filter = ''
Expand Down Expand Up @@ -58,14 +60,11 @@ function connect () {
scrollIntoView(instance)
highlight(instance)
}
bindToConsole(instance)
flush()
bridge.send('instance-details', stringify(getInstanceDetails(id)))
})

bridge.on('send-to-console', id => {
window.$vm = instanceMap.get(id)
console.log('[vue-devtools] <' + getInstanceName(window.$vm) + '> is now available as $vm.')
})

bridge.on('filter-instances', _filter => {
filter = _filter.toLowerCase()
flush()
Expand Down Expand Up @@ -224,6 +223,9 @@ function capture (instance, _, list) {
} else {
ret.top = Infinity
}
// check if instance is available in console
const consoleId = consoleBoundInstances.indexOf(instance._uid)
ret.consoleId = consoleId > -1 ? '$vm' + consoleId : null
// check router view
const isRouterView2 = instance.$vnode && instance.$vnode.data.routerView
if (instance._routerView || isRouterView2) {
Expand Down Expand Up @@ -506,3 +508,25 @@ function scrollIntoView (instance) {
window.scrollBy(0, rect.top)
}
}

/**
* Binds given instance in console as $vm0.
* For compatibility reasons it also binds it as $vm.
*
* @param {Vue} instance
*/

function bindToConsole (instance) {
const id = instance._uid
const index = consoleBoundInstances.indexOf(id)
if (index > -1) {
consoleBoundInstances.splice(index, 1)
} else {
consoleBoundInstances.pop()
}
consoleBoundInstances.unshift(id)
for (var i = 0; i < 5; i++) {
window['$vm' + i] = instanceMap.get(consoleBoundInstances[i])
}
window.$vm = instance
}
7 changes: 0 additions & 7 deletions src/devtools/components/ComponentInspector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
<i class="material-icons">visibility</i>
<span>Inspect DOM</span>
</a>
<a class="button" @click="sendToConsole">
<i class="material-icons">dvr</i>
<span>Send to console</span>
</a>
</span>
</section>
<section class="data">
Expand Down Expand Up @@ -63,9 +59,6 @@ export default {
} else {
window.alert('DOM inspection is not supported in this shell.')
}
},
sendToConsole () {
bridge.send('send-to-console', this.target.id)
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/devtools/components/ComponentInstance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
</span>
<span class="angle-bracket">&lt;</span><span class="instance-name">{{ instance.name }}</span><span class="angle-bracket">&gt;</span>
</span>
<span class="info console" v-if="instance.consoleId">
{{ instance.consoleId }}
</span>
<span class="info router-view" v-if="instance.isRouterView">
router-view{{ instance.matchedRouteSegment ? ': ' + instance.matchedRouteSegment : null }}
</span>
Expand Down Expand Up @@ -142,6 +145,8 @@ export default {
border-radius 3px
position relative
top -1px
&.console
background-color #f19d9b
&.router-view
background-color #ff8344
&.fragment
Expand Down

0 comments on commit a09035e

Please sign in to comment.