Skip to content

Serialization & Types improvements #523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Jan 22, 2018
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 79 additions & 6 deletions shells/dev/target/NativeTypes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,116 @@
<TestComponent ref="component" />

<p>
<button @click="sendComponent">Vuex mutation</button>
<button @click="sendComponent()">Vuex mutation</button>
<button @click="createLargeArray()">Create large array</button>
</p>

<h3>Set</h3>
<pre>{{ setDisplay() }}</pre>

<h3>Map</h3>
<pre>{{ mapDisplay() }}</pre>

<p>
<button @click="testVuexSet()">Vuex Set</button>
<button @click="testVuexMap()">Vuex Map</button>
<button @click="forceRefresh()">Refresh</button>
</p>
</div>
</template>

<script>
import { mapState, mapGetters, mapMutations } from 'vuex'
import CompDef from './Other.vue'

export default {
components: {
TestComponent: {
data: () => ({ foo: '42' }),
props: { bar: { default: 'hey' }},
data: () => ({ foo: '42' }),
computed: {
parentComp () { return this.$parent }
},
render: h => h('div', '<TestComponent />')
}
},

data () {
return {
localDate: new Date(),
testComponent: null
reg: /abc/gi,
testComponent: null,
hello: function foo (a, b, c) {},
hey: function empty () {},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add anonymous function here and make sure it works good as well?
hi: function (a, b) {} should be displayed probably as f (a, b), also what about arrow functions? Or hi() {}?

def: CompDef,
def2: {
name: 'MyComponent',
render () {}
},
def3: {
render () {}
},
largeArray: [],
i: new Set([1, 2, 3, 4, new Set([5, 6, 7, 8]), new Map([[1, 2], [3, 4], [5, new Map([[6, 7]])]])]),
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]])]])])]])
}
},
computed: {
...mapState(['date']),
...mapGetters(['hours'])
...mapState([
'date',
'set',
'map'
]),

...mapGetters([
'hours'
]),

theRouter () {
return this.$router
},

theStore () {
return this.$store
},
},

mounted () {
this.testComponent = this.$refs.component
},

methods: {
...mapMutations({
updateDate: 'UPDATE_DATE'
updateDate: 'UPDATE_DATE',
testVuexSet: 'TEST_SET',
testVuexMap: 'TEST_MAP'
}),

sendComponent () {
this.$store.commit('TEST_COMPONENT', this.testComponent)
},

createLargeArray () {
const list = []
for (let i = 0; i < 10000000; i++) {
list.push(i)
}
this.largeArray = list
},

setDisplay () {
return Array.from(this.set)
},

mapDisplay () {
return [...this.map]
},

forceRefresh () {
this.$forceUpdate()
}
},

filters: {
prototypeString: val => Object.prototype.toString.call(val)
}
Expand Down
12 changes: 10 additions & 2 deletions shells/dev/target/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ Vue.use(Vuex)
export default new Vuex.Store({
state: {
count: 0,
date: new Date()
date: new Date(),
set: new Set(),
map: new Map()
},
mutations: {
INCREMENT: state => state.count++,
DECREMENT: state => state.count--,
UPDATE_DATE: state => {
state.date = new Date()
},
TEST_COMPONENT: state => {}
TEST_COMPONENT: state => {},
TEST_SET: state => {
state.set.add(Math.random())
},
TEST_MAP: state => {
state.map.set(`mykey_${state.map.size}`, state.map.size)
}
},
getters: {
isPositive: state => state.count >= 0,
Expand Down
73 changes: 31 additions & 42 deletions src/backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,9 @@
import { highlight, unHighlight, getInstanceRect } from './highlighter'
import { initVuexBackend } from './vuex'
import { initEventsBackend } from './events'
import { stringify, classify, camelize, set, parse } from '../util'
import path from 'path'
import { stringify, classify, camelize, set, parse, getComponentName } from '../util'
import ComponentSelector from './component-selector'

// Use a custom basename functions instead of the shimed version
// because it doesn't work on Windows
function basename (filename, ext) {
return path.basename(
filename.replace(/^[a-zA-Z]:/, '').replace(/\\/g, '/'),
ext
)
}

// hook should have been injected before this executes.
const hook = window.__VUE_DEVTOOLS_GLOBAL_HOOK__
const rootInstances = []
Expand Down Expand Up @@ -64,7 +54,6 @@ function connect () {
currentInspectedId = id
const instance = instanceMap.get(id)
bindToConsole(instance)
flush()
bridge.send('instance-details', stringify(getInstanceDetails(id)))
})

Expand Down Expand Up @@ -380,6 +369,7 @@ export function getCustomInstanceDetails (instance) {
type: 'component',
id: instance.__VUE_DEVTOOLS_UID__,
display: getInstanceName(instance),
tooltip: 'Component instance',
value: reduceStateList(state),
fields: {
abstract: true
Expand Down Expand Up @@ -408,14 +398,8 @@ export function reduceStateList (list) {
*/

export function getInstanceName (instance) {
const name = instance.$options.name || instance.$options._componentTag
if (name) {
return name
}
const file = instance.$options.__file // injected by vue-loader
if (file) {
return classify(basename(file, '.vue'))
}
const name = getComponentName(instance.$options)
if (name) return name
return instance.$root === instance
? 'Root'
: 'Anonymous Component'
Expand All @@ -441,11 +425,11 @@ function processProps (instance) {
type: 'props',
key: prop.path,
value: instance[prop.path],
meta: {
meta: options ? {
type: options.type ? getPropType(options.type) : 'any',
required: !!options.required,
mode: propModes[prop.mode]
}
} : {}
}
})
} else if ((props = instance.$options.props)) {
Expand All @@ -458,9 +442,11 @@ function processProps (instance) {
type: 'props',
key,
value: instance[key],
meta: {
meta: prop ? {
type: prop.type ? getPropType(prop.type) : 'any',
required: !!prop.required
} : {
type: 'invalid'
}
})
}
Expand Down Expand Up @@ -562,27 +548,30 @@ function processComputed (instance) {
*/

function processRouteContext (instance) {
const route = instance.$route
if (route) {
const { path, query, params } = route
const value = { path, query, params }
if (route.fullPath) value.fullPath = route.fullPath
if (route.hash) value.hash = route.hash
if (route.name) value.name = route.name
if (route.meta) value.meta = route.meta
return [{
key: '$route',
value: {
_custom: {
type: 'router',
abstract: true,
value
try {
const route = instance.$route
if (route) {
const { path, query, params } = route
const value = { path, query, params }
if (route.fullPath) value.fullPath = route.fullPath
if (route.hash) value.hash = route.hash
if (route.name) value.name = route.name
if (route.meta) value.meta = route.meta
return [{
key: '$route',
value: {
_custom: {
type: 'router',
abstract: true,
value
}
}
}
}]
} else {
return []
}]
}
} catch (e) {
// Invalid $router
}
return []
}

/**
Expand Down
15 changes: 15 additions & 0 deletions src/backend/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function getCustomRouterDetails (router) {
return {
_custom: {
type: 'router',
display: 'VueRouter',
value: {
options: router.options,
currentRoute: router.currentRoute
},
fields: {
abstract: true
}
}
}
}
16 changes: 16 additions & 0 deletions src/backend/vuex.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,19 @@ export function initVuexBackend (hook, bridge) {
recording = enabled
})
}

export function getCustomStoreDetails (store) {
return {
_custom: {
type: 'store',
display: 'Store',
value: {
state: store.state,
getters: store.getters
},
fields: {
abstract: true
}
}
}
}
Loading