]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
refactor: rename NavigationType NavigationDirection
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 5 Jun 2019 13:58:11 +0000 (15:58 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 5 Jun 2019 13:58:11 +0000 (15:58 +0200)
__tests__/abstract.spec.js
explorations/html5.ts
src/history/abstract.ts
src/history/base.ts
src/history/html5.ts
src/router.ts

index e4822728431cd88e14dd748bbf567108f042666a..1b8a6b1d6f8550622be706982c8a60c1a2aba49d 100644 (file)
@@ -173,11 +173,11 @@ describe('Abstract/in memory history', () => {
     history.push(loc)
     history.back()
     expect(spy).toHaveBeenCalledTimes(1)
-    expect(spy).toHaveBeenCalledWith(START, normaliezedLoc, { type: 'back' })
+    expect(spy).toHaveBeenCalledWith(START, normaliezedLoc, { direction: 'back' })
     history.forward()
     expect(spy).toHaveBeenCalledTimes(2)
     expect(spy).toHaveBeenLastCalledWith(normaliezedLoc, START, {
-      type: 'forward',
+      direction: 'forward',
     })
   })
 
index ac52cc593674c507ae499011d7fd3745e71047bb..ad585974fc185fdbb68ad1e4ccd1f99b465e2930 100644 (file)
@@ -84,8 +84,8 @@ window.h = h
 // @ts-ignore
 window.r = r
 
-h.listen((to, from, { type }) => {
-  console.log(`popstate(${type})`, { to, from })
+h.listen((to, from, { direction }) => {
+  console.log(`popstate(${direction})`, { to, from })
 })
 
 async function run() {
index 8e283ff2bdcc6c623d35c234a440dc311c228edd..abef01ae8607532a9d352b587b528859726204d5 100644 (file)
@@ -3,7 +3,7 @@ import {
   BaseHistory,
   HistoryLocation,
   HistoryLocationNormalized,
-  NavigationType,
+  NavigationDirection,
 } from './base'
 import { NavigationCallback, HistoryState, START } from './base'
 
@@ -63,13 +63,17 @@ export class AbstractHistory extends BaseHistory {
   back() {
     const from = this.location
     if (this.position > 0) this.position--
-    this.triggerListeners(this.location, from, { type: NavigationType.back })
+    this.triggerListeners(this.location, from, {
+      direction: NavigationDirection.back,
+    })
   }
 
   forward() {
     const from = this.location
     if (this.position < this.queue.length - 1) this.position++
-    this.triggerListeners(this.location, from, { type: NavigationType.forward })
+    this.triggerListeners(this.location, from, {
+      direction: NavigationDirection.forward,
+    })
   }
 
   destroy() {
@@ -79,9 +83,9 @@ export class AbstractHistory extends BaseHistory {
   private triggerListeners(
     to: HistoryLocationNormalized,
     from: HistoryLocationNormalized,
-    { type }: { type: NavigationType }
+    { direction }: { direction: NavigationDirection }
   ): void {
-    const info = { type }
+    const info = { direction }
     for (let callback of this.listeners) {
       callback(to, from, info)
     }
index c97ef71c5120e30c026b72e5420ae46bcbe50809..aeb6cf35cd0434e834a51b54b84384d13c6e936e 100644 (file)
@@ -41,7 +41,7 @@ export const START: HistoryLocationNormalized = {
   hash: '',
 }
 
-export enum NavigationType {
+export enum NavigationDirection {
   // NOTE: is it better to have strings?
   back = 'back',
   forward = 'forward',
@@ -51,7 +51,7 @@ export interface NavigationCallback {
   (
     to: HistoryLocationNormalized,
     from: HistoryLocationNormalized,
-    info: { type: NavigationType }
+    info: { direction: NavigationDirection }
   ): void
 }
 
index 50e056851277b70589af63f2b20a5ceb7c61b70a..248d935fae93612256fa6e55400173a510d06cda 100644 (file)
@@ -1,6 +1,6 @@
 import consola from 'consola'
 import { BaseHistory, HistoryLocationNormalized, HistoryLocation } from './base'
-import { NavigationCallback, HistoryState, NavigationType } from './base'
+import { NavigationCallback, HistoryState, NavigationDirection } from './base'
 
 const cs = consola.withTag('html5')
 
@@ -144,10 +144,10 @@ export class HTML5History extends BaseHistory {
 
       // call all listeners
       const navigationInfo = {
-        type:
+        direction:
           state.forward && from.fullPath === state.forward.fullPath
-            ? NavigationType.back
-            : NavigationType.forward,
+            ? NavigationDirection.back
+            : NavigationDirection.forward,
       }
       this._listeners.forEach(listener =>
         listener(this.location, from, navigationInfo)
index 43651ee01886fe562220c832b421a6c631f9d846..aad33aa17251424106a0a330606a6eb914052f38 100644 (file)
@@ -1,7 +1,7 @@
 import {
   BaseHistory,
   HistoryLocationNormalized,
-  NavigationType,
+  NavigationDirection,
 } from './history/base'
 import { RouterMatcher } from './matcher'
 import {
@@ -61,7 +61,7 @@ export class Router {
         } else {
           // TODO: handle abort and redirect correctly
           // if we were going back, we push and discard the rest of the history
-          if (info.type === NavigationType.back) {
+          if (info.direction === NavigationDirection.back) {
             this.history.push(from)
           } else {
             // TODO: go back because we cancelled, then