From a821ec557f3066bdc354097597965495d123ef41 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Tue, 1 Sep 2020 22:49:59 +0200 Subject: [PATCH] wip bad internet../../.. --- src/devtools.ts | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ src/router.ts | 5 ++++ 2 files changed, 68 insertions(+) create mode 100644 src/devtools.ts diff --git a/src/devtools.ts b/src/devtools.ts new file mode 100644 index 00000000..7f9629a4 --- /dev/null +++ b/src/devtools.ts @@ -0,0 +1,63 @@ +import { App, setupDevtoolsPlugin } from '@vue/devtools-api' +import { Router } from './router' + +export function addDevtools(app: App, router: Router) { + setupDevtoolsPlugin( + { + id: 'Router', + label: 'Router devtools', + app, + }, + api => { + api.on.inspectComponent((payload, ctx) => { + if (payload.instanceData) { + const stateType = 'extra properties (test)' + payload.instanceData.state.push({ + type: stateType, + key: 'foo', + value: 'bar', + editable: false, + }) + + payload.instanceData.state.push({ + type: stateType, + key: 'time', + editable: false, + value: { + _custom: { + type: null, + readOnly: true, + display: `${router.currentRoute.value.fullPath}s`, + tooltip: 'Current Route', + value: router.currentRoute.value, + }, + }, + }) + } + }) + + api.addTimelineLayer({ + id: 'router:navigations', + label: 'Router Navigations', + color: 0x92a2bf, + }) + + router.afterEach((from, to) => { + // @ts-ignore + api.notifyComponentUpdate() + api.addTimelineEvent({ + layerId: 'router:navigations', + event: { + time: Date.now(), + data: { + info: 'afterEach', + from, + to, + }, + meta: { foo: 'meta?' }, + }, + }) + }) + } + ) +} diff --git a/src/router.ts b/src/router.ts index 786c4180..9a73539d 100644 --- a/src/router.ts +++ b/src/router.ts @@ -57,6 +57,7 @@ import { warn } from './warning' import { RouterLink } from './RouterLink' import { RouterView } from './RouterView' import { routerKey, routeLocationKey } from './injectionSymbols' +import { addDevtools } from './devtools' /** * Internal type to define an ErrorHandler @@ -1103,6 +1104,10 @@ export function createRouter(options: RouterOptions): Router { } unmountApp.call(this, arguments) } + + if (__DEV__) { + addDevtools(app, router) + } }, } -- 2.47.3