From dc181e65ad8c993751ec70f8e7d054d4d8827538 Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Tue, 16 Jan 2018 11:26:48 +0100 Subject: [PATCH 1/4] More fault tolerant --- src/backend/index.js | 49 ++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/backend/index.js b/src/backend/index.js index 0cb3621c9..aeef5d577 100644 --- a/src/backend/index.js +++ b/src/backend/index.js @@ -441,11 +441,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)) { @@ -458,9 +458,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' } }) } @@ -562,27 +564,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 [] } /** From 6268c1a30135525fbcc0aebfb93f5c1027bc541b Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Tue, 16 Jan 2018 11:27:03 +0100 Subject: [PATCH 2/4] Display stores with CustomValue API --- src/backend/vuex.js | 16 ++++++++++++++++ src/util.js | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/src/backend/vuex.js b/src/backend/vuex.js index cfe86c23e..d88c869ec 100644 --- a/src/backend/vuex.js +++ b/src/backend/vuex.js @@ -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 + } + } + } +} diff --git a/src/util.js b/src/util.js index deb91d0e9..c31f27108 100644 --- a/src/util.js +++ b/src/util.js @@ -1,6 +1,7 @@ import CircularJSON from 'circular-json-es6' import { instanceMap, getCustomInstanceDetails } from 'src/backend' +import { getCustomStoreDetails } from 'src/backend/vuex' function cached (fn) { const cache = Object.create(null) @@ -71,6 +72,8 @@ function replacer (key) { return `[native RegExp ${val.toString()}]` } else if (val instanceof Date) { return `[native Date ${val.toString()}]` + } else if (isVuexStore(val)) { + return getCustomStoreDetails(val) } else if (val && val._isVue) { return getCustomInstanceDetails(val) } else { @@ -78,6 +81,10 @@ function replacer (key) { } } +export function isVuexStore (val) { + return val && val.state && val._vm +} + export function parse (data, revive) { return revive ? CircularJSON.parse(data, reviver) From 4272abb33b5b1907f1f15b92fa3a630297a721ec Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Tue, 16 Jan 2018 11:38:52 +0100 Subject: [PATCH 3/4] Dsiplay VueRouter instances with CustomValue API --- src/backend/router.js | 19 +++++++++++++++++++ src/backend/vuex.js | 4 ++++ src/util.js | 9 ++++----- 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 src/backend/router.js diff --git a/src/backend/router.js b/src/backend/router.js new file mode 100644 index 000000000..fc795f7ea --- /dev/null +++ b/src/backend/router.js @@ -0,0 +1,19 @@ +export function isVueRouter (router) { + return router && router.constructor && router.constructor.name === 'VueRouter' +} + +export function getCustomRouterDetails (router) { + return { + _custom: { + type: 'router', + display: 'VueRouter', + value: { + options: router.options, + currentRoute: router.currentRoute + }, + fields: { + abstract: true + } + } + } +} diff --git a/src/backend/vuex.js b/src/backend/vuex.js index d88c869ec..ff66e50f4 100644 --- a/src/backend/vuex.js +++ b/src/backend/vuex.js @@ -42,6 +42,10 @@ export function initVuexBackend (hook, bridge) { }) } +export function isVuexStore (val) { + return val && val.state && val._vm +} + export function getCustomStoreDetails (store) { return { _custom: { diff --git a/src/util.js b/src/util.js index c31f27108..742aec987 100644 --- a/src/util.js +++ b/src/util.js @@ -1,7 +1,8 @@ import CircularJSON from 'circular-json-es6' import { instanceMap, getCustomInstanceDetails } from 'src/backend' -import { getCustomStoreDetails } from 'src/backend/vuex' +import { isVuexStore, getCustomStoreDetails } from 'src/backend/vuex' +import { isVueRouter, getCustomRouterDetails } from 'src/backend/router' function cached (fn) { const cache = Object.create(null) @@ -74,6 +75,8 @@ function replacer (key) { return `[native Date ${val.toString()}]` } else if (isVuexStore(val)) { return getCustomStoreDetails(val) + } else if (isVueRouter(val)) { + return getCustomRouterDetails(val) } else if (val && val._isVue) { return getCustomInstanceDetails(val) } else { @@ -81,10 +84,6 @@ function replacer (key) { } } -export function isVuexStore (val) { - return val && val.state && val._vm -} - export function parse (data, revive) { return revive ? CircularJSON.parse(data, reviver) From f5d9fd58f8336eeac2210fc0454ab6d9494a4a7c Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Tue, 16 Jan 2018 12:21:43 +0100 Subject: [PATCH 4/4] CustomValue API: new 'tooltip' option, supports functions, component def --- shells/dev/target/NativeTypes.vue | 14 ++++- src/backend/index.js | 23 ++----- src/devtools/components/DataField.vue | 22 ++++++- src/devtools/variables.styl | 1 + src/devtools/views/events/EventInspector.vue | 2 +- .../views/vuex/VuexStateInspector.vue | 2 +- src/util.js | 62 ++++++++++++++++++- 7 files changed, 101 insertions(+), 25 deletions(-) diff --git a/shells/dev/target/NativeTypes.vue b/shells/dev/target/NativeTypes.vue index 498fb2944..c45c2fec6 100644 --- a/shells/dev/target/NativeTypes.vue +++ b/shells/dev/target/NativeTypes.vue @@ -18,6 +18,7 @@