Skip to content

Commit b3787ea

Browse files
committed
automatically infer component display name from __file injected by vue-loader
1 parent d83ac41 commit b3787ea

File tree

9 files changed

+20
-22
lines changed

9 files changed

+20
-22
lines changed

shells/dev/target/Counter.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import { mapState } from 'vuex'
1111
1212
export default {
13-
name: 'Counter',
1413
created () {
1514
// simulate firebase binding
1615
this.$firebaseRefs = {

shells/dev/target/EventChild.vue

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
<script>
1010
export default {
11-
name: 'EventChild',
1211
methods: {
1312
emitEvent () {
1413
let data = {
@@ -25,12 +24,12 @@ export default {
2524
emitEvent2 () {
2625
let complexData = {
2726
componentName: 'EventChild',
28-
string: 'Lorem ipsum',
29-
complex: {
30-
string: 'Lorem ipsum',
31-
object: {
32-
number: 23,
33-
boolean: true,
27+
string: 'Lorem ipsum',
28+
complex: {
29+
string: 'Lorem ipsum',
30+
object: {
31+
number: 23,
32+
boolean: true,
3433
array: [1,2,3,4,5]
3534
}
3635
}
@@ -39,4 +38,4 @@ export default {
3938
}
4039
}
4140
}
42-
</script>
41+
</script>

shells/dev/target/EventChild1.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
<script>
88
export default {
9-
name: 'EventChild1',
109
methods: {
1110
emitLogEvent () {
1211
this.$emit('log')

shells/dev/target/EventChildCond.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
<script>
88
export default {
9-
name: 'EventChildCond',
109
methods: {
1110
emitLogEvent () {
1211
let data = {

shells/dev/target/Event.vue renamed to shells/dev/target/Events.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import EventChild from './EventChild.vue'
1313
import EventChild1 from './EventChild1.vue'
1414
import EventChildCond from './EventChildCond.vue'
1515
export default {
16-
name: 'Event',
17-
components: {
16+
components: {
1817
EventChild,
1918
EventChild1,
2019
EventChildCond

shells/dev/target/Other.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
<script>
99
export default {
10-
name: 'Other',
1110
props: ['id'],
1211
data () {
1312
let a = { c: function () {} }

shells/dev/target/Target.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
<script>
1212
import Other from './Other.vue'
1313
export default {
14-
name: 'Target',
1514
components: { Other },
1615
props: {
1716
msg: String,

shells/dev/target/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import store from './store'
33
import Target from './Target.vue'
44
import Other from './Other.vue'
55
import Counter from './Counter.vue'
6-
import Event from './Event.vue'
6+
import Events from './Events.vue'
77

88
let items = []
99
for (var i = 0; i < 100; i++) {
@@ -20,7 +20,7 @@ new Vue({
2020
h(Counter),
2121
h(Target, {props:{msg:'hi'}}),
2222
h(Other),
23-
h(Event)
23+
h(Events)
2424
])
2525
},
2626
data: {

src/backend/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,16 @@ function getInstanceDetails (id) {
299299

300300
export function getInstanceName (instance) {
301301
const name = instance.$options.name || instance.$options._componentTag
302-
return name
303-
? classify(name)
304-
: instance.$root === instance
305-
? 'Root'
306-
: 'Anonymous Component'
302+
if (name) {
303+
return classify(name)
304+
}
305+
const file = instance.$options.__file // injected by vue-loader
306+
if (file) {
307+
return classify(require('path').basename(file).replace(/\.vue$/, ''))
308+
}
309+
return instance.$root === instance
310+
? 'Root'
311+
: 'Anonymous Component'
307312
}
308313

309314
/**

0 commit comments

Comments
 (0)