From: Eduardo San Martin Morote Date: Fri, 24 Apr 2020 16:43:27 +0000 (+0200) Subject: refactor: use shallowRef X-Git-Tag: v4.0.0-alpha.8~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b971458132f3511e599db389ff239f16cf97107e;p=thirdparty%2Fvuejs%2Frouter.git refactor: use shallowRef --- diff --git a/src/router.ts b/src/router.ts index 68226e19..f9004c49 100644 --- a/src/router.ts +++ b/src/router.ts @@ -39,7 +39,7 @@ import { parseQuery as originalParseQuery, stringifyQuery as originalStringifyQuery, } from './query' -import { ref, Ref, markRaw, nextTick, App, warn } from 'vue' +import { shallowRef, Ref, nextTick, App, warn } from 'vue' import { RouteRecord, RouteRecordNormalized } from './matcher/types' import { parseURL, stringifyURL, isSameRouteLocation } from './location' import { extractComponentsGuards, guardToPromiseFn } from './navigationGuards' @@ -161,7 +161,7 @@ export function createRouter({ const beforeGuards = useCallbacks>() const beforeResolveGuards = useCallbacks>() const afterGuards = useCallbacks() - const currentRoute = ref( + const currentRoute = shallowRef( START_LOCATION_NORMALIZED ) let pendingLocation: RouteLocation = START_LOCATION_NORMALIZED @@ -525,7 +525,7 @@ export function createRouter({ } // accept current navigation - currentRoute.value = markRaw(toLocation) + currentRoute.value = toLocation // TODO: this doesn't work on first load. Moving it to RouterView could allow automatically handling transitions too maybe // TODO: refactor with a state getter if (isBrowser) { diff --git a/src/types/index.ts b/src/types/index.ts index 3943a791..3a6fe8b4 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,6 +1,6 @@ import { LocationQuery, LocationQueryRaw } from '../query' import { PathParserOptions } from '../matcher/pathParserRanker' -import { markRaw, Ref, ComputedRef, ComponentOptions } from 'vue' +import { Ref, ComputedRef, ComponentOptions } from 'vue' import { RouteRecord, RouteRecordNormalized } from '../matcher/types' import { HistoryState } from '../history/common' @@ -201,19 +201,17 @@ export type RouteRecordRaw = | RouteRecordMultipleViews | RouteRecordRedirectRaw -export const START_LOCATION_NORMALIZED: RouteLocationNormalizedLoaded = markRaw( - { - path: '/', - name: undefined, - params: {}, - query: {}, - hash: '', - fullPath: '/', - matched: [], - meta: {}, - redirectedFrom: undefined, - } -) +export const START_LOCATION_NORMALIZED: RouteLocationNormalizedLoaded = { + path: '/', + name: undefined, + params: {}, + query: {}, + hash: '', + fullPath: '/', + matched: [], + meta: {}, + redirectedFrom: undefined, +} // make matched non enumerable for easy printing // NOTE: commented for tests at RouterView.spec