]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
refactor: remove duplicated type
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 12 Feb 2020 11:04:33 +0000 (12:04 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 12 Feb 2020 11:04:33 +0000 (12:04 +0100)
__tests__/RouterLink.spec.ts
__tests__/extractComponentsGuards.spec.ts
__tests__/utils.ts
src/components/Link.ts
src/components/View.ts
src/matcher/types.ts
src/router.ts
src/types/index.ts
src/utils/index.ts

index 67d08602c1bbeec2085993aec75edbb0ea61fbe5..c9c9bd51f5be48b6c84dd6c749efc58fd471ea57 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * @jest-environment jsdom
  */
-import RouterLink from '../src/components/Link'
+import { Link as RouterLink } from '../src/components/Link'
 import {
   START_LOCATION_NORMALIZED,
   RouteQueryAndHash,
index d274e4036e179026be9cf13cb91e3a1ef15d2053..128a91947ce561b73679d5345c161c508cd4b80e 100644 (file)
@@ -1,7 +1,7 @@
 import { extractComponentsGuards } from '../src/utils'
 import { START_LOCATION_NORMALIZED, RouteRecord } from '../src/types'
 import { components, normalizeRouteRecord } from './utils'
-import { RouteRecordMatched } from '../src/matcher/types'
+import { RouteRecordNormalized } from '../src/matcher/types'
 
 const beforeRouteEnter = jest.fn()
 
@@ -24,7 +24,7 @@ const SingleGuardNamed: RouteRecord = {
 
 function makeAsync(
   record: Exclude<RouteRecord, { redirect: any }>
-): RouteRecordMatched {
+): RouteRecordNormalized {
   if ('components' in record) {
     const copy = { ...record }
     copy.components = Object.keys(record.components).reduce(
index 9e5c45a7cff4fde76dc4833d7908a34f11492b74..35462a3a38b9457fd136fccaac7c08a933de2097 100644 (file)
@@ -7,7 +7,7 @@ import {
   RouteLocationNormalized,
 } from '../src/types'
 import { h, resolveComponent } from 'vue'
-import { RouteRecordMatched } from '../src/matcher/types'
+import { RouteRecordNormalized } from '../src/matcher/types'
 
 export const tick = (time?: number) =>
   new Promise(resolve => {
@@ -110,7 +110,7 @@ const DEFAULT_COMMON_RECORD_PROPERTIES = {
 export function normalizeRouteRecord(
   // cannot be a redirect record
   record: Exclude<RouteRecord, { redirect: any }>
-): RouteRecordMatched {
+): RouteRecordNormalized {
   if ('components' in record)
     return {
       ...DEFAULT_COMMON_RECORD_PROPERTIES,
index 8d615a4482117dd297fad1e6584aca11c5eb74c9..9c0d8d51944b44c3308fefc4a561520181fb7656 100644 (file)
@@ -42,7 +42,7 @@ export function useLink(props: UseLinkProps) {
   }
 }
 
-const Link = defineComponent({
+export const Link = defineComponent({
   name: 'RouterLink',
   props: {
     to: {
@@ -95,5 +95,3 @@ function guardEvent(e: MouseEvent) {
 
   return true
 }
-
-export default Link
index b3753f1a98cccaefd8b62dbca4392a10030f1f4a..1fac190168e57222c8184d257a201ec3e8a03601 100644 (file)
@@ -9,10 +9,12 @@ import {
   InjectionKey,
   Ref,
 } from 'vue'
-import { RouteRecordMatched } from '../matcher/types'
+import { RouteRecordNormalized } from '../matcher/types'
 
 // TODO: make it work with no symbols too for IE
-export const matchedRouteKey = Symbol() as InjectionKey<Ref<RouteRecordMatched>>
+export const matchedRouteKey = Symbol() as InjectionKey<
+  Ref<RouteRecordNormalized>
+>
 
 export const View = defineComponent({
   name: 'RouterView',
index fae8580e2c8b3d276ab15eb2616de10d0364a2d5..752afcb24a95991f070db3d5599f2f7297c0710c 100644 (file)
@@ -4,7 +4,6 @@ export interface RouteRecordNormalizedCommon {
   leaveGuards: NavigationGuard[]
 }
 
-// TODO: rename or refactor the duplicated type
 // normalize component/components into components
 export type RouteRecordNormalized = RouteRecordNormalizedCommon &
   // TODO: make it required (monomorphic)
@@ -12,6 +11,3 @@ export type RouteRecordNormalized = RouteRecordNormalizedCommon &
     RouteRecordMultipleViews,
     'path' | 'name' | 'components' | 'children' | 'meta' | 'beforeEnter'
   >
-
-// When Matching a location, only RouteRecordView is possible, because redirections never end up in `matched`
-export type RouteRecordMatched = RouteRecordNormalized
index aed0b767abfb77b428271ddd10493050d4bf13b6..2b17b0dbd13c639f46392f6240c4a2f64c553fab 100644 (file)
@@ -31,8 +31,8 @@ import { useCallbacks } from './utils/callbacks'
 import { encodeParam, decode } from './utils/encoding'
 import { normalizeQuery, parseQuery, stringifyQuery } from './utils/query'
 import { ref, Ref, markNonReactive, nextTick, App } from 'vue'
-import { RouteRecordMatched } from './matcher/types'
-import Link from './components/Link'
+import { RouteRecordNormalized } from './matcher/types'
+import { Link } from './components/Link'
 import { View } from './components/View'
 
 type ErrorHandler = (error: any) => any
@@ -485,9 +485,9 @@ function extractChangingRecords(
   to: RouteLocationNormalized,
   from: RouteLocationNormalized
 ) {
-  const leavingRecords: RouteRecordMatched[] = []
-  const updatingRecords: RouteRecordMatched[] = []
-  const enteringRecords: RouteRecordMatched[] = []
+  const leavingRecords: RouteRecordNormalized[] = []
+  const updatingRecords: RouteRecordNormalized[] = []
+  const enteringRecords: RouteRecordNormalized[] = []
 
   // TODO: could be optimized with one single for loop
   for (const record of from.matched) {
index d96da34a6f462d66d36aa38f7804adc998181d34..93ec05fbe0d017a155c20f50f75f14d7b1e82b3a 100644 (file)
@@ -1,7 +1,7 @@
 import { HistoryQuery, RawHistoryQuery } from '../utils/query'
 import { PathParserOptions } from '../matcher/path-parser-ranker'
 import { markNonReactive } from 'vue'
-import { RouteRecordMatched } from '../matcher/types'
+import { RouteRecordNormalized } from '../matcher/types'
 
 // type Component = ComponentOptions<Vue> | typeof Vue | AsyncComponent
 
@@ -56,7 +56,7 @@ export interface RouteLocationNormalized
   query: HistoryQuery
   // TODO: do the same for params
   name: string | null | undefined
-  matched: RouteRecordMatched[] // non-enumerable
+  matched: RouteRecordNormalized[] // non-enumerable
   redirectedFrom?: RouteLocationNormalized
   meta: Record<string | number | symbol, any>
 }
@@ -168,7 +168,7 @@ export interface MatcherLocationNormalized {
   path: string
   // record?
   params: RouteLocationNormalized['params']
-  matched: RouteRecordMatched[]
+  matched: RouteRecordNormalized[]
   // TODO: remove optional and allow null as value (monomorphic)
   redirectedFrom?: MatcherLocationNormalized
   meta: RouteLocationNormalized['meta']
index d9c8169e23b21b3114b2f0596469cf3c9018bd95..da97587f2bbe0eada4558723708f4e56b7eaf98a 100644 (file)
@@ -1,12 +1,12 @@
 import { RouteLocationNormalized, RouteParams } from '../types'
 import { guardToPromiseFn } from './guardToPromiseFn'
-import { RouteRecordMatched } from '../matcher/types'
+import { RouteRecordNormalized } from '../matcher/types'
 
 export * from './guardToPromiseFn'
 
 type GuardType = 'beforeRouteEnter' | 'beforeRouteUpdate' | 'beforeRouteLeave'
 export async function extractComponentsGuards(
-  matched: RouteRecordMatched[],
+  matched: RouteRecordNormalized[],
   guardType: GuardType,
   to: RouteLocationNormalized,
   from: RouteLocationNormalized