Skip to content

Commit 842aa35

Browse files
author
Guillaume Chau
authored
Serialization & Types improvements (#523)
* More fault tolerant * Display stores with CustomValue API * Dsiplay VueRouter instances with CustomValue API * CustomValue API: new 'tooltip' option, supports functions, component def * Test router & store * Open in editor Component defs * Fix #528 * Comments * Encode cache clear * Large array test * CustomValue API: respect fields order * Switch props and data sections to follow style guide * New 'grey' and 'red' classes DataField: allowing to reproduce current available styling using CustomValue API * Add support for Map and Set - Fix #349 Initial PR #490 by AdamNiederer * Set and Map test case * Fix Map key/value inverted * Optimizations * Fix tooltip * DataField style changes * Env: added isLinux & isWindows + function 'f' style fixes * gps-not-fixed icon is ugly on Windows * Style tweaks * Typo * Added more function test cases
1 parent 000a632 commit 842aa35

File tree

16 files changed

+532
-104
lines changed

16 files changed

+532
-104
lines changed

shells/dev/target/NativeTypes.vue

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,118 @@
1111
<TestComponent ref="component" />
1212

1313
<p>
14-
<button @click="sendComponent">Vuex mutation</button>
14+
<button @click="sendComponent()">Vuex mutation</button>
15+
<button @click="createLargeArray()">Create large array</button>
16+
</p>
17+
18+
<h3>Set</h3>
19+
<pre>{{ setDisplay() }}</pre>
20+
21+
<h3>Map</h3>
22+
<pre>{{ mapDisplay() }}</pre>
23+
24+
<p>
25+
<button @click="testVuexSet()">Vuex Set</button>
26+
<button @click="testVuexMap()">Vuex Map</button>
27+
<button @click="forceRefresh()">Refresh</button>
1528
</p>
1629
</div>
1730
</template>
1831

1932
<script>
2033
import { mapState, mapGetters, mapMutations } from 'vuex'
34+
import CompDef from './Other.vue'
2135
2236
export default {
2337
components: {
2438
TestComponent: {
25-
data: () => ({ foo: '42' }),
2639
props: { bar: { default: 'hey' }},
40+
data: () => ({ foo: '42' }),
41+
computed: {
42+
parentComp () { return this.$parent }
43+
},
2744
render: h => h('div', '<TestComponent />')
2845
}
2946
},
47+
3048
data () {
3149
return {
3250
localDate: new Date(),
33-
testComponent: null
51+
reg: /abc/gi,
52+
testComponent: null,
53+
hello: function foo (a, b, c) {},
54+
hey: function empty () {},
55+
anon: function (foo, bar) {},
56+
arrow: (a, b) => {},
57+
def: CompDef,
58+
def2: {
59+
name: 'MyComponent',
60+
render () {}
61+
},
62+
def3: {
63+
render () {}
64+
},
65+
largeArray: [],
66+
i: new Set([1, 2, 3, 4, new Set([5, 6, 7, 8]), new Map([[1, 2], [3, 4], [5, new Map([[6, 7]])]])]),
67+
j: new Map([[1, 2], [3, 4], [5, new Map([[6, 7]])], [8, new Set([1, 2, 3, 4, new Set([5, 6, 7, 8]), new Map([[1, 2], [3, 4], [5, new Map([[6, 7]])]])])]])
3468
}
3569
},
3670
computed: {
37-
...mapState(['date']),
38-
...mapGetters(['hours'])
71+
...mapState([
72+
'date',
73+
'set',
74+
'map'
75+
]),
76+
77+
...mapGetters([
78+
'hours'
79+
]),
80+
81+
theRouter () {
82+
return this.$router
83+
},
84+
85+
theStore () {
86+
return this.$store
87+
},
3988
},
89+
4090
mounted () {
4191
this.testComponent = this.$refs.component
4292
},
93+
4394
methods: {
4495
...mapMutations({
45-
updateDate: 'UPDATE_DATE'
96+
updateDate: 'UPDATE_DATE',
97+
testVuexSet: 'TEST_SET',
98+
testVuexMap: 'TEST_MAP'
4699
}),
100+
47101
sendComponent () {
48102
this.$store.commit('TEST_COMPONENT', this.testComponent)
103+
},
104+
105+
createLargeArray () {
106+
const list = []
107+
for (let i = 0; i < 10000000; i++) {
108+
list.push(i)
109+
}
110+
this.largeArray = list
111+
},
112+
113+
setDisplay () {
114+
return Array.from(this.set)
115+
},
116+
117+
mapDisplay () {
118+
return [...this.map]
119+
},
120+
121+
forceRefresh () {
122+
this.$forceUpdate()
49123
}
50124
},
125+
51126
filters: {
52127
prototypeString: val => Object.prototype.toString.call(val)
53128
}

shells/dev/target/store.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,23 @@ Vue.use(Vuex)
66
export default new Vuex.Store({
77
state: {
88
count: 0,
9-
date: new Date()
9+
date: new Date(),
10+
set: new Set(),
11+
map: new Map()
1012
},
1113
mutations: {
1214
INCREMENT: state => state.count++,
1315
DECREMENT: state => state.count--,
1416
UPDATE_DATE: state => {
1517
state.date = new Date()
1618
},
17-
TEST_COMPONENT: state => {}
19+
TEST_COMPONENT: state => {},
20+
TEST_SET: state => {
21+
state.set.add(Math.random())
22+
},
23+
TEST_MAP: state => {
24+
state.map.set(`mykey_${state.map.size}`, state.map.size)
25+
}
1826
},
1927
getters: {
2028
isPositive: state => state.count >= 0,

src/backend/index.js

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,10 @@
44
import { highlight, unHighlight, getInstanceRect } from './highlighter'
55
import { initVuexBackend } from './vuex'
66
import { initEventsBackend } from './events'
7-
import { stringify, classify, camelize, set, parse } from '../util'
8-
import path from 'path'
7+
import { stringify, classify, camelize, set, parse, getComponentName } from '../util'
98
import ComponentSelector from './component-selector'
109
import config from './config'
1110

12-
// Use a custom basename functions instead of the shimed version
13-
// because it doesn't work on Windows
14-
function basename (filename, ext) {
15-
return path.basename(
16-
filename.replace(/^[a-zA-Z]:/, '').replace(/\\/g, '/'),
17-
ext
18-
)
19-
}
20-
2111
// hook should have been injected before this executes.
2212
const hook = window.__VUE_DEVTOOLS_GLOBAL_HOOK__
2313
const rootInstances = []
@@ -67,7 +57,6 @@ function connect () {
6757
currentInspectedId = id
6858
const instance = instanceMap.get(id)
6959
bindToConsole(instance)
70-
flush()
7160
bridge.send('instance-details', stringify(getInstanceDetails(id)))
7261
})
7362

@@ -383,6 +372,7 @@ export function getCustomInstanceDetails (instance) {
383372
type: 'component',
384373
id: instance.__VUE_DEVTOOLS_UID__,
385374
display: getInstanceName(instance),
375+
tooltip: 'Component instance',
386376
value: reduceStateList(state),
387377
fields: {
388378
abstract: true
@@ -411,14 +401,8 @@ export function reduceStateList (list) {
411401
*/
412402

413403
export function getInstanceName (instance) {
414-
const name = instance.$options.name || instance.$options._componentTag
415-
if (name) {
416-
return name
417-
}
418-
const file = instance.$options.__file // injected by vue-loader
419-
if (file) {
420-
return classify(basename(file, '.vue'))
421-
}
404+
const name = getComponentName(instance.$options)
405+
if (name) return name
422406
return instance.$root === instance
423407
? 'Root'
424408
: 'Anonymous Component'
@@ -444,11 +428,11 @@ function processProps (instance) {
444428
type: 'props',
445429
key: prop.path,
446430
value: instance[prop.path],
447-
meta: {
431+
meta: options ? {
448432
type: options.type ? getPropType(options.type) : 'any',
449433
required: !!options.required,
450434
mode: propModes[prop.mode]
451-
}
435+
} : {}
452436
}
453437
})
454438
} else if ((props = instance.$options.props)) {
@@ -461,9 +445,11 @@ function processProps (instance) {
461445
type: 'props',
462446
key,
463447
value: instance[key],
464-
meta: {
448+
meta: prop ? {
465449
type: prop.type ? getPropType(prop.type) : 'any',
466450
required: !!prop.required
451+
} : {
452+
type: 'invalid'
467453
}
468454
})
469455
}
@@ -565,27 +551,30 @@ function processComputed (instance) {
565551
*/
566552

567553
function processRouteContext (instance) {
568-
const route = instance.$route
569-
if (route) {
570-
const { path, query, params } = route
571-
const value = { path, query, params }
572-
if (route.fullPath) value.fullPath = route.fullPath
573-
if (route.hash) value.hash = route.hash
574-
if (route.name) value.name = route.name
575-
if (route.meta) value.meta = route.meta
576-
return [{
577-
key: '$route',
578-
value: {
579-
_custom: {
580-
type: 'router',
581-
abstract: true,
582-
value
554+
try {
555+
const route = instance.$route
556+
if (route) {
557+
const { path, query, params } = route
558+
const value = { path, query, params }
559+
if (route.fullPath) value.fullPath = route.fullPath
560+
if (route.hash) value.hash = route.hash
561+
if (route.name) value.name = route.name
562+
if (route.meta) value.meta = route.meta
563+
return [{
564+
key: '$route',
565+
value: {
566+
_custom: {
567+
type: 'router',
568+
abstract: true,
569+
value
570+
}
583571
}
584-
}
585-
}]
586-
} else {
587-
return []
572+
}]
573+
}
574+
} catch (e) {
575+
// Invalid $router
588576
}
577+
return []
589578
}
590579

591580
/**

src/backend/router.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export function getCustomRouterDetails (router) {
2+
return {
3+
_custom: {
4+
type: 'router',
5+
display: 'VueRouter',
6+
value: {
7+
options: router.options,
8+
currentRoute: router.currentRoute
9+
},
10+
fields: {
11+
abstract: true
12+
}
13+
}
14+
}
15+
}

src/backend/vuex.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,19 @@ export function initVuexBackend (hook, bridge) {
4141
recording = enabled
4242
})
4343
}
44+
45+
export function getCustomStoreDetails (store) {
46+
return {
47+
_custom: {
48+
type: 'store',
49+
display: 'Store',
50+
value: {
51+
state: store.state,
52+
getters: store.getters
53+
},
54+
fields: {
55+
abstract: true
56+
}
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)