]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
refactor: rename internal function
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 24 Jun 2020 09:51:57 +0000 (11:51 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 24 Jun 2020 09:51:57 +0000 (11:51 +0200)
__tests__/location.spec.ts
src/RouterLink.ts
src/location.ts

index b3738077ca82e757f04b123f5fb8e9af58d557a8..9be6c3a690f076c1ef6837f2cc9aed206467e0e2 100644 (file)
@@ -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)
   })
 })
index 6b6239c325683e7879da393db5e5057ea8367e4a..82d6ac46ac303a148b936abbfbd9729c5092214d 100644 (file)
@@ -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<any> {
index 4e650708a5002f4bf2d9820ad1802a44c2a99b02..2bccbd51d5911d9b979339fc5e8e384bd7d3635a 100644 (file)
@@ -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[]