]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
refactor: rename historyquery
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 12 Feb 2020 11:10:57 +0000 (12:10 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 12 Feb 2020 11:10:57 +0000 (12:10 +0100)
src/history/common.ts
src/types/index.ts
src/utils/query.ts

index 20226d31407b91b2ae6951ae957c2e67407fe5fb..f8eab7f01aad14260b823a5cc654782eddf5a9fa 100644 (file)
@@ -1,5 +1,5 @@
 import { ListenerRemover } from '../types'
-import { RawHistoryQuery, HistoryQuery } from '../utils/query'
+import { LocationQueryRaw, LocationQuery } from '../utils/query'
 
 interface HistoryLocation {
   fullPath: string
@@ -10,14 +10,14 @@ export type RawHistoryLocation = HistoryLocation | string
 export type HistoryLocationNormalized = Pick<HistoryLocation, 'fullPath'>
 export interface LocationPartial {
   path: string
-  query?: RawHistoryQuery
+  query?: LocationQueryRaw
   hash?: string
 }
 export interface LocationNormalized {
   path: string
   fullPath: string
   hash: string
-  query: HistoryQuery
+  query: LocationQuery
 }
 
 // pushState clones the state passed and do not accept everything
@@ -94,11 +94,11 @@ export interface RouterHistory {
  * @returns a normalized history location
  */
 export function parseURL(
-  parseQuery: (search: string) => HistoryQuery,
+  parseQuery: (search: string) => LocationQuery,
   location: string
 ): LocationNormalized {
   let path = '',
-    query: HistoryQuery = {},
+    query: LocationQuery = {},
     searchString = '',
     hash = ''
 
@@ -139,7 +139,7 @@ export function parseURL(
  * @param location
  */
 export function stringifyURL(
-  stringifyQuery: (query: RawHistoryQuery) => string,
+  stringifyQuery: (query: LocationQueryRaw) => string,
   location: LocationPartial
 ): string {
   let query: string = location.query ? stringifyQuery(location.query) : ''
index 93ec05fbe0d017a155c20f50f75f14d7b1e82b3a..040f76ee1953cfe82ea4e5cec38c511f6e7f837e 100644 (file)
@@ -1,4 +1,4 @@
-import { HistoryQuery, RawHistoryQuery } from '../utils/query'
+import { LocationQuery, LocationQueryRaw } from '../utils/query'
 import { PathParserOptions } from '../matcher/path-parser-ranker'
 import { markNonReactive } from 'vue'
 import { RouteRecordNormalized } from '../matcher/types'
@@ -20,7 +20,7 @@ export type ListenerRemover = () => void
 export type RouteParams = Record<string, string | string[]>
 
 export interface RouteQueryAndHash {
-  query?: RawHistoryQuery
+  query?: LocationQueryRaw
   hash?: string
 }
 export interface LocationAsPath {
@@ -53,7 +53,7 @@ export interface RouteLocationNormalized
   extends Required<RouteQueryAndHash & LocationAsRelative & LocationAsPath> {
   fullPath: string
   // the normalized version cannot have numbers or undefined
-  query: HistoryQuery
+  query: LocationQuery
   // TODO: do the same for params
   name: string | null | undefined
   matched: RouteRecordNormalized[] // non-enumerable
index 0ceb9c87e1bb9167f5cb0e1e920012911bc4f249..0830707e6656a122ccdeb582597fa0fc62b90ec5 100644 (file)
@@ -1,14 +1,14 @@
 import { decode, encodeQueryProperty } from '../utils/encoding'
 
-type HistoryQueryValue = string | null
-type RawHistoryQueryValue = HistoryQueryValue | number | undefined
-export type HistoryQuery = Record<
+type LocationQueryValue = string | null
+type LocationQueryValueRaw = LocationQueryValue | number | undefined
+export type LocationQuery = Record<
   string,
-  HistoryQueryValue | HistoryQueryValue[]
+  LocationQueryValue | LocationQueryValue[]
 >
-export type RawHistoryQuery = Record<
+export type LocationQueryRaw = Record<
   string | number,
-  RawHistoryQueryValue | RawHistoryQueryValue[]
+  LocationQueryValueRaw | LocationQueryValueRaw[]
 >
 
 /**
@@ -17,8 +17,8 @@ export type RawHistoryQuery = Record<
  * @param search
  * @returns a query object
  */
-export function parseQuery(search: string): HistoryQuery {
-  const query: HistoryQuery = {}
+export function parseQuery(search: string): LocationQuery {
+  const query: LocationQuery = {}
   // avoid creating an object with an empty key and empty value
   // because of split('&')
   if (search === '' || search === '?') return query
@@ -50,7 +50,7 @@ export function parseQuery(search: string): HistoryQuery {
  * Stringify an object query. Works like URLSearchParams. Doesn't prepend a `?`
  * @param query
  */
-export function stringifyQuery(query: RawHistoryQuery): string {
+export function stringifyQuery(query: LocationQueryRaw): string {
   let search = ''
   for (let key in query) {
     if (search.length) search += '&'
@@ -62,7 +62,7 @@ export function stringifyQuery(query: RawHistoryQuery): string {
       continue
     }
     // keep null values
-    let values: RawHistoryQueryValue[] = Array.isArray(value)
+    let values: LocationQueryValueRaw[] = Array.isArray(value)
       ? value.map(v => v && encodeQueryProperty(v))
       : [value && encodeQueryProperty(value)]
 
@@ -82,8 +82,8 @@ export function stringifyQuery(query: RawHistoryQuery): string {
  * null in arrays
  * @param query
  */
-export function normalizeQuery(query: RawHistoryQuery): HistoryQuery {
-  const normalizedQuery: HistoryQuery = {}
+export function normalizeQuery(query: LocationQueryRaw): LocationQuery {
+  const normalizedQuery: LocationQuery = {}
 
   for (let key in query) {
     let value = query[key]