]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
chore: remove outdated TODO
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 29 Apr 2020 14:10:33 +0000 (16:10 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 29 Apr 2020 14:10:33 +0000 (16:10 +0200)
16 files changed:
__tests__/RouterView.spec.ts
__tests__/history/hash.spec.ts
__tests__/matcher/pathParser.spec.ts
__tests__/matcher/pathRanking.spec.ts
__tests__/mount.ts
e2e/scroll-behavior/index.ts
playground/views/ComponentWithData.vue
playground/views/User.vue
src/RouterLink.ts
src/history/memory.ts
src/install.ts
src/matcher/index.ts
src/matcher/pathMatcher.ts
src/matcher/pathTokenizer.ts
src/router.ts
src/types/index.ts

index 08a53a661e7984f4802412e644b93953c898a045..b7e163915dd1ed757f239e6b255738e0bb8ac1db 100644 (file)
@@ -196,10 +196,15 @@ describe('RouterView', () => {
   })
 
   it('does not pass params as props by default', async () => {
-    // TODO: rewrite so it is by default instead of explicitly stated
     let noPropsWithParams = {
       ...routes.withParams,
-      matched: [{ ...routes.withParams.matched[0], props: false }],
+      matched: [
+        {
+          components: { default: components.User },
+          instances: {},
+          path: '/users/:id',
+        },
+      ],
     }
     const { wrapper, route } = await factory(noPropsWithParams)
     expect(wrapper.html()).toBe(`<div>User: default</div>`)
index 5f3fbdbcbdc3c5ff38fba6eef348959459f780c4..765b23f6244babb2650953e5740222d9324e5ba6 100644 (file)
@@ -80,7 +80,5 @@ describe('History Hash', () => {
         expect.stringMatching(/^#\/?$/)
       )
     })
-
-    it.todo('warns if we provide a base with file://')
   })
 })
index 6225d6c1ab8987eda35921d464f6a27a988a719c..2d5d18100de4a3b956cdd8e60ffaefd57bce7f07 100644 (file)
@@ -9,14 +9,6 @@ describe('Path parser', () => {
       ])
     })
 
-    // TODO: refactor trailing slash cases
-    it.skip('trailing slash', () => {
-      expect(tokenizePath('/foo/')).toEqual([
-        [{ type: TokenType.Static, value: 'foo' }],
-        [{ type: TokenType.Static, value: '' }],
-      ])
-    })
-
     it('empty', () => {
       expect(tokenizePath('')).toEqual([[]])
     })
index f437fed0979047cd66ccaa1feaa8cedc6401ba53..86e9151a1979227ffa3e3fb3faa541c4b2132ccd 100644 (file)
@@ -38,7 +38,7 @@ describe('Path ranking', () => {
     })
     it('longer', () => {
       expect(compare([[2]], [[3, 1]])).toEqual(1)
-      // TODO: we are assuming we never pass end: false
+      // NOTE: we are assuming we never pass end: false
       expect(compare([[3]], [[3, 1]])).toEqual(1)
       expect(compare([[1, 3]], [[2]])).toEqual(1)
       expect(compare([[4]], [[3]])).toEqual(-1)
index 46091bc2caee2e3ac632938d8dd0b5e927c1b7ce..8e460a4bc78c173bdbdf8f1210fb920bbf93ff03 100644 (file)
@@ -41,7 +41,6 @@ function initialProps<P>(propsOption: ComponentObjectPropsOptions<P>) {
     const prop = propsOption[key]!
     // @ts-ignore
     if (!prop.required && prop.default)
-      // TODO: function value
       // @ts-ignore
       copy[key] = prop.default
   }
@@ -57,7 +56,6 @@ afterAll(() => {
 })
 
 export function mount(
-  // TODO: generic?
   targetComponent: Parameters<typeof createApp>[0],
   options: Partial<MountOptions> = {}
 ): Promise<Wrapper> {
@@ -124,7 +122,6 @@ export function mount(
       }
     }
 
-    // TODO: how to cleanup?
     const rootEl = document.createElement('div')
     document.body.appendChild(rootEl)
 
@@ -140,6 +137,7 @@ export function mount(
 
     activeWrapperRemovers.push(() => {
       app.unmount(rootEl)
+      rootEl.remove()
     })
   })
 }
index dbafb0a21e3866afee7791759105b63997a020ec..5ba37ef50ec12ac1baa98ab167c0c4a84315f261 100644 (file)
@@ -40,8 +40,7 @@ const scrollBehavior: ScrollBehavior = async function (
 
       // specify offset of the element
       if (to.hash === '#anchor2') {
-        // TODO: allow partial { y: 100 }
-        position.offset = { x: 0, y: 100 }
+        position.offset = { y: 100 }
       }
 
       // bypass #1number check
index a1598ac8f01df8fb8952502066dd3d656642f167..9a989f1419dbf8aba8b681ce26c9404f5ef9f067 100644 (file)
@@ -8,14 +8,18 @@
 <script>
 import { defineComponent, toRefs, reactive, inject } from 'vue'
 import { getData, delay } from '../api'
+import { onBeforeRouteUpdate } from '../../src'
 
 export default defineComponent({
   name: 'ComponentWithData',
   async setup() {
-    const data = reactive({ other: 'old' })
+    const data = reactive({ other: 'old', fromApi: null })
     data.fromApi = await getData()
 
-    // TODO: add sample with onBeforeRouteUpdate()
+    onBeforeRouteUpdate(async (to, from, next) => {
+      data.fromApi = await getData()
+      next()
+    })
 
     return {
       ...toRefs(data),
index 86ccd0c0465a14bfaa40d0ae38ce139f81fd5a76..af3e663565b3db8656751e34cf5f2cb018169352 100644 (file)
@@ -12,10 +12,9 @@ export default defineComponent({
   },
 
   beforeRouteUpdate(to, from, next) {
-    // TODO: these do not work yet
-    console.log('this', this)
+    console.log('in beforeRouteUpdate this', this)
     next(vm => {
-      console.log('in next', vm)
+      console.log('in next callback', vm)
     })
   },
 })
index b093820baeaddfe06449fe27bfc405cbecd1bef3..6c9eda60cfdca7c9362652fc1f4ed1d3f970cd8e 100644 (file)
@@ -51,12 +51,10 @@ export function useLink(props: UseLinkOptions) {
       isSameLocationObject(currentRoute.params, route.value.params)
   )
 
-  // TODO: handle replace prop
-  // const method = unref(rep)
-
-  function navigate(e: MouseEvent = {} as MouseEvent) {
-    // TODO: handle navigate with empty parameters for scoped slot and composition api
-    if (guardEvent(e)) router.push(unref(props.to))
+  function navigate(e: MouseEvent = {} as MouseEvent): Promise<any> {
+    if (guardEvent(e))
+      return router[unref(props.replace) ? 'replace' : 'push'](unref(props.to))
+    return Promise.resolve()
   }
 
   return {
index 83f447f6d39b5c78e7f15c36adff9c0c2b9b8ce8..8e3a29331cd3432b5e1aa1d111ada741982adc8a 100644 (file)
@@ -18,7 +18,6 @@ import {
  */
 export default function createMemoryHistory(base: string = ''): RouterHistory {
   let listeners: NavigationCallback[] = []
-  // TODO: make sure this is right as the first location is nowhere so maybe this should be empty instead
   let queue: HistoryLocationNormalized[] = [START]
   let position: number = 0
 
@@ -52,7 +51,6 @@ export default function createMemoryHistory(base: string = ''): RouterHistory {
   const routerHistory: RouterHistory = {
     // rewritten by Object.defineProperty
     location: START,
-    // TODO:
     state: {},
     base,
 
index 86d6b6ef09927caaf307cd85b6cbf30cb767d162..651b8d0970598c262b8cd048e8e6f7f25e96bbf9 100644 (file)
@@ -95,5 +95,4 @@ export function applyRouterPlugin(app: App, router: Router) {
 
   app.provide(routerKey, router)
   app.provide(routeLocationKey, reactive(reactiveRoute))
-  // TODO: merge strats for beforeRoute hooks
 }
index 8c4b4a2f374ca57ff365b8b005faf8933351b2cf..fdd5198ffc9d1a3771185f4c97dee6b87f139a0f 100644 (file)
@@ -43,7 +43,6 @@ export function createRouterMatcher(
     return matcherMap.get(name)
   }
 
-  // TODO: add routes to children of parent
   function addRoute(
     record: RouteRecordRaw,
     parent?: RouteRecordMatcher,
@@ -250,7 +249,6 @@ export function createRouterMatcher(
     while (parentMatcher) {
       // reversed order so parents are at the beginning
 
-      // TODO: check resolving child routes by path when parent has an alias
       matched.unshift(parentMatcher.record)
       parentMatcher = parentMatcher.parent
     }
index 0132a111672944f723d6e86f43e931efb23106e2..fd4745dc4453971c2e11f492f0c7ec36dba4a513 100644 (file)
@@ -35,7 +35,6 @@ export function createRouteRecordMatcher(
     // passing originalRecord in Matcher.addRoute
     if (!matcher.record.aliasOf === !parent.record.aliasOf)
       parent.children.push(matcher)
-    // else TODO: save alias children to be able to remove them
   }
 
   return matcher
index 5b8cbcb0b2f66d1816f60cedc3533e5246ec6c16..2e9c43d684f2f6cf9d925b9a13eb733ca198ac0e 100644 (file)
@@ -123,9 +123,6 @@ export function tokenizePath(path: string): Array<Token[]> {
         } else if (char === ':') {
           consumeBuffer()
           state = TokenizerState.Param
-          // } else if (char === '{') {
-          // TODO: handle group (or drop it)
-          // addCharToBuffer()
         } else {
           addCharToBuffer()
         }
index 0eaa56e4e2a7c30d37899fd283339e2109cf42c3..bb37b5dda15a05f86ad2c2afc2612e5e2e41d748 100644 (file)
@@ -5,7 +5,6 @@ import {
   PostNavigationGuard,
   START_LOCATION_NORMALIZED,
   Lazy,
-  TODO,
   MatcherLocation,
   RouteLocationNormalizedLoaded,
   RouteLocation,
@@ -60,8 +59,7 @@ export interface ScrollBehavior {
     to: RouteLocationNormalized,
     from: RouteLocationNormalizedLoaded,
     savedPosition: Required<ScrollPositionCoordinates> | null
-  ): // TODO: implement false nad refactor promise based type
-  Awaitable<ScrollPosition | false | void>
+  ): Awaitable<ScrollPosition | false | void>
 }
 
 export interface RouterOptions {
@@ -405,11 +403,10 @@ export function createRouter({
   function navigate(
     to: RouteLocationNormalized,
     from: RouteLocationNormalizedLoaded
-  ): Promise<TODO> {
+  ): Promise<any> {
     let guards: Lazy<any>[]
 
     // all components here have been resolved once because we are leaving
-    // TODO: refactor both together
     guards = extractComponentsGuards(
       from.matched.filter(record => to.matched.indexOf(record) < 0).reverse(),
       'beforeRouteLeave',
@@ -477,7 +474,7 @@ export function createRouter({
         return runGuardQueue(guards)
       })
       .then(() => {
-        // TODO: at this point to.matched is normalized and does not contain any () => Promise<Component>
+        // NOTE: at this point to.matched is normalized and does not contain any () => Promise<Component>
 
         // check in-component beforeRouteEnter
         guards = extractComponentsGuards(
@@ -541,7 +538,7 @@ export function createRouter({
       record.leaveGuards = []
       // free the references
 
-      // TODO: add tests
+      // TODO: to refactor once keep-alive and transition can be supported
       record.instances = {}
     }
 
@@ -564,8 +561,9 @@ export function createRouter({
 
     // accept current navigation
     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
+    // TODO: call handleScroll in afterEach so it can also be triggered on
+    // duplicated navigation (e.g. same anchor navigation). It needs exposing
+    // the navigation information (type, direction)
     if (isBrowser) {
       const savedScroll = getSavedScrollPosition(
         getScrollKey(toLocation.fullPath, 0)
@@ -620,8 +618,9 @@ export function createRouter({
           pushWithRedirect(
             (error as NavigationRedirectError).to,
             toLocation
+          ).catch(() => {
             // TODO: in dev show warning, in prod noop, same as initial navigation
-          )
+          })
           // avoid the then branch
           return Promise.reject()
         }
@@ -649,7 +648,9 @@ export function createRouter({
           failure
         )
       })
-      .catch(() => {})
+      .catch(() => {
+        // TODO: same as above: in dev show warning, in prod noop, same as initial navigation
+      })
   })
 
   // Initialization and Errors
index 3a6fe8b47f5e6ba2affb4c3f3343e4cac7299a83..ad30df7ae340eac7abedf6c1926a3c4ad1ae9f02 100644 (file)
@@ -3,6 +3,7 @@ import { PathParserOptions } from '../matcher/pathParserRanker'
 import { Ref, ComputedRef, ComponentOptions } from 'vue'
 import { RouteRecord, RouteRecordNormalized } from '../matcher/types'
 import { HistoryState } from '../history/common'
+import { NavigationFailure } from '../errors'
 
 export type Lazy<T> = () => Promise<T>
 export type Override<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U
@@ -86,7 +87,6 @@ export interface _RouteLocationBase {
   hash: string
   name: RouteRecordName | null | undefined
   params: RouteParams
-  // TODO: make it an array?
   redirectedFrom: RouteLocation | undefined
   meta: Record<string | number | symbol, any>
 }
@@ -233,8 +233,6 @@ export interface MatcherLocation
     'name' | 'path' | 'params' | 'matched' | 'meta'
   > {}
 
-// TODO: remove any to type vm and use a generic that comes from the component
-// where the navigation guard callback is defined
 export interface NavigationGuardCallback {
   (): void
   (error: Error): void
@@ -268,7 +266,7 @@ export interface PostNavigationGuard {
     to: RouteLocationNormalized,
     from: RouteLocationNormalized,
     // TODO: move these types to a different file
-    failure?: TODO
+    failure?: NavigationFailure | void
   ): any
 }