Skip to content

Commit 97068c8

Browse files
1099511627776Akryum
authored andcommitted
feat: Show key values in vue developers console (#691)
* Show key values in vue developers console * Bugfixes found by eslint * fix: key format + misc
1 parent 73177b1 commit 97068c8

File tree

4 files changed

+74
-9
lines changed

4 files changed

+74
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ build
55
tests_output
66
selenium-debug.log
77
TODOs.md
8+
.idea

shells/dev/target/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ new Vue({
2525
h(Counter),
2626
h(Target, { props: { msg: 'hi', ins: new MyClass() }}),
2727
h(Other),
28-
h(Events),
29-
h(NativeTypes),
30-
h(Router)
28+
h(Events, { key: 'foo' }),
29+
h(NativeTypes, { key: new Date() }),
30+
h(Router, { key: [] })
3131
])
3232
},
3333
data: {

src/backend/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ function capture (instance, _, list) {
284284
const ret = {
285285
id: instance.__VUE_DEVTOOLS_UID__,
286286
name: getInstanceName(instance),
287+
renderKey: getRenderKey(instance.$vnode ? instance.$vnode['key'] : null),
287288
inactive: !!instance._inactive,
288289
isFragment: !!instance._isFragment,
289290
children: instance.$children
@@ -694,6 +695,20 @@ function getUniqueId (instance) {
694695
return `${rootVueId}:${instance._uid}`
695696
}
696697

698+
function getRenderKey (value) {
699+
if (value == null) return
700+
const type = typeof value
701+
if (type === 'number') {
702+
return value
703+
} else if (type === 'string') {
704+
return `'${value}'`
705+
} else if (Array.isArray(value)) {
706+
return 'Array'
707+
} else {
708+
return 'Object'
709+
}
710+
}
711+
697712
/**
698713
* Display a toast message.
699714
* @param {any} message HTML content

src/devtools/views/components/ComponentInstance.vue

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
@mouseenter="enter"
1313
@mouseleave="leave"
1414
:class="{ selected: selected }"
15-
:style="{ paddingLeft: depth * 15 + 'px' }">
15+
:style="{ paddingLeft: depth * 15 + 'px' }"
16+
>
17+
<!-- Component tag -->
1618
<span class="content">
1719
<!-- arrow wrapper for better hit box -->
1820
<span class="arrow-wrapper"
@@ -21,7 +23,16 @@
2123
<span class="arrow right" :class="{ rotated: expanded }">
2224
</span>
2325
</span>
24-
<span class="angle-bracket">&lt;</span><span class="item-name">{{ displayName }}</span><span class="angle-bracket">&gt;</span>
26+
27+
<span class="angle-bracket">&lt;</span>
28+
29+
<span class="item-name">{{ displayName }}</span>
30+
31+
<span v-if="componentHasKey" class="attr">
32+
<span class="attr-title"> key</span>=<span class="attr-value">{{instance.renderKey}}</span>
33+
</span>
34+
35+
<span class="angle-bracket">&gt;</span>
2536
</span>
2637
<span
2738
v-if="instance.consoleId"
@@ -48,14 +59,17 @@
4859
>
4960
inactive
5061
</span>
62+
5163
<span class="spacer"></span>
64+
5265
<VueIcon
5366
class="icon-button"
5467
icon="visibility"
5568
v-tooltip="'Scroll into view'"
5669
@click="scrollToInstance"
5770
/>
5871
</div>
72+
5973
<div v-if="expanded">
6074
<component-instance
6175
v-for="child in sortedChildren"
@@ -69,44 +83,57 @@
6983

7084
<script>
7185
import { mapState } from 'vuex'
72-
import { classify, scrollIntoView } from '../../../util'
86+
import { classify, scrollIntoView, UNDEFINED } from '../../../util'
7387
7488
export default {
7589
name: 'ComponentInstance',
90+
7691
props: {
7792
instance: Object,
7893
depth: Number
7994
},
95+
8096
created () {
8197
// expand root by default
8298
if (this.depth === 0) {
8399
this.expand()
84100
}
85101
},
102+
86103
computed: {
87104
...mapState('components', [
88105
'classifyComponents'
89106
]),
107+
90108
scrollToExpanded () {
91109
return this.$store.state.components.scrollToExpanded
92110
},
111+
93112
expanded () {
94113
return !!this.$store.state.components.expansionMap[this.instance.id]
95114
},
115+
96116
selected () {
97117
return this.instance.id === this.$store.state.components.inspectedInstance.id
98118
},
119+
99120
sortedChildren () {
100121
return this.instance.children.slice().sort((a, b) => {
101122
return a.top === b.top
102123
? a.id - b.id
103124
: a.top - b.top
104125
})
105126
},
127+
106128
displayName () {
107129
return this.classifyComponents ? classify(this.instance.name) : this.instance.name
130+
},
131+
132+
componentHasKey () {
133+
return !!this.instance.renderKey && this.instance.renderKey !== UNDEFINED
108134
}
109135
},
136+
110137
watch: {
111138
scrollToExpanded: {
112139
handler (value, oldValue) {
@@ -117,35 +144,44 @@ export default {
117144
immediate: true
118145
}
119146
},
147+
120148
methods: {
121149
toggle (event) {
122150
this.toggleWithValue(!this.expanded, event.altKey)
123151
},
152+
124153
expand () {
125154
this.toggleWithValue(true)
126155
},
156+
127157
collapse () {
128158
this.toggleWithValue(false)
129159
},
160+
130161
toggleWithValue (val, recursive = false) {
131162
this.$store.dispatch('components/toggleInstance', {
132163
instance: this.instance,
133164
expanded: val,
134165
recursive
135166
})
136167
},
168+
137169
select () {
138170
bridge.send('select-instance', this.instance.id)
139171
},
172+
140173
enter () {
141174
bridge.send('enter-instance', this.instance.id)
142175
},
176+
143177
leave () {
144178
bridge.send('leave-instance', this.instance.id)
145179
},
180+
146181
scrollToInstance () {
147182
bridge.send('scroll-to-instance', this.instance.id)
148183
},
184+
149185
scrollIntoView (center = true) {
150186
this.$nextTick(() => {
151187
scrollIntoView(this.$globalRefs.leftScroll, this.$refs.self, center)
@@ -233,16 +269,29 @@ export default {
233269
color $component-color
234270
margin 0 1px
235271
272+
.attr
273+
opacity .5
274+
font-size 12px
275+
276+
.attr-title
277+
color purple
278+
236279
.spacer
237-
flex 100% 1 1
238-
width 0
280+
flex auto 1 1
239281
240282
.icon-button
241-
font-size 16px
283+
width 16px
284+
height 16px
242285
243286
.self:not(:hover) &
244287
visibility hidden
245288
246289
.self.selected & >>> svg
247290
fill $white
291+
292+
.self.selected
293+
.attr
294+
opacity 1
295+
.attr-title
296+
color lighten($purple, 70%)
248297
</style>

0 commit comments

Comments
 (0)