From: Eduardo San Martin Morote Date: Wed, 24 Jun 2020 09:51:57 +0000 (+0200) Subject: refactor: rename internal function X-Git-Tag: v4.0.0-alpha.14~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2bb0db95cea7c1c87e7d2107f7feeb35551a8ca3;p=thirdparty%2Fvuejs%2Frouter.git refactor: rename internal function --- diff --git a/__tests__/location.spec.ts b/__tests__/location.spec.ts index b3738077..9be6c3a6 100644 --- a/__tests__/location.spec.ts +++ b/__tests__/location.spec.ts @@ -4,7 +4,7 @@ import { parseURL as originalParseURL, stringifyURL as originalStringifyURL, stripBase, - isSameLocationObject, + isSameRouteLocationParams, } from '../src/location' describe('parseURL', () => { @@ -243,33 +243,33 @@ describe('stripBase', () => { }) }) -describe('isSameLocationObject', () => { +describe('isSameRouteLocationParams', () => { it('compare simple values', () => { - expect(isSameLocationObject({ a: '2' }, { a: '2' })).toBe(true) - expect(isSameLocationObject({ a: '3' }, { a: '2' })).toBe(false) + expect(isSameRouteLocationParams({ a: '2' }, { a: '2' })).toBe(true) + expect(isSameRouteLocationParams({ a: '3' }, { a: '2' })).toBe(false) // different order - expect(isSameLocationObject({ a: '2', b: '3' }, { b: '3', a: '2' })).toBe( - true - ) - expect(isSameLocationObject({ a: '3', b: '3' }, { b: '3', a: '2' })).toBe( - false - ) + expect( + isSameRouteLocationParams({ a: '2', b: '3' }, { b: '3', a: '2' }) + ).toBe(true) + expect( + isSameRouteLocationParams({ a: '3', b: '3' }, { b: '3', a: '2' }) + ).toBe(false) }) it('compare array values', () => { - expect(isSameLocationObject({ a: ['2'] }, { a: ['2'] })).toBe(true) - expect(isSameLocationObject({ a: ['3'] }, { a: ['2'] })).toBe(false) + expect(isSameRouteLocationParams({ a: ['2'] }, { a: ['2'] })).toBe(true) + expect(isSameRouteLocationParams({ a: ['3'] }, { a: ['2'] })).toBe(false) // different order expect( - isSameLocationObject({ a: ['2'], b: ['3'] }, { b: ['3'], a: ['2'] }) + isSameRouteLocationParams({ a: ['2'], b: ['3'] }, { b: ['3'], a: ['2'] }) ).toBe(true) expect( - isSameLocationObject({ a: ['3'], b: ['3'] }, { b: ['3'], a: ['2'] }) + isSameRouteLocationParams({ a: ['3'], b: ['3'] }, { b: ['3'], a: ['2'] }) ).toBe(false) }) it('considers arrays of one item same as the item itself', () => { - expect(isSameLocationObject({ a: ['2'] }, { a: '2' })).toBe(true) - expect(isSameLocationObject({ a: ['3'] }, { a: '2' })).toBe(false) + expect(isSameRouteLocationParams({ a: ['2'] }, { a: '2' })).toBe(true) + expect(isSameRouteLocationParams({ a: ['3'] }, { a: '2' })).toBe(false) }) }) diff --git a/src/RouterLink.ts b/src/RouterLink.ts index 6b6239c3..82d6ac46 100644 --- a/src/RouterLink.ts +++ b/src/RouterLink.ts @@ -9,7 +9,7 @@ import { VNodeProps, } from 'vue' import { RouteLocationRaw, VueUseOptions, RouteLocation } from './types' -import { isSameLocationObject, isSameRouteRecord } from './location' +import { isSameRouteLocationParams, isSameRouteRecord } from './location' import { routerKey, routeLocationKey } from './injectionSymbols' import { RouteRecord } from './matcher/types' import { assign } from './utils' @@ -68,7 +68,7 @@ export function useLink(props: UseLinkOptions) { () => activeRecordIndex.value > -1 && activeRecordIndex.value === currentRoute.matched.length - 1 && - isSameLocationObject(currentRoute.params, route.value.params) + isSameRouteLocationParams(currentRoute.params, route.value.params) ) function navigate(e: MouseEvent = {} as MouseEvent): Promise { diff --git a/src/location.ts b/src/location.ts index 4e650708..2bccbd51 100644 --- a/src/location.ts +++ b/src/location.ts @@ -137,8 +137,8 @@ export function isSameRouteLocation( aLastIndex > -1 && aLastIndex === bLastIndex && isSameRouteRecord(a.matched[aLastIndex], b.matched[bLastIndex]) && - isSameLocationObject(a.params, b.params) && - isSameLocationObject(a.query, b.query) && + isSameRouteLocationParams(a.params, b.params) && + isSameRouteLocationParams(a.query, b.query) && a.hash === b.hash ) } @@ -157,36 +157,36 @@ export function isSameRouteRecord(a: RouteRecord, b: RouteRecord): boolean { return (a.aliasOf || a) === (b.aliasOf || b) } -export function isSameLocationObject( +export function isSameRouteLocationParams( a: RouteLocationNormalized['query'], b: RouteLocationNormalized['query'] ): boolean -export function isSameLocationObject( +export function isSameRouteLocationParams( a: RouteLocationNormalized['params'], b: RouteLocationNormalized['params'] ): boolean -export function isSameLocationObject( +export function isSameRouteLocationParams( a: RouteLocationNormalized['query' | 'params'], b: RouteLocationNormalized['query' | 'params'] ): boolean { if (Object.keys(a).length !== Object.keys(b).length) return false for (let key in a) { - if (!isSameLocationObjectValue(a[key], b[key])) return false + if (!isSameRouteLocationParamsValue(a[key], b[key])) return false } return true } -function isSameLocationObjectValue( +function isSameRouteLocationParamsValue( a: LocationQueryValue | LocationQueryValue[], b: LocationQueryValue | LocationQueryValue[] ): boolean -function isSameLocationObjectValue( +function isSameRouteLocationParamsValue( a: RouteParamValue | RouteParamValue[], b: RouteParamValue | RouteParamValue[] ): boolean -function isSameLocationObjectValue( +function isSameRouteLocationParamsValue( a: | LocationQueryValue | LocationQueryValue[]