From: Eduardo San Martin Morote Date: Tue, 1 Sep 2020 20:49:59 +0000 (+0200) Subject: wip bad internet../../.. X-Git-Tag: v4.0.0-rc.2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a821ec557f3066bdc354097597965495d123ef41;p=thirdparty%2Fvuejs%2Frouter.git wip bad internet../../.. --- 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) + } }, }