From 7dbebb6e2d75ab4aa77019712f2ed251ad62464f Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 26 Feb 2020 11:13:11 +0100 Subject: [PATCH] refactor: rename createHistory and createHashHistory BREAKING CHANGE: `createHistory` is now named `createWebHistory`. `createHashHistory` is now named `createWebHashHistory`. Both createHistory and createHashHistory are renamed to better reflect that they must be used in a browser environment while createMemoryHistory doesn't. --- __tests__/guards/component-beforeRouteEnter.spec.ts | 4 ++-- __tests__/guards/component-beforeRouteLeave.spec.ts | 4 ++-- __tests__/guards/component-beforeRouteUpdate.spec.ts | 4 ++-- __tests__/guards/global-after.spec.ts | 4 ++-- __tests__/guards/global-beforeEach.spec.ts | 4 ++-- __tests__/guards/route-beforeEnter.spec.ts | 4 ++-- __tests__/history/html5.spec.ts | 4 ++-- __tests__/router.spec.ts | 4 ++-- __tests__/url-encoding.spec.ts | 4 ++-- playground/router.ts | 4 ++-- src/history/hash.ts | 6 +++--- src/history/html5.ts | 2 +- src/index.ts | 6 +++--- 13 files changed, 27 insertions(+), 27 deletions(-) diff --git a/__tests__/guards/component-beforeRouteEnter.spec.ts b/__tests__/guards/component-beforeRouteEnter.spec.ts index 616ce99e..cf129633 100644 --- a/__tests__/guards/component-beforeRouteEnter.spec.ts +++ b/__tests__/guards/component-beforeRouteEnter.spec.ts @@ -2,13 +2,13 @@ import { RouterOptions, createRouter as newRouter } from '../../src/router' import fakePromise from 'faked-promise' import { NAVIGATION_TYPES, createDom, noGuard } from '../utils' import { RouteRecord, NavigationGuard } from '../../src/types' -import { createHistory } from '../../src' +import { createWebHistory } from '../../src' function createRouter( options: Partial & { routes: RouteRecord[] } ) { return newRouter({ - history: createHistory(), + history: createWebHistory(), ...options, }) } diff --git a/__tests__/guards/component-beforeRouteLeave.spec.ts b/__tests__/guards/component-beforeRouteLeave.spec.ts index 4777418d..c008f7e4 100644 --- a/__tests__/guards/component-beforeRouteLeave.spec.ts +++ b/__tests__/guards/component-beforeRouteLeave.spec.ts @@ -1,14 +1,14 @@ import { RouterOptions, createRouter as newRouter } from '../../src/router' import { NAVIGATION_TYPES, createDom, noGuard } from '../utils' import { RouteRecord } from '../../src/types' -import { createHistory } from '../../src' +import { createWebHistory } from '../../src' // TODO: refactor in utils function createRouter( options: Partial & { routes: RouteRecord[] } ) { return newRouter({ - history: createHistory(), + history: createWebHistory(), ...options, }) } diff --git a/__tests__/guards/component-beforeRouteUpdate.spec.ts b/__tests__/guards/component-beforeRouteUpdate.spec.ts index a6c89a00..6ffc1ba9 100644 --- a/__tests__/guards/component-beforeRouteUpdate.spec.ts +++ b/__tests__/guards/component-beforeRouteUpdate.spec.ts @@ -1,6 +1,6 @@ import fakePromise from 'faked-promise' import { NAVIGATION_TYPES, createDom, noGuard } from '../utils' -import { createRouter as newRouter, createHistory } from '../../src' +import { createRouter as newRouter, createWebHistory } from '../../src' import { RouteRecord } from '../../src/types' function createRouter( @@ -9,7 +9,7 @@ function createRouter( } ) { return newRouter({ - history: createHistory(), + history: createWebHistory(), ...options, }) } diff --git a/__tests__/guards/global-after.spec.ts b/__tests__/guards/global-after.spec.ts index e98dde1d..3b6a2039 100644 --- a/__tests__/guards/global-after.spec.ts +++ b/__tests__/guards/global-after.spec.ts @@ -1,5 +1,5 @@ import { NAVIGATION_TYPES, createDom } from '../utils' -import { createHistory, createRouter as newRouter } from '../../src' +import { createWebHistory, createRouter as newRouter } from '../../src' function createRouter( options: Partial & { @@ -7,7 +7,7 @@ function createRouter( } ) { return newRouter({ - history: createHistory(), + history: createWebHistory(), ...options, }) } diff --git a/__tests__/guards/global-beforeEach.spec.ts b/__tests__/guards/global-beforeEach.spec.ts index f5d8e5ae..58df9ed3 100644 --- a/__tests__/guards/global-beforeEach.spec.ts +++ b/__tests__/guards/global-beforeEach.spec.ts @@ -2,13 +2,13 @@ import { RouterOptions } from '../../src/router' import fakePromise from 'faked-promise' import { NAVIGATION_TYPES, createDom, tick, noGuard } from '../utils' import { RouteRecord, RouteLocation } from '../../src/types' -import { createHistory, createRouter as newRouter } from '../../src' +import { createWebHistory, createRouter as newRouter } from '../../src' function createRouter( options: Partial & { routes: RouteRecord[] } ) { return newRouter({ - history: createHistory(), + history: createWebHistory(), ...options, }) } diff --git a/__tests__/guards/route-beforeEnter.spec.ts b/__tests__/guards/route-beforeEnter.spec.ts index 6849daa1..58ed8918 100644 --- a/__tests__/guards/route-beforeEnter.spec.ts +++ b/__tests__/guards/route-beforeEnter.spec.ts @@ -2,13 +2,13 @@ import { RouterOptions, createRouter as newRouter } from '../../src/router' import fakePromise from 'faked-promise' import { NAVIGATION_TYPES, createDom, noGuard, tick } from '../utils' import { RouteRecord } from '../../src/types' -import { createHistory } from '../../src' +import { createWebHistory } from '../../src' function createRouter( options: Partial & { routes: RouteRecord[] } ) { return newRouter({ - history: createHistory(), + history: createWebHistory(), ...options, }) } diff --git a/__tests__/history/html5.spec.ts b/__tests__/history/html5.spec.ts index 7e1e1ca3..641b99b0 100644 --- a/__tests__/history/html5.spec.ts +++ b/__tests__/history/html5.spec.ts @@ -1,4 +1,4 @@ -import createHistory from '../../src/history/html5' +import createWebHistory from '../../src/history/html5' import { createDom } from '../utils' // TODO: is it really worth testing this implementation on jest or is it @@ -9,7 +9,7 @@ describe.skip('History HTMl5', () => { }) it('can be instantiated', () => { - const history = createHistory() + const history = createWebHistory() expect(history.location).toEqual({ fullPath: '/', path: '/', diff --git a/__tests__/router.spec.ts b/__tests__/router.spec.ts index c8a896c4..77f1d010 100644 --- a/__tests__/router.spec.ts +++ b/__tests__/router.spec.ts @@ -1,5 +1,5 @@ import fakePromise from 'faked-promise' -import { createRouter, createMemoryHistory, createHistory } from '../src' +import { createRouter, createMemoryHistory, createWebHistory } from '../src' import { NavigationCancelled } from '../src/errors' import { createDom, components, tick } from './utils' import { @@ -310,7 +310,7 @@ describe('Router', () => { }) it('allows base option with html5 history', async () => { - const history = createHistory('/app/') + const history = createWebHistory('/app/') const router = createRouter({ history, routes }) expect(router.currentRoute.value).toEqual({ name: undefined, diff --git a/__tests__/url-encoding.spec.ts b/__tests__/url-encoding.spec.ts index d54c1c5d..c03f89ef 100644 --- a/__tests__/url-encoding.spec.ts +++ b/__tests__/url-encoding.spec.ts @@ -16,13 +16,13 @@ const routes: RouteRecord[] = [ // this function is meant to easy refactor in the future as Histories are going to be // function-based -function createHistory() { +function createWebHistory() { const routerHistory = createMemoryHistory() return routerHistory } function createRouter() { - const history = createHistory() + const history = createWebHistory() const router = newRouter({ history, routes }) return router } diff --git a/playground/router.ts b/playground/router.ts index ef8be6de..116a70e1 100644 --- a/playground/router.ts +++ b/playground/router.ts @@ -1,4 +1,4 @@ -import { createRouter, createHistory } from '../src' +import { createRouter, createWebHistory } from '../src' import Home from './views/Home.vue' import Nested from './views/Nested.vue' import User from './views/User.vue' @@ -12,7 +12,7 @@ import { scrollWaiter } from './scrollWaiter' // const hist = new HTML5History() // const hist = new HashHistory() -export const routerHistory = createHistory() +export const routerHistory = createWebHistory() export const router = createRouter({ history: routerHistory, routes: [ diff --git a/src/history/hash.ts b/src/history/hash.ts index 1c8ac40a..08a6cae0 100644 --- a/src/history/hash.ts +++ b/src/history/hash.ts @@ -1,7 +1,7 @@ import { RouterHistory } from './common' -import createHistory from './html5' +import createWebHistory from './html5' -export default function createHashHistory(base: string = ''): RouterHistory { +export default function createWebHashHistory(base: string = ''): RouterHistory { // Make sure this implementation is fine in terms of encoding, specially for IE11 - return createHistory('/#' + base) + return createWebHistory('/#' + base) } diff --git a/src/history/html5.ts b/src/history/html5.ts index d80e8c12..463005ee 100644 --- a/src/history/html5.ts +++ b/src/history/html5.ts @@ -264,7 +264,7 @@ function useHistoryStateNavigation(base: string) { } } -export default function createHistory(base: string = ''): RouterHistory { +export default function createWebHistory(base: string = ''): RouterHistory { const historyNavigation = useHistoryStateNavigation(base) const historyListeners = useHistoryListeners( base, diff --git a/src/index.ts b/src/index.ts index 719b341a..e5058595 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ -import createHistory from './history/html5' +import createWebHistory from './history/html5' import createMemoryHistory from './history/memory' -import createHashHistory from './history/hash' +import createWebHashHistory from './history/hash' export { RouteLocationNormalized, @@ -15,4 +15,4 @@ export { useRoute, useRouter } from './injectKeys' export { Link } from './components/Link' export { View } from './components/View' -export { createHistory, createMemoryHistory, createHashHistory } +export { createWebHistory, createMemoryHistory, createWebHashHistory } -- 2.39.5