From 5f9ae0dd47f6297b6d42c195a9af07ecf5672825 Mon Sep 17 00:00:00 2001 From: MICHAEL JACKSON Date: Mon, 20 Nov 2017 15:19:33 -0800 Subject: [PATCH 1/2] Remove support for legacy attachEvent API --- modules/DOMUtils.js | 10 ---------- modules/createBrowserHistory.js | 12 +++++------- modules/createHashHistory.js | 6 ++---- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/modules/DOMUtils.js b/modules/DOMUtils.js index 21140edfc..e640e1004 100644 --- a/modules/DOMUtils.js +++ b/modules/DOMUtils.js @@ -2,16 +2,6 @@ export const canUseDOM = !!( typeof window !== 'undefined' && window.document && window.document.createElement ) -export const addEventListener = (node, event, listener) => - node.addEventListener - ? node.addEventListener(event, listener, false) - : node.attachEvent('on' + event, listener) - -export const removeEventListener = (node, event, listener) => - node.removeEventListener - ? node.removeEventListener(event, listener, false) - : node.detachEvent('on' + event, listener) - export const getConfirmation = (message, callback) => callback(window.confirm(message)) // eslint-disable-line no-alert diff --git a/modules/createBrowserHistory.js b/modules/createBrowserHistory.js index 596035418..a79588af5 100644 --- a/modules/createBrowserHistory.js +++ b/modules/createBrowserHistory.js @@ -11,8 +11,6 @@ import { import createTransitionManager from './createTransitionManager' import { canUseDOM, - addEventListener, - removeEventListener, getConfirmation, supportsHistory, supportsPopStateOnHashChange, @@ -90,7 +88,7 @@ const createBrowserHistory = (props = {}) => { const handlePopState = (event) => { // Ignore extraneous popstate events in WebKit. if (isExtraneousPopstateEvent(event)) - return + return handlePop(getDOMLocation(event.state)) } @@ -250,15 +248,15 @@ const createBrowserHistory = (props = {}) => { listenerCount += delta if (listenerCount === 1) { - addEventListener(window, PopStateEvent, handlePopState) + window.addEventListener(PopStateEvent, handlePopState) if (needsHashChangeListener) - addEventListener(window, HashChangeEvent, handleHashChange) + window.addEventListener(HashChangeEvent, handleHashChange) } else if (listenerCount === 0) { - removeEventListener(window, PopStateEvent, handlePopState) + window.removeEventListener(PopStateEvent, handlePopState) if (needsHashChangeListener) - removeEventListener(window, HashChangeEvent, handleHashChange) + window.removeEventListener(HashChangeEvent, handleHashChange) } } diff --git a/modules/createHashHistory.js b/modules/createHashHistory.js index fb180e0e1..49b46e559 100644 --- a/modules/createHashHistory.js +++ b/modules/createHashHistory.js @@ -12,8 +12,6 @@ import { import createTransitionManager from './createTransitionManager' import { canUseDOM, - addEventListener, - removeEventListener, getConfirmation, supportsGoWithoutReloadUsingHash } from './DOMUtils' @@ -279,9 +277,9 @@ const createHashHistory = (props = {}) => { listenerCount += delta if (listenerCount === 1) { - addEventListener(window, HashChangeEvent, handleHashChange) + window.addEventListener(HashChangeEvent, handleHashChange) } else if (listenerCount === 0) { - removeEventListener(window, HashChangeEvent, handleHashChange) + window.removeEventListener(HashChangeEvent, handleHashChange) } } From dca21eaa9230ae187c72ef657f70aac97cb172aa Mon Sep 17 00:00:00 2001 From: MICHAEL JACKSON Date: Mon, 20 Nov 2017 15:22:23 -0800 Subject: [PATCH 2/2] Use Prettier --- modules/DOMUtils.js | 22 +- modules/LocationUtils.js | 40 +-- modules/PathUtils.js | 44 ++- modules/__tests__/BrowserHistory-test.js | 168 ++++++------ modules/__tests__/HashHistory-test.js | 180 ++++++------ modules/__tests__/LocationUtils-test.js | 183 +++++++------ modules/__tests__/MemoryHistory-test.js | 108 ++++---- .../TestSequences/BackButtonTransitionHook.js | 21 +- .../TestSequences/BlockEverything.js | 12 +- .../TestSequences/BlockPopWithoutListening.js | 6 +- modules/__tests__/TestSequences/DenyGoBack.js | 22 +- .../__tests__/TestSequences/DenyGoForward.js | 26 +- modules/__tests__/TestSequences/DenyPush.js | 16 +- .../EncodedReservedCharacters.js | 27 +- modules/__tests__/TestSequences/GoBack.js | 18 +- modules/__tests__/TestSequences/GoForward.js | 22 +- .../TestSequences/HashChangeTransitionHook.js | 19 +- .../TestSequences/HashbangHashPathCoding.js | 38 +-- .../TestSequences/InitialLocationHasKey.js | 6 +- .../TestSequences/InitialLocationNoKey.js | 6 +- modules/__tests__/TestSequences/Listen.js | 4 +- .../LocationPathnameAlwaysDecoded.js | 31 +-- .../TestSequences/NoslashHashPathCoding.js | 34 +-- .../TestSequences/PushEncodedLocation.js | 22 +- .../TestSequences/PushInvalidPathname.js | 6 +- .../TestSequences/PushMissingPathname.js | 28 +- .../TestSequences/PushNewLocation.js | 18 +- .../TestSequences/PushRelativePathname.js | 28 +- .../__tests__/TestSequences/PushSamePath.js | 24 +- .../TestSequences/PushSamePathWarning.js | 27 +- modules/__tests__/TestSequences/PushState.js | 20 +- .../TestSequences/PushStateWarning.js | 21 +- .../TestSequences/PushUnicodeLocation.js | 22 +- .../TestSequences/ReplaceInvalidPathname.js | 6 +- .../TestSequences/ReplaceNewLocation.js | 18 +- .../TestSequences/ReplaceSamePath.js | 20 +- .../__tests__/TestSequences/ReplaceState.js | 20 +- .../TestSequences/ReplaceStateWarning.js | 21 +- .../ReturnFalseTransitionHook.js | 14 +- .../TestSequences/SlashHashPathCoding.js | 38 +-- .../TestSequences/TransitionHookArgs.js | 12 +- modules/__tests__/TestSequences/execSteps.js | 10 +- modules/__tests__/TestSequences/index.js | 68 ++--- modules/__tests__/createHref-test.js | 186 ++++++------- modules/createBrowserHistory.js | 238 ++++++++-------- modules/createHashHistory.js | 256 +++++++++--------- modules/createMemoryHistory.js | 167 +++++++----- modules/createTransitionManager.js | 33 +-- modules/index.js | 10 +- package.json | 5 +- 50 files changed, 1237 insertions(+), 1154 deletions(-) diff --git a/modules/DOMUtils.js b/modules/DOMUtils.js index e640e1004..c331865be 100644 --- a/modules/DOMUtils.js +++ b/modules/DOMUtils.js @@ -1,5 +1,7 @@ export const canUseDOM = !!( - typeof window !== 'undefined' && window.document && window.document.createElement + typeof window !== "undefined" && + window.document && + window.document.createElement ) export const getConfirmation = (message, callback) => @@ -15,14 +17,15 @@ export const getConfirmation = (message, callback) => export const supportsHistory = () => { const ua = window.navigator.userAgent - if ((ua.indexOf('Android 2.') !== -1 || ua.indexOf('Android 4.0') !== -1) && - ua.indexOf('Mobile Safari') !== -1 && - ua.indexOf('Chrome') === -1 && - ua.indexOf('Windows Phone') === -1 + if ( + (ua.indexOf("Android 2.") !== -1 || ua.indexOf("Android 4.0") !== -1) && + ua.indexOf("Mobile Safari") !== -1 && + ua.indexOf("Chrome") === -1 && + ua.indexOf("Windows Phone") === -1 ) return false - return window.history && 'pushState' in window.history + return window.history && "pushState" in window.history } /** @@ -30,13 +33,13 @@ export const supportsHistory = () => { * IE10 and IE11 do not. */ export const supportsPopStateOnHashChange = () => - window.navigator.userAgent.indexOf('Trident') === -1 + window.navigator.userAgent.indexOf("Trident") === -1 /** * Returns false if using go(n) with hash history causes a full page reload. */ export const supportsGoWithoutReloadUsingHash = () => - window.navigator.userAgent.indexOf('Firefox') === -1 + window.navigator.userAgent.indexOf("Firefox") === -1 /** * Returns true if a given popstate event is an extraneous WebKit event. @@ -44,5 +47,4 @@ export const supportsGoWithoutReloadUsingHash = () => * containing undefined state when pressing the back button. */ export const isExtraneousPopstateEvent = event => - event.state === undefined && - navigator.userAgent.indexOf('CriOS') === -1 + event.state === undefined && navigator.userAgent.indexOf("CriOS") === -1 diff --git a/modules/LocationUtils.js b/modules/LocationUtils.js index 25aceb584..bc3d50c85 100644 --- a/modules/LocationUtils.js +++ b/modules/LocationUtils.js @@ -1,10 +1,10 @@ -import resolvePathname from 'resolve-pathname' -import valueEqual from 'value-equal' -import { parsePath } from './PathUtils' +import resolvePathname from "resolve-pathname" +import valueEqual from "value-equal" +import { parsePath } from "./PathUtils" export const createLocation = (path, state, key, currentLocation) => { let location - if (typeof path === 'string') { + if (typeof path === "string") { // Two-arg form: push(path, state) location = parsePath(path) location.state = state @@ -12,21 +12,19 @@ export const createLocation = (path, state, key, currentLocation) => { // One-arg form: push(location) location = { ...path } - if (location.pathname === undefined) - location.pathname = '' + if (location.pathname === undefined) location.pathname = "" if (location.search) { - if (location.search.charAt(0) !== '?') - location.search = '?' + location.search + if (location.search.charAt(0) !== "?") + location.search = "?" + location.search } else { - location.search = '' + location.search = "" } if (location.hash) { - if (location.hash.charAt(0) !== '#') - location.hash = '#' + location.hash + if (location.hash.charAt(0) !== "#") location.hash = "#" + location.hash } else { - location.hash = '' + location.hash = "" } if (state !== undefined && location.state === undefined) @@ -38,28 +36,32 @@ export const createLocation = (path, state, key, currentLocation) => { } catch (e) { if (e instanceof URIError) { throw new URIError( - 'Pathname "' + location.pathname + '" could not be decoded. ' + - 'This is likely caused by an invalid percent-encoding.' + 'Pathname "' + + location.pathname + + '" could not be decoded. ' + + "This is likely caused by an invalid percent-encoding." ) } else { throw e } } - if (key) - location.key = key + if (key) location.key = key if (currentLocation) { // Resolve incomplete/relative pathname relative to current location. if (!location.pathname) { location.pathname = currentLocation.pathname - } else if (location.pathname.charAt(0) !== '/') { - location.pathname = resolvePathname(location.pathname, currentLocation.pathname) + } else if (location.pathname.charAt(0) !== "/") { + location.pathname = resolvePathname( + location.pathname, + currentLocation.pathname + ) } } else { // When there is no prior location and pathname is empty, set it to / if (!location.pathname) { - location.pathname = '/' + location.pathname = "/" } } diff --git a/modules/PathUtils.js b/modules/PathUtils.js index fc2d69855..c2b9a8a93 100644 --- a/modules/PathUtils.js +++ b/modules/PathUtils.js @@ -1,30 +1,30 @@ -export const addLeadingSlash = (path) => - path.charAt(0) === '/' ? path : '/' + path +export const addLeadingSlash = path => + path.charAt(0) === "/" ? path : "/" + path -export const stripLeadingSlash = (path) => - path.charAt(0) === '/' ? path.substr(1) : path +export const stripLeadingSlash = path => + path.charAt(0) === "/" ? path.substr(1) : path -export const hasBasename = (path, prefix) => - (new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i')).test(path) +export const hasBasename = (path, prefix) => + new RegExp("^" + prefix + "(\\/|\\?|#|$)", "i").test(path) export const stripBasename = (path, prefix) => hasBasename(path, prefix) ? path.substr(prefix.length) : path -export const stripTrailingSlash = (path) => - path.charAt(path.length - 1) === '/' ? path.slice(0, -1) : path +export const stripTrailingSlash = path => + path.charAt(path.length - 1) === "/" ? path.slice(0, -1) : path -export const parsePath = (path) => { - let pathname = path || '/' - let search = '' - let hash = '' +export const parsePath = path => { + let pathname = path || "/" + let search = "" + let hash = "" - const hashIndex = pathname.indexOf('#') + const hashIndex = pathname.indexOf("#") if (hashIndex !== -1) { hash = pathname.substr(hashIndex) pathname = pathname.substr(0, hashIndex) } - const searchIndex = pathname.indexOf('?') + const searchIndex = pathname.indexOf("?") if (searchIndex !== -1) { search = pathname.substr(searchIndex) pathname = pathname.substr(0, searchIndex) @@ -32,22 +32,20 @@ export const parsePath = (path) => { return { pathname, - search: search === '?' ? '' : search, - hash: hash === '#' ? '' : hash + search: search === "?" ? "" : search, + hash: hash === "#" ? "" : hash } } -export const createPath = (location) => { +export const createPath = location => { const { pathname, search, hash } = location - let path = pathname || '/' + let path = pathname || "/" - if (search && search !== '?') - path += (search.charAt(0) === '?' ? search : `?${search}`) - - if (hash && hash !== '#') - path += (hash.charAt(0) === '#' ? hash : `#${hash}`) + if (search && search !== "?") + path += search.charAt(0) === "?" ? search : `?${search}` + if (hash && hash !== "#") path += hash.charAt(0) === "#" ? hash : `#${hash}` return path } diff --git a/modules/__tests__/BrowserHistory-test.js b/modules/__tests__/BrowserHistory-test.js index 7fb2c063a..3b6e20ca5 100644 --- a/modules/__tests__/BrowserHistory-test.js +++ b/modules/__tests__/BrowserHistory-test.js @@ -1,144 +1,144 @@ -import expect from 'expect' -import createHistory from '../createBrowserHistory' -import { canUseDOM, supportsHistory } from '../DOMUtils' -import * as TestSequences from './TestSequences' +import expect from "expect" +import createHistory from "../createBrowserHistory" +import { canUseDOM, supportsHistory } from "../DOMUtils" +import * as TestSequences from "./TestSequences" const canUseHistory = canUseDOM && supportsHistory() const describeHistory = canUseHistory ? describe : describe.skip -describeHistory('a browser history', () => { +describeHistory("a browser history", () => { beforeEach(() => { - window.history.replaceState(null, null, '/') + window.history.replaceState(null, null, "/") }) - describe('by default', () => { + describe("by default", () => { let history beforeEach(() => { history = createHistory() }) - describe('listen', () => { - it('does not immediately call listeners', (done) => { + describe("listen", () => { + it("does not immediately call listeners", done => { TestSequences.Listen(history, done) }) }) - describe('the initial location', () => { - it('does not have a key', (done) => { + describe("the initial location", () => { + it("does not have a key", done => { TestSequences.InitialLocationNoKey(history, done) }) }) - describe('push a new path', () => { - it('calls change listeners with the new location', (done) => { + describe("push a new path", () => { + it("calls change listeners with the new location", done => { TestSequences.PushNewLocation(history, done) }) }) - describe('push the same path', () => { - it('calls change listeners with the new location', (done) => { + describe("push the same path", () => { + it("calls change listeners with the new location", done => { TestSequences.PushSamePath(history, done) }) }) - describe('push state', () => { - it('calls change listeners with the new location', (done) => { + describe("push state", () => { + it("calls change listeners with the new location", done => { TestSequences.PushState(history, done) }) }) - describe('push with no pathname', () => { - it('calls change listeners with the normalized location', (done) => { + describe("push with no pathname", () => { + it("calls change listeners with the normalized location", done => { TestSequences.PushMissingPathname(history, done) }) }) - describe('push with a relative pathname', () => { - it('calls change listeners with the normalized location', (done) => { + describe("push with a relative pathname", () => { + it("calls change listeners with the normalized location", done => { TestSequences.PushRelativePathname(history, done) }) }) - describe('push with a unicode path string', () => { - it('creates a location with decoded properties', (done) => { + describe("push with a unicode path string", () => { + it("creates a location with decoded properties", done => { TestSequences.PushUnicodeLocation(history, done) }) }) - describe('push with an encoded path string', () => { - it('creates a location object with decoded pathname', (done) => { + describe("push with an encoded path string", () => { + it("creates a location object with decoded pathname", done => { TestSequences.PushEncodedLocation(history, done) }) }) - describe('push with an invalid path string (bad percent-encoding)', () => { - it('throws an error', (done) => { + describe("push with an invalid path string (bad percent-encoding)", () => { + it("throws an error", done => { TestSequences.PushInvalidPathname(history, done) }) }) - describe('replace a new path', () => { - it('calls change listeners with the new location', (done) => { + describe("replace a new path", () => { + it("calls change listeners with the new location", done => { TestSequences.ReplaceNewLocation(history, done) }) }) - describe('replace the same path', () => { - it('calls change listeners with the new location', (done) => { + describe("replace the same path", () => { + it("calls change listeners with the new location", done => { TestSequences.ReplaceSamePath(history, done) }) }) - describe('replace state', () => { - it('calls change listeners with the new location', (done) => { + describe("replace state", () => { + it("calls change listeners with the new location", done => { TestSequences.ReplaceState(history, done) }) }) - describe('replace with an invalid path string (bad percent-encoding)', () => { - it('throws an error', (done) => { + describe("replace with an invalid path string (bad percent-encoding)", () => { + it("throws an error", done => { TestSequences.ReplaceInvalidPathname(history, done) }) }) - describe('location created by encoded and unencoded pathname', () => { - it('produces the same location.pathname', (done) => { + describe("location created by encoded and unencoded pathname", () => { + it("produces the same location.pathname", done => { TestSequences.LocationPathnameAlwaysDecoded(history, done) }) }) - describe('location created with encoded/unencoded reserved characters', () => { - it('produces different location objects', (done) => { + describe("location created with encoded/unencoded reserved characters", () => { + it("produces different location objects", done => { TestSequences.EncodedReservedCharacters(history, done) }) }) - describe('goBack', () => { - it('calls change listeners with the previous location', (done) => { + describe("goBack", () => { + it("calls change listeners with the previous location", done => { TestSequences.GoBack(history, done) }) }) - describe('goForward', () => { - it('calls change listeners with the next location', (done) => { + describe("goForward", () => { + it("calls change listeners with the next location", done => { TestSequences.GoForward(history, done) }) }) - describe('block', () => { - it('blocks all transitions', (done) => { + describe("block", () => { + it("blocks all transitions", done => { TestSequences.BlockEverything(history, done) }) }) - describe('block a POP without listening', () => { - it('receives the next location and action as arguments', (done) => { + describe("block a POP without listening", () => { + it("receives the next location and action as arguments", done => { TestSequences.BlockPopWithoutListening(history, done) }) }) }) - describe('that denies all transitions', () => { + describe("that denies all transitions", () => { const getUserConfirmation = (_, callback) => callback(false) let history @@ -148,26 +148,26 @@ describeHistory('a browser history', () => { }) }) - describe('clicking on a link (push)', () => { - it('does not update the location', (done) => { + describe("clicking on a link (push)", () => { + it("does not update the location", done => { TestSequences.DenyPush(history, done) }) }) - describe('clicking the back button (goBack)', () => { - it('does not update the location', (done) => { + describe("clicking the back button (goBack)", () => { + it("does not update the location", done => { TestSequences.DenyGoBack(history, done) }) }) - describe('clicking the forward button (goForward)', () => { - it('does not update the location', (done) => { + describe("clicking the forward button (goForward)", () => { + it("does not update the location", done => { TestSequences.DenyGoForward(history, done) }) }) }) - describe('a transition hook', () => { + describe("a transition hook", () => { const getUserConfirmation = (_, callback) => callback(true) let history @@ -177,58 +177,58 @@ describeHistory('a browser history', () => { }) }) - it('receives the next location and action as arguments', (done) => { + it("receives the next location and action as arguments", done => { TestSequences.TransitionHookArgs(history, done) }) - it('cancels the transition when it returns false', (done) => { + it("cancels the transition when it returns false", done => { TestSequences.ReturnFalseTransitionHook(history, done) }) - it('is called when the back button is clicked', (done) => { + it("is called when the back button is clicked", done => { TestSequences.BackButtonTransitionHook(history, done) }) - it('is called on the hashchange event', (done) => { + it("is called on the hashchange event", done => { TestSequences.HashChangeTransitionHook(history, done) }) }) - describe('basename', () => { - it('strips the basename from the pathname', () => { - window.history.replaceState(null, null, '/prefix/pathname') - const history = createHistory({ basename: '/prefix' }) - expect(history.location.pathname).toEqual('/pathname') + describe("basename", () => { + it("strips the basename from the pathname", () => { + window.history.replaceState(null, null, "/prefix/pathname") + const history = createHistory({ basename: "/prefix" }) + expect(history.location.pathname).toEqual("/pathname") }) - it('is not case-sensitive', () => { - window.history.replaceState(null, null, '/PREFIX/pathname') - const history = createHistory({ basename: '/prefix' }) - expect(history.location.pathname).toEqual('/pathname') + it("is not case-sensitive", () => { + window.history.replaceState(null, null, "/PREFIX/pathname") + const history = createHistory({ basename: "/prefix" }) + expect(history.location.pathname).toEqual("/pathname") }) - it('does not strip partial prefix matches', () => { - window.history.replaceState(null, null, '/prefixed/pathname') - const history = createHistory({ basename: '/prefix' }) - expect(history.location.pathname).toEqual('/prefixed/pathname') + it("does not strip partial prefix matches", () => { + window.history.replaceState(null, null, "/prefixed/pathname") + const history = createHistory({ basename: "/prefix" }) + expect(history.location.pathname).toEqual("/prefixed/pathname") }) - it('strips when path is only the prefix', () => { - window.history.replaceState(null, null, '/prefix') - const history = createHistory({ basename: '/prefix' }) - expect(history.location.pathname).toEqual('/') + it("strips when path is only the prefix", () => { + window.history.replaceState(null, null, "/prefix") + const history = createHistory({ basename: "/prefix" }) + expect(history.location.pathname).toEqual("/") }) - it('strips with no pathname, but with a search string', () => { - window.history.replaceState(null, null, '/prefix?a=b') - const history = createHistory({ basename: '/prefix' }) - expect(history.location.pathname).toEqual('/') + it("strips with no pathname, but with a search string", () => { + window.history.replaceState(null, null, "/prefix?a=b") + const history = createHistory({ basename: "/prefix" }) + expect(history.location.pathname).toEqual("/") }) - it('strips with no pathname, but with a hash string', () => { - window.history.replaceState(null, null, '/prefix#rest') - const history = createHistory({ basename: '/prefix' }) - expect(history.location.pathname).toEqual('/') + it("strips with no pathname, but with a hash string", () => { + window.history.replaceState(null, null, "/prefix#rest") + const history = createHistory({ basename: "/prefix" }) + expect(history.location.pathname).toEqual("/") }) }) }) diff --git a/modules/__tests__/HashHistory-test.js b/modules/__tests__/HashHistory-test.js index 7ca0d323f..70f30ee01 100644 --- a/modules/__tests__/HashHistory-test.js +++ b/modules/__tests__/HashHistory-test.js @@ -1,147 +1,146 @@ -import expect from 'expect' -import createHistory from '../createHashHistory' -import { canUseDOM, supportsGoWithoutReloadUsingHash } from '../DOMUtils' -import * as TestSequences from './TestSequences' +import expect from "expect" +import createHistory from "../createHashHistory" +import { canUseDOM, supportsGoWithoutReloadUsingHash } from "../DOMUtils" +import * as TestSequences from "./TestSequences" const describeHistory = canUseDOM ? describe : describe.skip const canGoWithoutReload = canUseDOM && supportsGoWithoutReloadUsingHash() const describeGo = canGoWithoutReload ? describe : describe.skip -describeHistory('a hash history', () => { +describeHistory("a hash history", () => { beforeEach(() => { - if (window.location.hash !== '') - window.location.hash = '' + if (window.location.hash !== "") window.location.hash = "" }) - describe('by default', () => { + describe("by default", () => { let history beforeEach(() => { history = createHistory() }) - describe('listen', () => { - it('does not immediately call listeners', (done) => { + describe("listen", () => { + it("does not immediately call listeners", done => { TestSequences.Listen(history, done) }) }) - describe('the initial location', () => { - it('does not have a key', (done) => { + describe("the initial location", () => { + it("does not have a key", done => { TestSequences.InitialLocationNoKey(history, done) }) }) - describe('push a new path', () => { - it('calls change listeners with the new location', (done) => { + describe("push a new path", () => { + it("calls change listeners with the new location", done => { TestSequences.PushNewLocation(history, done) }) }) - describe('push the same path', () => { - it('calls change listeners with the same location and emits a warning', (done) => { + describe("push the same path", () => { + it("calls change listeners with the same location and emits a warning", done => { TestSequences.PushSamePathWarning(history, done) }) }) - describe('push state', () => { - it('calls change listeners with the new location and emits a warning', (done) => { + describe("push state", () => { + it("calls change listeners with the new location and emits a warning", done => { TestSequences.PushStateWarning(history, done) }) }) - describe('push with no pathname', () => { - it('calls change listeners with the normalized location', (done) => { + describe("push with no pathname", () => { + it("calls change listeners with the normalized location", done => { TestSequences.PushMissingPathname(history, done) }) }) - describe('push with a relative pathname', () => { - it('calls change listeners with the normalized location', (done) => { + describe("push with a relative pathname", () => { + it("calls change listeners with the normalized location", done => { TestSequences.PushRelativePathname(history, done) }) }) - describe('push with a unicode path string', () => { - it('creates a location with decoded properties', (done) => { + describe("push with a unicode path string", () => { + it("creates a location with decoded properties", done => { TestSequences.PushUnicodeLocation(history, done) }) }) - describe('push with an encoded path string', () => { - it('creates a location object with decoded pathname', (done) => { + describe("push with an encoded path string", () => { + it("creates a location object with decoded pathname", done => { TestSequences.PushEncodedLocation(history, done) }) }) - describe('push with an invalid path string (bad percent-encoding)', () => { - it('throws an error', (done) => { + describe("push with an invalid path string (bad percent-encoding)", () => { + it("throws an error", done => { TestSequences.PushInvalidPathname(history, done) }) }) - describe('replace a new path', () => { - it('calls change listeners with the new location', (done) => { + describe("replace a new path", () => { + it("calls change listeners with the new location", done => { TestSequences.ReplaceNewLocation(history, done) }) }) - describe('replace the same path', () => { - it('calls change listeners with the new location', (done) => { + describe("replace the same path", () => { + it("calls change listeners with the new location", done => { TestSequences.ReplaceSamePath(history, done) }) }) - describe('replace state', () => { - it('calls change listeners with the new location and emits a warning', (done) => { + describe("replace state", () => { + it("calls change listeners with the new location and emits a warning", done => { TestSequences.ReplaceStateWarning(history, done) }) }) - describe('replace with an invalid path string (bad percent-encoding)', () => { - it('throws an error', (done) => { + describe("replace with an invalid path string (bad percent-encoding)", () => { + it("throws an error", done => { TestSequences.ReplaceInvalidPathname(history, done) }) }) - describe('location created by encoded and unencoded pathname', () => { - it('produces the same location.pathname', (done) => { + describe("location created by encoded and unencoded pathname", () => { + it("produces the same location.pathname", done => { TestSequences.LocationPathnameAlwaysDecoded(history, done) }) }) - describe('location created with encoded/unencoded reserved characters', () => { - it('produces different location objects', (done) => { + describe("location created with encoded/unencoded reserved characters", () => { + it("produces different location objects", done => { TestSequences.EncodedReservedCharacters(history, done) }) }) - describeGo('goBack', () => { - it('calls change listeners with the previous location', (done) => { + describeGo("goBack", () => { + it("calls change listeners with the previous location", done => { TestSequences.GoBack(history, done) }) }) - describeGo('goForward', () => { - it('calls change listeners with the next location', (done) => { + describeGo("goForward", () => { + it("calls change listeners with the next location", done => { TestSequences.GoForward(history, done) }) }) - describe('block', () => { - it('blocks all transitions', (done) => { + describe("block", () => { + it("blocks all transitions", done => { TestSequences.BlockEverything(history, done) }) }) - describeGo('block a POP without listening', () => { - it('receives the next location and action as arguments', (done) => { + describeGo("block a POP without listening", () => { + it("receives the next location and action as arguments", done => { TestSequences.BlockPopWithoutListening(history, done) }) }) }) - describe('that denies all transitions', () => { + describe("that denies all transitions", () => { const getUserConfirmation = (_, callback) => callback(false) let history @@ -151,26 +150,26 @@ describeHistory('a hash history', () => { }) }) - describe('clicking on a link (push)', () => { - it('does not update the location', (done) => { + describe("clicking on a link (push)", () => { + it("does not update the location", done => { TestSequences.DenyPush(history, done) }) }) - describeGo('clicking the back button (goBack)', () => { - it('does not update the location', (done) => { + describeGo("clicking the back button (goBack)", () => { + it("does not update the location", done => { TestSequences.DenyGoBack(history, done) }) }) - describeGo('clicking the forward button (goForward)', () => { - it('does not update the location', (done) => { + describeGo("clicking the forward button (goForward)", () => { + it("does not update the location", done => { TestSequences.DenyGoForward(history, done) }) }) }) - describe('a transition hook', () => { + describe("a transition hook", () => { const getUserConfirmation = (_, callback) => callback(true) let history @@ -180,17 +179,17 @@ describeHistory('a hash history', () => { }) }) - it('receives the next location and action as arguments', (done) => { + it("receives the next location and action as arguments", done => { TestSequences.TransitionHookArgs(history, done) }) const itBackButton = canGoWithoutReload ? it : it.skip - itBackButton('is called when the back button is clicked', (done) => { + itBackButton("is called when the back button is clicked", done => { TestSequences.BackButtonTransitionHook(history, done) }) - it('cancels the transition when it returns false', (done) => { + it("cancels the transition when it returns false", done => { TestSequences.ReturnFalseTransitionHook(history, done) }) }) @@ -199,11 +198,11 @@ describeHistory('a hash history', () => { let history beforeEach(() => { history = createHistory({ - hashType: 'hashbang' + hashType: "hashbang" }) }) - it('properly encodes and decodes window.location.hash', (done) => { + it("properly encodes and decodes window.location.hash", done => { TestSequences.HashbangHashPathCoding(history, done) }) }) @@ -212,11 +211,11 @@ describeHistory('a hash history', () => { let history beforeEach(() => { history = createHistory({ - hashType: 'noslash' + hashType: "noslash" }) }) - it('properly encodes and decodes window.location.hash', (done) => { + it("properly encodes and decodes window.location.hash", done => { TestSequences.NoslashHashPathCoding(history, done) }) }) @@ -225,51 +224,50 @@ describeHistory('a hash history', () => { let history beforeEach(() => { history = createHistory({ - hashType: 'slash' + hashType: "slash" }) }) - it('properly encodes and decodes window.location.hash', (done) => { + it("properly encodes and decodes window.location.hash", done => { TestSequences.SlashHashPathCoding(history, done) }) }) - - describe('basename', () => { - it('strips the basename from the pathname', () => { - window.location.hash = '#/prefix/pathname' - const history = createHistory({ basename: '/prefix' }) - expect(history.location.pathname).toEqual('/pathname') + describe("basename", () => { + it("strips the basename from the pathname", () => { + window.location.hash = "#/prefix/pathname" + const history = createHistory({ basename: "/prefix" }) + expect(history.location.pathname).toEqual("/pathname") }) - it('is not case-sensitive', () => { - window.location.hash = '#/PREFIX/pathname' - const history = createHistory({ basename: '/prefix' }) - expect(history.location.pathname).toEqual('/pathname') + it("is not case-sensitive", () => { + window.location.hash = "#/PREFIX/pathname" + const history = createHistory({ basename: "/prefix" }) + expect(history.location.pathname).toEqual("/pathname") }) - it('does not strip partial prefix matches', () => { - window.location.hash = '#/prefixed/pathname' - const history = createHistory({ basename: '/prefix' }) - expect(history.location.pathname).toEqual('/prefixed/pathname') + it("does not strip partial prefix matches", () => { + window.location.hash = "#/prefixed/pathname" + const history = createHistory({ basename: "/prefix" }) + expect(history.location.pathname).toEqual("/prefixed/pathname") }) - it('strips when path is only the prefix', () => { - window.location.hash = '#/prefix' - const history = createHistory({ basename: '/prefix' }) - expect(history.location.pathname).toEqual('/') + it("strips when path is only the prefix", () => { + window.location.hash = "#/prefix" + const history = createHistory({ basename: "/prefix" }) + expect(history.location.pathname).toEqual("/") }) - it('strips with no pathname, but with a search string', () => { - window.location.hash = '#/prefix?a=b' - const history = createHistory({ basename: '/prefix' }) - expect(history.location.pathname).toEqual('/') + it("strips with no pathname, but with a search string", () => { + window.location.hash = "#/prefix?a=b" + const history = createHistory({ basename: "/prefix" }) + expect(history.location.pathname).toEqual("/") }) - it('strips with no pathname, but with a hash string', () => { - window.location.hash = '#/prefix#rest' - const history = createHistory({ basename: '/prefix' }) - expect(history.location.pathname).toEqual('/') + it("strips with no pathname, but with a hash string", () => { + window.location.hash = "#/prefix#rest" + const history = createHistory({ basename: "/prefix" }) + expect(history.location.pathname).toEqual("/") }) }) }) diff --git a/modules/__tests__/LocationUtils-test.js b/modules/__tests__/LocationUtils-test.js index 9a840b5e4..938162849 100644 --- a/modules/__tests__/LocationUtils-test.js +++ b/modules/__tests__/LocationUtils-test.js @@ -1,145 +1,162 @@ -import expect from 'expect' -import { createLocation } from '../LocationUtils' +import expect from "expect" +import { createLocation } from "../LocationUtils" -describe('createLocation', () => { - describe('with a full path', () => { - describe('given as a string', () => { - it('has the correct properties', () => { - expect(createLocation('/the/path?the=query#the-hash')).toMatchObject({ - pathname: '/the/path', - search: '?the=query', - hash: '#the-hash' +describe("createLocation", () => { + describe("with a full path", () => { + describe("given as a string", () => { + it("has the correct properties", () => { + expect(createLocation("/the/path?the=query#the-hash")).toMatchObject({ + pathname: "/the/path", + search: "?the=query", + hash: "#the-hash" }) }) }) - describe('given as an object', () => { - it('has the correct properties', () => { - expect(createLocation({ pathname: '/the/path', search: '?the=query', hash: '#the-hash' })).toMatchObject({ - pathname: '/the/path', - search: '?the=query', - hash: '#the-hash' + describe("given as an object", () => { + it("has the correct properties", () => { + expect( + createLocation({ + pathname: "/the/path", + search: "?the=query", + hash: "#the-hash" + }) + ).toMatchObject({ + pathname: "/the/path", + search: "?the=query", + hash: "#the-hash" }) }) }) }) - describe('with a relative path', () => { - describe('given as a string', () => { - it('has the correct properties', () => { - expect(createLocation('the/path?the=query#the-hash')).toMatchObject({ - pathname: 'the/path', - search: '?the=query', - hash: '#the-hash' + describe("with a relative path", () => { + describe("given as a string", () => { + it("has the correct properties", () => { + expect(createLocation("the/path?the=query#the-hash")).toMatchObject({ + pathname: "the/path", + search: "?the=query", + hash: "#the-hash" }) }) }) - describe('given as an object', () => { - it('has the correct properties', () => { - expect(createLocation({ pathname: 'the/path', search: '?the=query', hash: '#the-hash' })).toMatchObject({ - pathname: 'the/path', - search: '?the=query', - hash: '#the-hash' + describe("given as an object", () => { + it("has the correct properties", () => { + expect( + createLocation({ + pathname: "the/path", + search: "?the=query", + hash: "#the-hash" + }) + ).toMatchObject({ + pathname: "the/path", + search: "?the=query", + hash: "#the-hash" }) }) }) }) - describe('with a path with no pathname', () => { - describe('given as a string', () => { - it('has the correct properties', () => { - expect(createLocation('?the=query#the-hash')).toMatchObject({ - pathname: '/', - search: '?the=query', - hash: '#the-hash' + describe("with a path with no pathname", () => { + describe("given as a string", () => { + it("has the correct properties", () => { + expect(createLocation("?the=query#the-hash")).toMatchObject({ + pathname: "/", + search: "?the=query", + hash: "#the-hash" }) }) }) - describe('given as an object', () => { - it('has the correct properties', () => { - expect(createLocation({ search: '?the=query', hash: '#the-hash' })).toMatchObject({ - pathname: '/', - search: '?the=query', - hash: '#the-hash' + describe("given as an object", () => { + it("has the correct properties", () => { + expect( + createLocation({ search: "?the=query", hash: "#the-hash" }) + ).toMatchObject({ + pathname: "/", + search: "?the=query", + hash: "#the-hash" }) }) }) }) - describe('with a path with no search', () => { - describe('given as a string', () => { - it('has the correct properties', () => { - expect(createLocation('/the/path#the-hash')).toMatchObject({ - pathname: '/the/path', - search: '', - hash: '#the-hash' + describe("with a path with no search", () => { + describe("given as a string", () => { + it("has the correct properties", () => { + expect(createLocation("/the/path#the-hash")).toMatchObject({ + pathname: "/the/path", + search: "", + hash: "#the-hash" }) }) }) - describe('given as an object', () => { - it('has the correct properties', () => { - expect(createLocation({ pathname: '/the/path', hash: '#the-hash' })).toMatchObject({ - pathname: '/the/path', - search: '', - hash: '#the-hash' + describe("given as an object", () => { + it("has the correct properties", () => { + expect( + createLocation({ pathname: "/the/path", hash: "#the-hash" }) + ).toMatchObject({ + pathname: "/the/path", + search: "", + hash: "#the-hash" }) }) }) }) - describe('with a path with no hash', () => { - describe('given as a string', () => { - it('has the correct properties', () => { - expect(createLocation('/the/path?the=query')).toMatchObject({ - pathname: '/the/path', - search: '?the=query', - hash: '' + describe("with a path with no hash", () => { + describe("given as a string", () => { + it("has the correct properties", () => { + expect(createLocation("/the/path?the=query")).toMatchObject({ + pathname: "/the/path", + search: "?the=query", + hash: "" }) }) }) - describe('given as an object', () => { - it('has the correct properties', () => { - expect(createLocation({ pathname: '/the/path', search: '?the=query' })).toMatchObject({ - pathname: '/the/path', - search: '?the=query', - hash: '' + describe("given as an object", () => { + it("has the correct properties", () => { + expect( + createLocation({ pathname: "/the/path", search: "?the=query" }) + ).toMatchObject({ + pathname: "/the/path", + search: "?the=query", + hash: "" }) }) }) }) - describe('with a path that cannot be decoded', () => { - - describe('given as a string', () => { - it('throws custom message when decodeURI throws a URIError', () => { + describe("with a path that cannot be decoded", () => { + describe("given as a string", () => { + it("throws custom message when decodeURI throws a URIError", () => { expect(() => { - createLocation('/test%') + createLocation("/test%") }).toThrow('Pathname "/test%" could not be decoded.') }) }) - describe('given as an object', () => { - it('throws custom message when decodeURI throws a URIError', () => { + describe("given as an object", () => { + it("throws custom message when decodeURI throws a URIError", () => { expect(() => { - createLocation({ pathname: '/test%' }) + createLocation({ pathname: "/test%" }) }).toThrow('Pathname "/test%" could not be decoded.') }) }) }) - describe('key', () => { - it('has a key property if a key is provided', () => { - const location = createLocation('/the/path', undefined, 'key') - expect(Object.keys(location)).toContain('key') + describe("key", () => { + it("has a key property if a key is provided", () => { + const location = createLocation("/the/path", undefined, "key") + expect(Object.keys(location)).toContain("key") }) - it('has no key property if no key is provided', () => { - const location = createLocation('/the/path') - expect(Object.keys(location)).not.toContain('key') + it("has no key property if no key is provided", () => { + const location = createLocation("/the/path") + expect(Object.keys(location)).not.toContain("key") }) }) }) diff --git a/modules/__tests__/MemoryHistory-test.js b/modules/__tests__/MemoryHistory-test.js index ddbca3b7e..aab1dcd7f 100644 --- a/modules/__tests__/MemoryHistory-test.js +++ b/modules/__tests__/MemoryHistory-test.js @@ -1,135 +1,135 @@ -import createHistory from '../createMemoryHistory' -import * as TestSequences from './TestSequences' +import createHistory from "../createMemoryHistory" +import * as TestSequences from "./TestSequences" -describe('a memory history', () => { - describe('by default', () => { +describe("a memory history", () => { + describe("by default", () => { let history beforeEach(() => { history = createHistory() }) - describe('listen', () => { - it('does not immediately call listeners', (done) => { + describe("listen", () => { + it("does not immediately call listeners", done => { TestSequences.Listen(history, done) }) }) - describe('the initial location', () => { - it('has a key', (done) => { + describe("the initial location", () => { + it("has a key", done => { TestSequences.InitialLocationHasKey(history, done) }) }) - describe('push a new path', () => { - it('calls change listeners with the new location', (done) => { + describe("push a new path", () => { + it("calls change listeners with the new location", done => { TestSequences.PushNewLocation(history, done) }) }) - describe('push the same path', () => { - it('calls change listeners with the new location', (done) => { + describe("push the same path", () => { + it("calls change listeners with the new location", done => { TestSequences.PushSamePath(history, done) }) }) - describe('push state', () => { - it('calls change listeners with the new location', (done) => { + describe("push state", () => { + it("calls change listeners with the new location", done => { TestSequences.PushState(history, done) }) }) - describe('push with no pathname', () => { - it('calls change listeners with the normalized location', (done) => { + describe("push with no pathname", () => { + it("calls change listeners with the normalized location", done => { TestSequences.PushMissingPathname(history, done) }) }) - describe('push with a relative pathname', () => { - it('calls change listeners with the normalized location', (done) => { + describe("push with a relative pathname", () => { + it("calls change listeners with the normalized location", done => { TestSequences.PushRelativePathname(history, done) }) }) - describe('push with a unicode path string', () => { - it('creates a location with decoded properties', (done) => { + describe("push with a unicode path string", () => { + it("creates a location with decoded properties", done => { TestSequences.PushUnicodeLocation(history, done) }) }) - describe('push with an encoded path string', () => { - it('creates a location object with decoded pathname', (done) => { + describe("push with an encoded path string", () => { + it("creates a location object with decoded pathname", done => { TestSequences.PushEncodedLocation(history, done) }) }) - describe('push with an invalid path string (bad percent-encoding)', () => { - it('throws an error', (done) => { + describe("push with an invalid path string (bad percent-encoding)", () => { + it("throws an error", done => { TestSequences.PushInvalidPathname(history, done) }) }) - describe('replace a new path', () => { - it('calls change listeners with the new location', (done) => { + describe("replace a new path", () => { + it("calls change listeners with the new location", done => { TestSequences.ReplaceNewLocation(history, done) }) }) - describe('replace the same path', () => { - it('calls change listeners with the new location', (done) => { + describe("replace the same path", () => { + it("calls change listeners with the new location", done => { TestSequences.ReplaceSamePath(history, done) }) }) - describe('replace state', () => { - it('calls change listeners with the new location', (done) => { + describe("replace state", () => { + it("calls change listeners with the new location", done => { TestSequences.ReplaceState(history, done) }) }) - describe('replace with an invalid path string (bad percent-encoding)', () => { - it('throws an error', (done) => { + describe("replace with an invalid path string (bad percent-encoding)", () => { + it("throws an error", done => { TestSequences.ReplaceInvalidPathname(history, done) }) }) - describe('location created by encoded and unencoded pathname', () => { - it('produces the same location.pathname', (done) => { + describe("location created by encoded and unencoded pathname", () => { + it("produces the same location.pathname", done => { TestSequences.LocationPathnameAlwaysDecoded(history, done) }) }) - describe('location created with encoded/unencoded reserved characters', () => { - it('produces different location objects', (done) => { + describe("location created with encoded/unencoded reserved characters", () => { + it("produces different location objects", done => { TestSequences.EncodedReservedCharacters(history, done) }) }) - describe('goBack', () => { - it('calls change listeners with the previous location', (done) => { + describe("goBack", () => { + it("calls change listeners with the previous location", done => { TestSequences.GoBack(history, done) }) }) - describe('goForward', () => { - it('calls change listeners with the next location', (done) => { + describe("goForward", () => { + it("calls change listeners with the next location", done => { TestSequences.GoForward(history, done) }) }) - describe('block', () => { - it('blocks all transitions', (done) => { + describe("block", () => { + it("blocks all transitions", done => { TestSequences.BlockEverything(history, done) }) }) - describe('block a POP without listening', () => { - it('receives the next location and action as arguments', (done) => { + describe("block a POP without listening", () => { + it("receives the next location and action as arguments", done => { TestSequences.BlockPopWithoutListening(history, done) }) }) }) - describe('that denies all transitions', () => { + describe("that denies all transitions", () => { const getUserConfirmation = (_, callback) => callback(false) let history @@ -139,26 +139,26 @@ describe('a memory history', () => { }) }) - describe('push', () => { - it('does not update the location', (done) => { + describe("push", () => { + it("does not update the location", done => { TestSequences.DenyPush(history, done) }) }) - describe('goBack', () => { - it('does not update the location', (done) => { + describe("goBack", () => { + it("does not update the location", done => { TestSequences.DenyGoBack(history, done) }) }) - describe('goForward', () => { - it('does not update the location', (done) => { + describe("goForward", () => { + it("does not update the location", done => { TestSequences.DenyGoForward(history, done) }) }) }) - describe('a transition hook', () => { + describe("a transition hook", () => { const getUserConfirmation = (_, callback) => callback(true) let history @@ -168,11 +168,11 @@ describe('a memory history', () => { }) }) - it('receives the next location and action as arguments', (done) => { + it("receives the next location and action as arguments", done => { TestSequences.TransitionHookArgs(history, done) }) - it('cancels the transition when it returns false', (done) => { + it("cancels the transition when it returns false", done => { TestSequences.ReturnFalseTransitionHook(history, done) }) }) diff --git a/modules/__tests__/TestSequences/BackButtonTransitionHook.js b/modules/__tests__/TestSequences/BackButtonTransitionHook.js index 9bd0c679e..2af6b958f 100644 --- a/modules/__tests__/TestSequences/BackButtonTransitionHook.js +++ b/modules/__tests__/TestSequences/BackButtonTransitionHook.js @@ -1,20 +1,21 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { - let unblock, hookWasCalled = false + let unblock, + hookWasCalled = false const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) - history.push('/home') + history.push("/home") }, (location, action) => { - expect(action).toBe('PUSH') + expect(action).toBe("PUSH") expect(location).toMatchObject({ - pathname: '/home' + pathname: "/home" }) unblock = history.block(() => { @@ -24,9 +25,9 @@ export default (history, done) => { window.history.go(-1) }, (location, action) => { - expect(action).toBe('POP') + expect(action).toBe("POP") expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) expect(hookWasCalled).toBe(true) diff --git a/modules/__tests__/TestSequences/BlockEverything.js b/modules/__tests__/TestSequences/BlockEverything.js index e588967c2..de189a883 100644 --- a/modules/__tests__/TestSequences/BlockEverything.js +++ b/modules/__tests__/TestSequences/BlockEverything.js @@ -1,19 +1,19 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) const unblock = history.block() - history.push('/home') + history.push("/home") expect(history.location).toMatchObject({ - pathname: '/' + pathname: "/" }) unblock() diff --git a/modules/__tests__/TestSequences/BlockPopWithoutListening.js b/modules/__tests__/TestSequences/BlockPopWithoutListening.js index 623937879..2c5b79202 100644 --- a/modules/__tests__/TestSequences/BlockPopWithoutListening.js +++ b/modules/__tests__/TestSequences/BlockPopWithoutListening.js @@ -1,11 +1,11 @@ -import expect from 'expect' +import expect from "expect" export default (history, done) => { expect(history.location).toMatchObject({ - pathname: '/' + pathname: "/" }) - history.push('/home') + history.push("/home") let transitionHookWasCalled = false const unblock = history.block(() => { diff --git a/modules/__tests__/TestSequences/DenyGoBack.js b/modules/__tests__/TestSequences/DenyGoBack.js index fad2bb341..98a7bf97d 100644 --- a/modules/__tests__/TestSequences/DenyGoBack.js +++ b/modules/__tests__/TestSequences/DenyGoBack.js @@ -1,36 +1,36 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { let unblock const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) - history.push('/home') + history.push("/home") }, (location, action) => { - expect(action).toBe('PUSH') + expect(action).toBe("PUSH") expect(location).toMatchObject({ - pathname: '/home' + pathname: "/home" }) unblock = history.block(nextLocation => { expect(nextLocation).toMatchObject({ - pathname: '/' + pathname: "/" }) - return 'Are you sure?' + return "Are you sure?" }) history.goBack() }, (location, action) => { - expect(action).toBe('PUSH') + expect(action).toBe("PUSH") expect(location).toMatchObject({ - pathname: '/home' + pathname: "/home" }) unblock() diff --git a/modules/__tests__/TestSequences/DenyGoForward.js b/modules/__tests__/TestSequences/DenyGoForward.js index ff676ba74..b07e00c33 100644 --- a/modules/__tests__/TestSequences/DenyGoForward.js +++ b/modules/__tests__/TestSequences/DenyGoForward.js @@ -1,44 +1,44 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { let unblock const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) - history.push('/home') + history.push("/home") }, (location, action) => { - expect(action).toBe('PUSH') + expect(action).toBe("PUSH") expect(location).toMatchObject({ - pathname: '/home' + pathname: "/home" }) history.goBack() }, (location, action) => { - expect(action).toBe('POP') + expect(action).toBe("POP") expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) unblock = history.block(nextLocation => { expect(nextLocation).toMatchObject({ - pathname: '/home' + pathname: "/home" }) - return 'Are you sure?' + return "Are you sure?" }) history.goForward() }, (location, action) => { - expect(action).toBe('POP') + expect(action).toBe("POP") expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) unblock() diff --git a/modules/__tests__/TestSequences/DenyPush.js b/modules/__tests__/TestSequences/DenyPush.js index 214a293b8..19716374d 100644 --- a/modules/__tests__/TestSequences/DenyPush.js +++ b/modules/__tests__/TestSequences/DenyPush.js @@ -1,25 +1,25 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) const unblock = history.block(nextLocation => { expect(nextLocation).toMatchObject({ - pathname: '/home' + pathname: "/home" }) - return 'Are you sure?' + return "Are you sure?" }) - history.push('/home') + history.push("/home") expect(history.location).toMatchObject({ - pathname: '/' + pathname: "/" }) unblock() diff --git a/modules/__tests__/TestSequences/EncodedReservedCharacters.js b/modules/__tests__/TestSequences/EncodedReservedCharacters.js index 7e9c77f09..7de8134d2 100644 --- a/modules/__tests__/TestSequences/EncodedReservedCharacters.js +++ b/modules/__tests__/TestSequences/EncodedReservedCharacters.js @@ -1,35 +1,34 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ () => { // encoded string - const pathname = '/view/%23abc' + const pathname = "/view/%23abc" history.replace(pathname) }, - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/view/%23abc' + pathname: "/view/%23abc" }) // encoded object - const pathname = '/view/%23abc' + const pathname = "/view/%23abc" history.replace({ pathname }) }, - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/view/%23abc' + pathname: "/view/%23abc" }) // unencoded string - const pathname = '/view/#abc' + const pathname = "/view/#abc" history.replace(pathname) - } - , - (location) => { + }, + location => { expect(location).toMatchObject({ - pathname: '/view/', - hash: '#abc' + pathname: "/view/", + hash: "#abc" }) } ] diff --git a/modules/__tests__/TestSequences/GoBack.js b/modules/__tests__/TestSequences/GoBack.js index 31a96d71c..cd9298f51 100644 --- a/modules/__tests__/TestSequences/GoBack.js +++ b/modules/__tests__/TestSequences/GoBack.js @@ -1,27 +1,27 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) - history.push('/home') + history.push("/home") }, (location, action) => { - expect(action).toEqual('PUSH') + expect(action).toEqual("PUSH") expect(location).toMatchObject({ - pathname: '/home' + pathname: "/home" }) history.goBack() }, (location, action) => { - expect(action).toEqual('POP') + expect(action).toEqual("POP") expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) } ] diff --git a/modules/__tests__/TestSequences/GoForward.js b/modules/__tests__/TestSequences/GoForward.js index 2c1bb99ac..3d082368c 100644 --- a/modules/__tests__/TestSequences/GoForward.js +++ b/modules/__tests__/TestSequences/GoForward.js @@ -1,35 +1,35 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) - history.push('/home') + history.push("/home") }, (location, action) => { - expect(action).toEqual('PUSH') + expect(action).toEqual("PUSH") expect(location).toMatchObject({ - pathname: '/home' + pathname: "/home" }) history.goBack() }, (location, action) => { - expect(action).toEqual('POP') + expect(action).toEqual("POP") expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) history.goForward() }, (location, action) => { - expect(action).toEqual('POP') + expect(action).toEqual("POP") expect(location).toMatchObject({ - pathname: '/home' + pathname: "/home" }) } ] diff --git a/modules/__tests__/TestSequences/HashChangeTransitionHook.js b/modules/__tests__/TestSequences/HashChangeTransitionHook.js index a49f269d5..3ee76c5e8 100644 --- a/modules/__tests__/TestSequences/HashChangeTransitionHook.js +++ b/modules/__tests__/TestSequences/HashChangeTransitionHook.js @@ -1,24 +1,25 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { - let unblock, hookWasCalled = false + let unblock, + hookWasCalled = false const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) unblock = history.block(() => { hookWasCalled = true }) - window.location.hash = 'something-new' + window.location.hash = "something-new" }, - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/', - hash: '#something-new' + pathname: "/", + hash: "#something-new" }) expect(hookWasCalled).toBe(true) diff --git a/modules/__tests__/TestSequences/HashbangHashPathCoding.js b/modules/__tests__/TestSequences/HashbangHashPathCoding.js index e42adf3ff..0b12f13dc 100644 --- a/modules/__tests__/TestSequences/HashbangHashPathCoding.js +++ b/modules/__tests__/TestSequences/HashbangHashPathCoding.js @@ -1,45 +1,45 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) - expect(window.location.hash).toBe('#!/') + expect(window.location.hash).toBe("#!/") - history.push('/home?the=query#the-hash') + history.push("/home?the=query#the-hash") }, - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/home', - search: '?the=query', - hash: '#the-hash' + pathname: "/home", + search: "?the=query", + hash: "#the-hash" }) - expect(window.location.hash).toBe('#!/home?the=query#the-hash') + expect(window.location.hash).toBe("#!/home?the=query#the-hash") history.goBack() }, - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) - expect(window.location.hash).toBe('#!/') + expect(window.location.hash).toBe("#!/") history.goForward() }, - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/home', - search: '?the=query', - hash: '#the-hash' + pathname: "/home", + search: "?the=query", + hash: "#the-hash" }) - expect(window.location.hash).toBe('#!/home?the=query#the-hash') + expect(window.location.hash).toBe("#!/home?the=query#the-hash") } ] diff --git a/modules/__tests__/TestSequences/InitialLocationHasKey.js b/modules/__tests__/TestSequences/InitialLocationHasKey.js index 02cf7527d..ceafe58ac 100644 --- a/modules/__tests__/TestSequences/InitialLocationHasKey.js +++ b/modules/__tests__/TestSequences/InitialLocationHasKey.js @@ -1,9 +1,9 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ - (location) => { + location => { expect(location.key).toBeTruthy() } ] diff --git a/modules/__tests__/TestSequences/InitialLocationNoKey.js b/modules/__tests__/TestSequences/InitialLocationNoKey.js index 7f1f481b5..0f0f3b3b3 100644 --- a/modules/__tests__/TestSequences/InitialLocationNoKey.js +++ b/modules/__tests__/TestSequences/InitialLocationNoKey.js @@ -1,9 +1,9 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ - (location) => { + location => { expect(location.key).toBeFalsy() } ] diff --git a/modules/__tests__/TestSequences/Listen.js b/modules/__tests__/TestSequences/Listen.js index 7423d4b51..c170ac38d 100644 --- a/modules/__tests__/TestSequences/Listen.js +++ b/modules/__tests__/TestSequences/Listen.js @@ -1,5 +1,5 @@ -import mock from 'jest-mock'; -import expect from 'expect' +import mock from "jest-mock" +import expect from "expect" export default (history, done) => { const spy = mock.fn() diff --git a/modules/__tests__/TestSequences/LocationPathnameAlwaysDecoded.js b/modules/__tests__/TestSequences/LocationPathnameAlwaysDecoded.js index f3dbf9143..a90f2ceaf 100644 --- a/modules/__tests__/TestSequences/LocationPathnameAlwaysDecoded.js +++ b/modules/__tests__/TestSequences/LocationPathnameAlwaysDecoded.js @@ -1,42 +1,41 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ () => { // encoded string - const pathname = '/%E6%AD%B4%E5%8F%B2' + const pathname = "/%E6%AD%B4%E5%8F%B2" history.replace(pathname) }, - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/歴史' + pathname: "/歴史" }) // encoded object - const pathname = '/%E6%AD%B4%E5%8F%B2' + const pathname = "/%E6%AD%B4%E5%8F%B2" history.replace({ pathname }) }, - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/歴史' + pathname: "/歴史" }) // unencoded string - const pathname = '/歴史' + const pathname = "/歴史" history.replace(pathname) - } - , - (location) => { + }, + location => { expect(location).toMatchObject({ - pathname: '/歴史' + pathname: "/歴史" }) // unencoded object - const pathname = '/歴史' + const pathname = "/歴史" history.replace({ pathname }) }, - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/歴史' + pathname: "/歴史" }) } ] diff --git a/modules/__tests__/TestSequences/NoslashHashPathCoding.js b/modules/__tests__/TestSequences/NoslashHashPathCoding.js index 7724ff8f2..4d54a591f 100644 --- a/modules/__tests__/TestSequences/NoslashHashPathCoding.js +++ b/modules/__tests__/TestSequences/NoslashHashPathCoding.js @@ -1,32 +1,32 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) // IE 10+ gives us "#", everyone else gives us "" expect(window.location.hash).toMatch(/^#?$/) - history.push('/home?the=query#the-hash') + history.push("/home?the=query#the-hash") }, - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/home', - search: '?the=query', - hash: '#the-hash' + pathname: "/home", + search: "?the=query", + hash: "#the-hash" }) - expect(window.location.hash).toBe('#home?the=query#the-hash') + expect(window.location.hash).toBe("#home?the=query#the-hash") history.goBack() }, - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) // IE 10+ gives us "#", everyone else gives us "" @@ -34,14 +34,14 @@ export default (history, done) => { history.goForward() }, - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/home', - search: '?the=query', - hash: '#the-hash' + pathname: "/home", + search: "?the=query", + hash: "#the-hash" }) - expect(window.location.hash).toBe('#home?the=query#the-hash') + expect(window.location.hash).toBe("#home?the=query#the-hash") } ] diff --git a/modules/__tests__/TestSequences/PushEncodedLocation.js b/modules/__tests__/TestSequences/PushEncodedLocation.js index 9ef466fea..cc430bba4 100644 --- a/modules/__tests__/TestSequences/PushEncodedLocation.js +++ b/modules/__tests__/TestSequences/PushEncodedLocation.js @@ -1,24 +1,24 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) - const pathname = '/%E6%AD%B4%E5%8F%B2' - const search = '?%E3%82%AD%E3%83%BC=%E5%80%A4' - const hash = '#%E3%83%8F%E3%83%83%E3%82%B7%E3%83%A5' + const pathname = "/%E6%AD%B4%E5%8F%B2" + const search = "?%E3%82%AD%E3%83%BC=%E5%80%A4" + const hash = "#%E3%83%8F%E3%83%83%E3%82%B7%E3%83%A5" history.push(pathname + search + hash) }, (location, action) => { - expect(action).toBe('PUSH') + expect(action).toBe("PUSH") expect(location).toMatchObject({ - pathname: '/歴史', - search: '?%E3%82%AD%E3%83%BC=%E5%80%A4', - hash: '#%E3%83%8F%E3%83%83%E3%82%B7%E3%83%A5' + pathname: "/歴史", + search: "?%E3%82%AD%E3%83%BC=%E5%80%A4", + hash: "#%E3%83%8F%E3%83%83%E3%82%B7%E3%83%A5" }) } ] diff --git a/modules/__tests__/TestSequences/PushInvalidPathname.js b/modules/__tests__/TestSequences/PushInvalidPathname.js index 5b6bf7ba6..98f14c9ed 100644 --- a/modules/__tests__/TestSequences/PushInvalidPathname.js +++ b/modules/__tests__/TestSequences/PushInvalidPathname.js @@ -1,11 +1,11 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ () => { expect(() => { - history.push('/hello%') + history.push("/hello%") }).toThrow( 'Pathname "/hello%" could not be decoded. This is likely caused by an invalid percent-encoding.' ) diff --git a/modules/__tests__/TestSequences/PushMissingPathname.js b/modules/__tests__/TestSequences/PushMissingPathname.js index 72cef9ba6..5be3a2ce0 100644 --- a/modules/__tests__/TestSequences/PushMissingPathname.js +++ b/modules/__tests__/TestSequences/PushMissingPathname.js @@ -1,31 +1,31 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) - history.push('/home?the=query#the-hash') + history.push("/home?the=query#the-hash") }, (location, action) => { - expect(action).toBe('PUSH') + expect(action).toBe("PUSH") expect(location).toMatchObject({ - pathname: '/home', - search: '?the=query', - hash: '#the-hash' + pathname: "/home", + search: "?the=query", + hash: "#the-hash" }) - history.push('?another=query#another-hash') + history.push("?another=query#another-hash") }, (location, action) => { - expect(action).toBe('PUSH') + expect(action).toBe("PUSH") expect(location).toMatchObject({ - pathname: '/home', - search: '?another=query', - hash: '#another-hash' + pathname: "/home", + search: "?another=query", + hash: "#another-hash" }) } ] diff --git a/modules/__tests__/TestSequences/PushNewLocation.js b/modules/__tests__/TestSequences/PushNewLocation.js index 5325ab240..c1085b81c 100644 --- a/modules/__tests__/TestSequences/PushNewLocation.js +++ b/modules/__tests__/TestSequences/PushNewLocation.js @@ -1,21 +1,21 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) - history.push('/home?the=query#the-hash') + history.push("/home?the=query#the-hash") }, (location, action) => { - expect(action).toBe('PUSH') + expect(action).toBe("PUSH") expect(location).toMatchObject({ - pathname: '/home', - search: '?the=query', - hash: '#the-hash' + pathname: "/home", + search: "?the=query", + hash: "#the-hash" }) } ] diff --git a/modules/__tests__/TestSequences/PushRelativePathname.js b/modules/__tests__/TestSequences/PushRelativePathname.js index 6e1cb45a9..c99c3b876 100644 --- a/modules/__tests__/TestSequences/PushRelativePathname.js +++ b/modules/__tests__/TestSequences/PushRelativePathname.js @@ -1,31 +1,31 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) - history.push('/the/path?the=query#the-hash') + history.push("/the/path?the=query#the-hash") }, (location, action) => { - expect(action).toBe('PUSH') + expect(action).toBe("PUSH") expect(location).toMatchObject({ - pathname: '/the/path', - search: '?the=query', - hash: '#the-hash' + pathname: "/the/path", + search: "?the=query", + hash: "#the-hash" }) - history.push('../other/path?another=query#another-hash') + history.push("../other/path?another=query#another-hash") }, (location, action) => { - expect(action).toBe('PUSH') + expect(action).toBe("PUSH") expect(location).toMatchObject({ - pathname: '/other/path', - search: '?another=query', - hash: '#another-hash' + pathname: "/other/path", + search: "?another=query", + hash: "#another-hash" }) } ] diff --git a/modules/__tests__/TestSequences/PushSamePath.js b/modules/__tests__/TestSequences/PushSamePath.js index b78e2cdff..fdbbed696 100644 --- a/modules/__tests__/TestSequences/PushSamePath.js +++ b/modules/__tests__/TestSequences/PushSamePath.js @@ -1,35 +1,35 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) - history.push('/home') + history.push("/home") }, (location, action) => { - expect(action).toBe('PUSH') + expect(action).toBe("PUSH") expect(location).toMatchObject({ - pathname: '/home' + pathname: "/home" }) - history.push('/home') + history.push("/home") }, (location, action) => { - expect(action).toBe('PUSH') + expect(action).toBe("PUSH") expect(location).toMatchObject({ - pathname: '/home' + pathname: "/home" }) history.goBack() }, (location, action) => { - expect(action).toBe('POP') + expect(action).toBe("POP") expect(location).toMatchObject({ - pathname: '/home' + pathname: "/home" }) } ] diff --git a/modules/__tests__/TestSequences/PushSamePathWarning.js b/modules/__tests__/TestSequences/PushSamePathWarning.js index 7928810b9..51c34f72d 100644 --- a/modules/__tests__/TestSequences/PushSamePathWarning.js +++ b/modules/__tests__/TestSequences/PushSamePathWarning.js @@ -1,31 +1,31 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { let prevLocation const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) - history.push('/home') + history.push("/home") }, (location, action) => { - expect(action).toBe('PUSH') + expect(action).toBe("PUSH") expect(location).toMatchObject({ - pathname: '/home' + pathname: "/home" }) prevLocation = location - history.push('/home') + history.push("/home") }, (location, action) => { - expect(action).toBe('PUSH') + expect(action).toBe("PUSH") expect(location).toMatchObject({ - pathname: '/home' + pathname: "/home" }) // We should get the SAME location object. Nothing @@ -33,14 +33,17 @@ export default (history, done) => { expect(location).toBe(prevLocation) // We should see a warning message. - expect(warningMessage).toMatch('Hash history cannot PUSH the same path; a new entry will not be added to the history stack') + expect(warningMessage).toMatch( + "Hash history cannot PUSH the same path; a new entry will not be added to the history stack" + ) } ] let consoleError = console.error // eslint-disable-line no-console let warningMessage - console.error = (message) => { // eslint-disable-line no-console + console.error = message => { + // eslint-disable-line no-console warningMessage = message } diff --git a/modules/__tests__/TestSequences/PushState.js b/modules/__tests__/TestSequences/PushState.js index 9a641ccb0..912fffacd 100644 --- a/modules/__tests__/TestSequences/PushState.js +++ b/modules/__tests__/TestSequences/PushState.js @@ -1,22 +1,22 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) - history.push('/home?the=query#the-hash', { the: 'state' }) + history.push("/home?the=query#the-hash", { the: "state" }) }, (location, action) => { - expect(action).toBe('PUSH') + expect(action).toBe("PUSH") expect(location).toMatchObject({ - pathname: '/home', - search: '?the=query', - hash: '#the-hash', - state: { the: 'state' } + pathname: "/home", + search: "?the=query", + hash: "#the-hash", + state: { the: "state" } }) } ] diff --git a/modules/__tests__/TestSequences/PushStateWarning.js b/modules/__tests__/TestSequences/PushStateWarning.js index 0fc2defd3..b52f3448c 100644 --- a/modules/__tests__/TestSequences/PushStateWarning.js +++ b/modules/__tests__/TestSequences/PushStateWarning.js @@ -1,31 +1,34 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) - history.push('/home', { the: 'state' }) + history.push("/home", { the: "state" }) }, (location, action) => { - expect(action).toBe('PUSH') + expect(action).toBe("PUSH") expect(location).toMatchObject({ - pathname: '/home', + pathname: "/home", state: undefined }) // We should see a warning message. - expect(warningMessage).toMatch('Hash history cannot push state; it is ignored') + expect(warningMessage).toMatch( + "Hash history cannot push state; it is ignored" + ) } ] let consoleError = console.error // eslint-disable-line no-console let warningMessage - console.error = (message) => { // eslint-disable-line no-console + console.error = message => { + // eslint-disable-line no-console warningMessage = message } diff --git a/modules/__tests__/TestSequences/PushUnicodeLocation.js b/modules/__tests__/TestSequences/PushUnicodeLocation.js index 19f996be0..db9e2fee5 100644 --- a/modules/__tests__/TestSequences/PushUnicodeLocation.js +++ b/modules/__tests__/TestSequences/PushUnicodeLocation.js @@ -1,24 +1,24 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) - const pathname = '/歴史' - const search = '?キー=値' - const hash = '#ハッシュ' + const pathname = "/歴史" + const search = "?キー=値" + const hash = "#ハッシュ" history.push(pathname + search + hash) }, (location, action) => { - expect(action).toBe('PUSH') + expect(action).toBe("PUSH") expect(location).toMatchObject({ - pathname: '/歴史', - search: '?キー=値', - hash: '#ハッシュ' + pathname: "/歴史", + search: "?キー=値", + hash: "#ハッシュ" }) } ] diff --git a/modules/__tests__/TestSequences/ReplaceInvalidPathname.js b/modules/__tests__/TestSequences/ReplaceInvalidPathname.js index 14e5b3a22..31e3ef1e5 100644 --- a/modules/__tests__/TestSequences/ReplaceInvalidPathname.js +++ b/modules/__tests__/TestSequences/ReplaceInvalidPathname.js @@ -1,11 +1,11 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ () => { expect(() => { - history.replace('/hello%') + history.replace("/hello%") }).toThrow( 'Pathname "/hello%" could not be decoded. This is likely caused by an invalid percent-encoding.' ) diff --git a/modules/__tests__/TestSequences/ReplaceNewLocation.js b/modules/__tests__/TestSequences/ReplaceNewLocation.js index 321e29ac1..b7153cb22 100644 --- a/modules/__tests__/TestSequences/ReplaceNewLocation.js +++ b/modules/__tests__/TestSequences/ReplaceNewLocation.js @@ -1,21 +1,21 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) - history.replace('/home?the=query#the-hash') + history.replace("/home?the=query#the-hash") }, (location, action) => { - expect(action).toBe('REPLACE') + expect(action).toBe("REPLACE") expect(location).toMatchObject({ - pathname: '/home', - search: '?the=query', - hash: '#the-hash' + pathname: "/home", + search: "?the=query", + hash: "#the-hash" }) } ] diff --git a/modules/__tests__/TestSequences/ReplaceSamePath.js b/modules/__tests__/TestSequences/ReplaceSamePath.js index 32e8f6bbf..4a1c6273a 100644 --- a/modules/__tests__/TestSequences/ReplaceSamePath.js +++ b/modules/__tests__/TestSequences/ReplaceSamePath.js @@ -1,31 +1,31 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { let prevLocation const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) - history.replace('/home') + history.replace("/home") }, (location, action) => { - expect(action).toBe('REPLACE') + expect(action).toBe("REPLACE") expect(location).toMatchObject({ - pathname: '/home' + pathname: "/home" }) prevLocation = location - history.replace('/home') + history.replace("/home") }, (location, action) => { - expect(action).toBe('REPLACE') + expect(action).toBe("REPLACE") expect(location).toMatchObject({ - pathname: '/home' + pathname: "/home" }) expect(location).not.toBe(prevLocation) diff --git a/modules/__tests__/TestSequences/ReplaceState.js b/modules/__tests__/TestSequences/ReplaceState.js index 85d766983..f77a64925 100644 --- a/modules/__tests__/TestSequences/ReplaceState.js +++ b/modules/__tests__/TestSequences/ReplaceState.js @@ -1,22 +1,22 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) - history.replace('/home?the=query#the-hash', { the: 'state' }) + history.replace("/home?the=query#the-hash", { the: "state" }) }, (location, action) => { - expect(action).toBe('REPLACE') + expect(action).toBe("REPLACE") expect(location).toMatchObject({ - pathname: '/home', - search: '?the=query', - hash: '#the-hash', - state: { the: 'state' } + pathname: "/home", + search: "?the=query", + hash: "#the-hash", + state: { the: "state" } }) } ] diff --git a/modules/__tests__/TestSequences/ReplaceStateWarning.js b/modules/__tests__/TestSequences/ReplaceStateWarning.js index 81b7b7adf..6bb30e33c 100644 --- a/modules/__tests__/TestSequences/ReplaceStateWarning.js +++ b/modules/__tests__/TestSequences/ReplaceStateWarning.js @@ -1,31 +1,34 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) - history.replace('/home', { the: 'state' }) + history.replace("/home", { the: "state" }) }, (location, action) => { - expect(action).toBe('REPLACE') + expect(action).toBe("REPLACE") expect(location).toMatchObject({ - pathname: '/home', + pathname: "/home", state: undefined }) // We should see a warning message. - expect(warningMessage).toMatch('Hash history cannot replace state; it is ignored') + expect(warningMessage).toMatch( + "Hash history cannot replace state; it is ignored" + ) } ] let consoleError = console.error // eslint-disable-line no-console let warningMessage - console.error = (message) => { // eslint-disable-line no-console + console.error = message => { + // eslint-disable-line no-console warningMessage = message } diff --git a/modules/__tests__/TestSequences/ReturnFalseTransitionHook.js b/modules/__tests__/TestSequences/ReturnFalseTransitionHook.js index ded321847..1955d0f91 100644 --- a/modules/__tests__/TestSequences/ReturnFalseTransitionHook.js +++ b/modules/__tests__/TestSequences/ReturnFalseTransitionHook.js @@ -1,26 +1,26 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) const unblock = history.block(nextLocation => { expect(nextLocation).toMatchObject({ - pathname: '/home' + pathname: "/home" }) // Cancel the transition. return false }) - history.push('/home') + history.push("/home") expect(history.location).toMatchObject({ - pathname: '/' + pathname: "/" }) unblock() diff --git a/modules/__tests__/TestSequences/SlashHashPathCoding.js b/modules/__tests__/TestSequences/SlashHashPathCoding.js index e33fe2d10..c097d16ce 100644 --- a/modules/__tests__/TestSequences/SlashHashPathCoding.js +++ b/modules/__tests__/TestSequences/SlashHashPathCoding.js @@ -1,45 +1,45 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) - expect(window.location.hash).toBe('#/') + expect(window.location.hash).toBe("#/") - history.push('/home?the=query#the-hash') + history.push("/home?the=query#the-hash") }, - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/home', - search: '?the=query', - hash: '#the-hash' + pathname: "/home", + search: "?the=query", + hash: "#the-hash" }) - expect(window.location.hash).toBe('#/home?the=query#the-hash') + expect(window.location.hash).toBe("#/home?the=query#the-hash") history.goBack() }, - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) - expect(window.location.hash).toBe('#/') + expect(window.location.hash).toBe("#/") history.goForward() }, - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/home', - search: '?the=query', - hash: '#the-hash' + pathname: "/home", + search: "?the=query", + hash: "#the-hash" }) - expect(window.location.hash).toBe('#/home?the=query#the-hash') + expect(window.location.hash).toBe("#/home?the=query#the-hash") } ] diff --git a/modules/__tests__/TestSequences/TransitionHookArgs.js b/modules/__tests__/TestSequences/TransitionHookArgs.js index 38b1182fe..bece1fa8b 100644 --- a/modules/__tests__/TestSequences/TransitionHookArgs.js +++ b/modules/__tests__/TestSequences/TransitionHookArgs.js @@ -1,15 +1,15 @@ -import expect from 'expect' -import execSteps from './execSteps' +import expect from "expect" +import execSteps from "./execSteps" export default (history, done) => { let hookLocation, hookAction const steps = [ - (location) => { + location => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/" }) - history.push('/home') + history.push("/home") }, (location, action) => { expect(hookAction).toBe(action) @@ -21,7 +21,7 @@ export default (history, done) => { hookLocation = location hookAction = action - return 'Are you sure?' + return "Are you sure?" }) execSteps(steps, history, (...args) => { diff --git a/modules/__tests__/TestSequences/execSteps.js b/modules/__tests__/TestSequences/execSteps.js index 9e250bc07..5ba65f183 100644 --- a/modules/__tests__/TestSequences/execSteps.js +++ b/modules/__tests__/TestSequences/execSteps.js @@ -1,5 +1,7 @@ const execSteps = (steps, history, done) => { - let index = 0, unlisten, cleanedUp = false + let index = 0, + unlisten, + cleanedUp = false const cleanup = (...args) => { if (!cleanedUp) { @@ -13,13 +15,11 @@ const execSteps = (steps, history, done) => { try { const nextStep = steps[index++] - if (!nextStep) - throw new Error('Test is missing step ' + index) + if (!nextStep) throw new Error("Test is missing step " + index) nextStep(...args) - if (index === steps.length) - cleanup() + if (index === steps.length) cleanup() } catch (error) { cleanup(error) } diff --git a/modules/__tests__/TestSequences/index.js b/modules/__tests__/TestSequences/index.js index aeed0fce6..ff2410a29 100644 --- a/modules/__tests__/TestSequences/index.js +++ b/modules/__tests__/TestSequences/index.js @@ -1,34 +1,34 @@ -export BackButtonTransitionHook from './BackButtonTransitionHook' -export BlockEverything from './BlockEverything' -export BlockPopWithoutListening from './BlockPopWithoutListening' -export DenyPush from './DenyPush' -export DenyGoBack from './DenyGoBack' -export DenyGoForward from './DenyGoForward' -export EncodedReservedCharacters from './EncodedReservedCharacters' -export GoBack from './GoBack' -export GoForward from './GoForward' -export HashbangHashPathCoding from './HashbangHashPathCoding' -export HashChangeTransitionHook from './HashChangeTransitionHook' -export InitialLocationNoKey from './InitialLocationNoKey' -export InitialLocationHasKey from './InitialLocationHasKey' -export Listen from './Listen' -export LocationPathnameAlwaysDecoded from './LocationPathnameAlwaysDecoded' -export NoslashHashPathCoding from './NoslashHashPathCoding' -export PushEncodedLocation from './PushEncodedLocation' -export PushInvalidPathname from './PushInvalidPathname' -export PushNewLocation from './PushNewLocation' -export PushMissingPathname from './PushMissingPathname' -export PushSamePath from './PushSamePath' -export PushSamePathWarning from './PushSamePathWarning' -export PushState from './PushState' -export PushStateWarning from './PushStateWarning' -export PushRelativePathname from './PushRelativePathname' -export PushUnicodeLocation from './PushUnicodeLocation' -export ReplaceInvalidPathname from './ReplaceInvalidPathname' -export ReplaceNewLocation from './ReplaceNewLocation' -export ReplaceSamePath from './ReplaceSamePath' -export ReplaceState from './ReplaceState' -export ReplaceStateWarning from './ReplaceStateWarning' -export ReturnFalseTransitionHook from './ReturnFalseTransitionHook' -export SlashHashPathCoding from './SlashHashPathCoding' -export TransitionHookArgs from './TransitionHookArgs' +export BackButtonTransitionHook from "./BackButtonTransitionHook" +export BlockEverything from "./BlockEverything" +export BlockPopWithoutListening from "./BlockPopWithoutListening" +export DenyPush from "./DenyPush" +export DenyGoBack from "./DenyGoBack" +export DenyGoForward from "./DenyGoForward" +export EncodedReservedCharacters from "./EncodedReservedCharacters" +export GoBack from "./GoBack" +export GoForward from "./GoForward" +export HashbangHashPathCoding from "./HashbangHashPathCoding" +export HashChangeTransitionHook from "./HashChangeTransitionHook" +export InitialLocationNoKey from "./InitialLocationNoKey" +export InitialLocationHasKey from "./InitialLocationHasKey" +export Listen from "./Listen" +export LocationPathnameAlwaysDecoded from "./LocationPathnameAlwaysDecoded" +export NoslashHashPathCoding from "./NoslashHashPathCoding" +export PushEncodedLocation from "./PushEncodedLocation" +export PushInvalidPathname from "./PushInvalidPathname" +export PushNewLocation from "./PushNewLocation" +export PushMissingPathname from "./PushMissingPathname" +export PushSamePath from "./PushSamePath" +export PushSamePathWarning from "./PushSamePathWarning" +export PushState from "./PushState" +export PushStateWarning from "./PushStateWarning" +export PushRelativePathname from "./PushRelativePathname" +export PushUnicodeLocation from "./PushUnicodeLocation" +export ReplaceInvalidPathname from "./ReplaceInvalidPathname" +export ReplaceNewLocation from "./ReplaceNewLocation" +export ReplaceSamePath from "./ReplaceSamePath" +export ReplaceState from "./ReplaceState" +export ReplaceStateWarning from "./ReplaceStateWarning" +export ReturnFalseTransitionHook from "./ReturnFalseTransitionHook" +export SlashHashPathCoding from "./SlashHashPathCoding" +export TransitionHookArgs from "./TransitionHookArgs" diff --git a/modules/__tests__/createHref-test.js b/modules/__tests__/createHref-test.js index 586dbf6a7..427a1b64f 100644 --- a/modules/__tests__/createHref-test.js +++ b/modules/__tests__/createHref-test.js @@ -1,255 +1,255 @@ -import expect from 'expect' -import createBrowserHistory from '../createBrowserHistory' -import createHashHistory from '../createHashHistory' -import createMemoryHistory from '../createMemoryHistory' +import expect from "expect" +import createBrowserHistory from "../createBrowserHistory" +import createHashHistory from "../createHashHistory" +import createMemoryHistory from "../createMemoryHistory" -describe('a browser history', () => { - describe('with no basename', () => { +describe("a browser history", () => { + describe("with no basename", () => { let history beforeEach(() => { history = createBrowserHistory() }) - it('knows how to create hrefs', () => { + it("knows how to create hrefs", () => { const href = history.createHref({ - pathname: '/the/path', - search: '?the=query', - hash: '#the-hash' + pathname: "/the/path", + search: "?the=query", + hash: "#the-hash" }) - expect(href).toEqual('/the/path?the=query#the-hash') + expect(href).toEqual("/the/path?the=query#the-hash") }) }) - describe('with a basename', () => { + describe("with a basename", () => { let history beforeEach(() => { - history = createBrowserHistory({ basename: '/the/base' }) + history = createBrowserHistory({ basename: "/the/base" }) }) - it('knows how to create hrefs', () => { + it("knows how to create hrefs", () => { const href = history.createHref({ - pathname: '/the/path', - search: '?the=query', - hash: '#the-hash' + pathname: "/the/path", + search: "?the=query", + hash: "#the-hash" }) - expect(href).toEqual('/the/base/the/path?the=query#the-hash') + expect(href).toEqual("/the/base/the/path?the=query#the-hash") }) }) - describe('with a bad basename', () => { + describe("with a bad basename", () => { let history beforeEach(() => { - history = createBrowserHistory({ basename: '/the/bad/base/' }) + history = createBrowserHistory({ basename: "/the/bad/base/" }) }) - it('knows how to create hrefs', () => { + it("knows how to create hrefs", () => { const href = history.createHref({ - pathname: '/the/path', - search: '?the=query', - hash: '#the-hash' + pathname: "/the/path", + search: "?the=query", + hash: "#the-hash" }) - expect(href).toEqual('/the/bad/base/the/path?the=query#the-hash') + expect(href).toEqual("/the/bad/base/the/path?the=query#the-hash") }) }) - describe('with a slash basename', () => { + describe("with a slash basename", () => { let history beforeEach(() => { - history = createBrowserHistory({ basename: '/' }) + history = createBrowserHistory({ basename: "/" }) }) - it('knows how to create hrefs', () => { + it("knows how to create hrefs", () => { const href = history.createHref({ - pathname: '/the/path', - search: '?the=query', - hash: '#the-hash' + pathname: "/the/path", + search: "?the=query", + hash: "#the-hash" }) - expect(href).toEqual('/the/path?the=query#the-hash') + expect(href).toEqual("/the/path?the=query#the-hash") }) }) - describe('encoding', () => { + describe("encoding", () => { let history beforeEach(() => { history = createBrowserHistory() }) - it('does not encode the generated path', () => { + it("does not encode the generated path", () => { // encoded const encodedHref = history.createHref({ - pathname: '/%23abc' + pathname: "/%23abc" }) // unencoded const unencodedHref = history.createHref({ - pathname: '/#abc' + pathname: "/#abc" }) - expect(encodedHref).toEqual('/%23abc') - expect(unencodedHref).toEqual('/#abc') + expect(encodedHref).toEqual("/%23abc") + expect(unencodedHref).toEqual("/#abc") }) }) }) -describe('a hash history', () => { - describe('with default encoding', () => { +describe("a hash history", () => { + describe("with default encoding", () => { let history beforeEach(() => { history = createHashHistory() }) - it('knows how to create hrefs', () => { + it("knows how to create hrefs", () => { const href = history.createHref({ - pathname: '/the/path', - search: '?the=query', - hash: '#the-hash' + pathname: "/the/path", + search: "?the=query", + hash: "#the-hash" }) - expect(href).toEqual('#/the/path?the=query#the-hash') + expect(href).toEqual("#/the/path?the=query#the-hash") }) }) describe('with hashType="noslash"', () => { let history beforeEach(() => { - history = createHashHistory({ hashType: 'noslash' }) + history = createHashHistory({ hashType: "noslash" }) }) - it('knows how to create hrefs', () => { + it("knows how to create hrefs", () => { const href = history.createHref({ - pathname: '/the/path', - search: '?the=query', - hash: '#the-hash' + pathname: "/the/path", + search: "?the=query", + hash: "#the-hash" }) - expect(href).toEqual('#the/path?the=query#the-hash') + expect(href).toEqual("#the/path?the=query#the-hash") }) }) describe('with hashType="hashbang"', () => { let history beforeEach(() => { - history = createHashHistory({ hashType: 'hashbang' }) + history = createHashHistory({ hashType: "hashbang" }) }) - it('knows how to create hrefs', () => { + it("knows how to create hrefs", () => { const href = history.createHref({ - pathname: '/the/path', - search: '?the=query', - hash: '#the-hash' + pathname: "/the/path", + search: "?the=query", + hash: "#the-hash" }) - expect(href).toEqual('#!/the/path?the=query#the-hash') + expect(href).toEqual("#!/the/path?the=query#the-hash") }) }) - describe('with a basename', () => { + describe("with a basename", () => { let history beforeEach(() => { - history = createHashHistory({ basename: '/the/base' }) + history = createHashHistory({ basename: "/the/base" }) }) - it('knows how to create hrefs', () => { + it("knows how to create hrefs", () => { const href = history.createHref({ - pathname: '/the/path', - search: '?the=query' + pathname: "/the/path", + search: "?the=query" }) - expect(href).toEqual('#/the/base/the/path?the=query') + expect(href).toEqual("#/the/base/the/path?the=query") }) }) - describe('with a bad basename', () => { + describe("with a bad basename", () => { let history beforeEach(() => { - history = createHashHistory({ basename: '/the/bad/base/' }) + history = createHashHistory({ basename: "/the/bad/base/" }) }) - it('knows how to create hrefs', () => { + it("knows how to create hrefs", () => { const href = history.createHref({ - pathname: '/the/path', - search: '?the=query' + pathname: "/the/path", + search: "?the=query" }) - expect(href).toEqual('#/the/bad/base/the/path?the=query') + expect(href).toEqual("#/the/bad/base/the/path?the=query") }) }) - describe('with a slash basename', () => { + describe("with a slash basename", () => { let history beforeEach(() => { - history = createHashHistory({ basename: '/' }) + history = createHashHistory({ basename: "/" }) }) - it('knows how to create hrefs', () => { + it("knows how to create hrefs", () => { const href = history.createHref({ - pathname: '/the/path', - search: '?the=query' + pathname: "/the/path", + search: "?the=query" }) - expect(href).toEqual('#/the/path?the=query') + expect(href).toEqual("#/the/path?the=query") }) }) - describe('encoding', () => { + describe("encoding", () => { let history beforeEach(() => { history = createHashHistory() }) - it('does not encode the generated path', () => { + it("does not encode the generated path", () => { // encoded const encodedHref = history.createHref({ - pathname: '/%23abc' + pathname: "/%23abc" }) // unencoded const unencodedHref = history.createHref({ - pathname: '/#abc' + pathname: "/#abc" }) - expect(encodedHref).toEqual('#/%23abc') - expect(unencodedHref).toEqual('#/#abc') + expect(encodedHref).toEqual("#/%23abc") + expect(unencodedHref).toEqual("#/#abc") }) }) }) -describe('a memory history', () => { +describe("a memory history", () => { let history beforeEach(() => { history = createMemoryHistory() }) - it('knows how to create hrefs', () => { + it("knows how to create hrefs", () => { const href = history.createHref({ - pathname: '/the/path', - search: '?the=query', - hash: '#the-hash' + pathname: "/the/path", + search: "?the=query", + hash: "#the-hash" }) - expect(href).toEqual('/the/path?the=query#the-hash') + expect(href).toEqual("/the/path?the=query#the-hash") }) - describe('encoding', () => { + describe("encoding", () => { let history beforeEach(() => { history = createMemoryHistory() }) - it('does not encode the generated path', () => { + it("does not encode the generated path", () => { // encoded const encodedHref = history.createHref({ - pathname: '/%23abc' + pathname: "/%23abc" }) // unencoded const unencodedHref = history.createHref({ - pathname: '/#abc' + pathname: "/#abc" }) - expect(encodedHref).toEqual('/%23abc') - expect(unencodedHref).toEqual('/#abc') + expect(encodedHref).toEqual("/%23abc") + expect(unencodedHref).toEqual("/#abc") }) }) }) diff --git a/modules/createBrowserHistory.js b/modules/createBrowserHistory.js index a79588af5..fa0727d70 100644 --- a/modules/createBrowserHistory.js +++ b/modules/createBrowserHistory.js @@ -1,24 +1,24 @@ -import warning from 'warning' -import invariant from 'invariant' -import { createLocation } from './LocationUtils' +import warning from "warning" +import invariant from "invariant" +import { createLocation } from "./LocationUtils" import { addLeadingSlash, stripTrailingSlash, hasBasename, stripBasename, createPath -} from './PathUtils' -import createTransitionManager from './createTransitionManager' +} from "./PathUtils" +import createTransitionManager from "./createTransitionManager" import { canUseDOM, getConfirmation, supportsHistory, supportsPopStateOnHashChange, isExtraneousPopstateEvent -} from './DOMUtils' +} from "./DOMUtils" -const PopStateEvent = 'popstate' -const HashChangeEvent = 'hashchange' +const PopStateEvent = "popstate" +const HashChangeEvent = "hashchange" const getHistoryState = () => { try { @@ -35,10 +35,7 @@ const getHistoryState = () => { * pushState, replaceState, and the popstate event. */ const createBrowserHistory = (props = {}) => { - invariant( - canUseDOM, - 'Browser history needs a DOM' - ) + invariant(canUseDOM, "Browser history needs a DOM") const globalHistory = window.history const canUseHistory = supportsHistory() @@ -49,46 +46,49 @@ const createBrowserHistory = (props = {}) => { getUserConfirmation = getConfirmation, keyLength = 6 } = props - const basename = props.basename ? stripTrailingSlash(addLeadingSlash(props.basename)) : '' + const basename = props.basename + ? stripTrailingSlash(addLeadingSlash(props.basename)) + : "" - const getDOMLocation = (historyState) => { - const { key, state } = (historyState || {}) + const getDOMLocation = historyState => { + const { key, state } = historyState || {} const { pathname, search, hash } = window.location let path = pathname + search + hash warning( - (!basename || hasBasename(path, basename)), - 'You are attempting to use a basename on a page whose URL path does not begin ' + - 'with the basename. Expected path "' + path + '" to begin with "' + basename + '".' + !basename || hasBasename(path, basename), + "You are attempting to use a basename on a page whose URL path does not begin " + + 'with the basename. Expected path "' + + path + + '" to begin with "' + + basename + + '".' ) - if (basename) - path = stripBasename(path, basename) + if (basename) path = stripBasename(path, basename) return createLocation(path, state, key) } const createKey = () => - Math.random().toString(36).substr(2, keyLength) + Math.random() + .toString(36) + .substr(2, keyLength) const transitionManager = createTransitionManager() - const setState = (nextState) => { + const setState = nextState => { Object.assign(history, nextState) history.length = globalHistory.length - transitionManager.notifyListeners( - history.location, - history.action - ) + transitionManager.notifyListeners(history.location, history.action) } - const handlePopState = (event) => { + const handlePopState = event => { // Ignore extraneous popstate events in WebKit. - if (isExtraneousPopstateEvent(event)) - return + if (isExtraneousPopstateEvent(event)) return handlePop(getDOMLocation(event.state)) } @@ -99,24 +99,29 @@ const createBrowserHistory = (props = {}) => { let forceNextPop = false - const handlePop = (location) => { + const handlePop = location => { if (forceNextPop) { forceNextPop = false setState() } else { - const action = 'POP' - - transitionManager.confirmTransitionTo(location, action, getUserConfirmation, (ok) => { - if (ok) { - setState({ action, location }) - } else { - revertPop(location) + const action = "POP" + + transitionManager.confirmTransitionTo( + location, + action, + getUserConfirmation, + ok => { + if (ok) { + setState({ action, location }) + } else { + revertPop(location) + } } - }) + ) } } - const revertPop = (fromLocation) => { + const revertPop = fromLocation => { const toLocation = history.location // TODO: We could probably make this more reliable by @@ -125,13 +130,11 @@ const createBrowserHistory = (props = {}) => { let toIndex = allKeys.indexOf(toLocation.key) - if (toIndex === -1) - toIndex = 0 + if (toIndex === -1) toIndex = 0 let fromIndex = allKeys.indexOf(fromLocation.key) - if (fromIndex === -1) - fromIndex = 0 + if (fromIndex === -1) fromIndex = 0 const delta = toIndex - fromIndex @@ -142,109 +145,124 @@ const createBrowserHistory = (props = {}) => { } const initialLocation = getDOMLocation(getHistoryState()) - let allKeys = [ initialLocation.key ] + let allKeys = [initialLocation.key] // Public interface - const createHref = (location) => - basename + createPath(location) + const createHref = location => basename + createPath(location) const push = (path, state) => { warning( - !(typeof path === 'object' && path.state !== undefined && state !== undefined), - 'You should avoid providing a 2nd state argument to push when the 1st ' + - 'argument is a location-like object that already has state; it is ignored' + !( + typeof path === "object" && + path.state !== undefined && + state !== undefined + ), + "You should avoid providing a 2nd state argument to push when the 1st " + + "argument is a location-like object that already has state; it is ignored" ) - const action = 'PUSH' + const action = "PUSH" const location = createLocation(path, state, createKey(), history.location) - transitionManager.confirmTransitionTo(location, action, getUserConfirmation, (ok) => { - if (!ok) - return - - const href = createHref(location) - const { key, state } = location - - if (canUseHistory) { - globalHistory.pushState({ key, state }, null, href) - - if (forceRefresh) { - window.location.href = href + transitionManager.confirmTransitionTo( + location, + action, + getUserConfirmation, + ok => { + if (!ok) return + + const href = createHref(location) + const { key, state } = location + + if (canUseHistory) { + globalHistory.pushState({ key, state }, null, href) + + if (forceRefresh) { + window.location.href = href + } else { + const prevIndex = allKeys.indexOf(history.location.key) + const nextKeys = allKeys.slice( + 0, + prevIndex === -1 ? 0 : prevIndex + 1 + ) + + nextKeys.push(location.key) + allKeys = nextKeys + + setState({ action, location }) + } } else { - const prevIndex = allKeys.indexOf(history.location.key) - const nextKeys = allKeys.slice(0, prevIndex === -1 ? 0 : prevIndex + 1) + warning( + state === undefined, + "Browser history cannot push state in browsers that do not support HTML5 history" + ) - nextKeys.push(location.key) - allKeys = nextKeys - - setState({ action, location }) + window.location.href = href } - } else { - warning( - state === undefined, - 'Browser history cannot push state in browsers that do not support HTML5 history' - ) - - window.location.href = href } - }) + ) } const replace = (path, state) => { warning( - !(typeof path === 'object' && path.state !== undefined && state !== undefined), - 'You should avoid providing a 2nd state argument to replace when the 1st ' + - 'argument is a location-like object that already has state; it is ignored' + !( + typeof path === "object" && + path.state !== undefined && + state !== undefined + ), + "You should avoid providing a 2nd state argument to replace when the 1st " + + "argument is a location-like object that already has state; it is ignored" ) - const action = 'REPLACE' + const action = "REPLACE" const location = createLocation(path, state, createKey(), history.location) - transitionManager.confirmTransitionTo(location, action, getUserConfirmation, (ok) => { - if (!ok) - return + transitionManager.confirmTransitionTo( + location, + action, + getUserConfirmation, + ok => { + if (!ok) return - const href = createHref(location) - const { key, state } = location + const href = createHref(location) + const { key, state } = location - if (canUseHistory) { - globalHistory.replaceState({ key, state }, null, href) + if (canUseHistory) { + globalHistory.replaceState({ key, state }, null, href) - if (forceRefresh) { - window.location.replace(href) - } else { - const prevIndex = allKeys.indexOf(history.location.key) + if (forceRefresh) { + window.location.replace(href) + } else { + const prevIndex = allKeys.indexOf(history.location.key) - if (prevIndex !== -1) - allKeys[prevIndex] = location.key + if (prevIndex !== -1) allKeys[prevIndex] = location.key - setState({ action, location }) - } - } else { - warning( - state === undefined, - 'Browser history cannot replace state in browsers that do not support HTML5 history' - ) + setState({ action, location }) + } + } else { + warning( + state === undefined, + "Browser history cannot replace state in browsers that do not support HTML5 history" + ) - window.location.replace(href) + window.location.replace(href) + } } - }) + ) } - const go = (n) => { + const go = n => { globalHistory.go(n) } - const goBack = () => - go(-1) + const goBack = () => go(-1) - const goForward = () => - go(1) + const goForward = () => go(1) let listenerCount = 0 - const checkDOMListeners = (delta) => { + const checkDOMListeners = delta => { listenerCount += delta if (listenerCount === 1) { @@ -280,7 +298,7 @@ const createBrowserHistory = (props = {}) => { } } - const listen = (listener) => { + const listen = listener => { const unlisten = transitionManager.appendListener(listener) checkDOMListeners(1) @@ -292,7 +310,7 @@ const createBrowserHistory = (props = {}) => { const history = { length: globalHistory.length, - action: 'POP', + action: "POP", location: initialLocation, createHref, push, diff --git a/modules/createHashHistory.js b/modules/createHashHistory.js index 49b46e559..a85afb7f6 100644 --- a/modules/createHashHistory.js +++ b/modules/createHashHistory.js @@ -1,6 +1,6 @@ -import warning from 'warning' -import invariant from 'invariant' -import { createLocation, locationsAreEqual } from './LocationUtils' +import warning from "warning" +import invariant from "invariant" +import { createLocation, locationsAreEqual } from "./LocationUtils" import { addLeadingSlash, stripLeadingSlash, @@ -8,20 +8,21 @@ import { hasBasename, stripBasename, createPath -} from './PathUtils' -import createTransitionManager from './createTransitionManager' +} from "./PathUtils" +import createTransitionManager from "./createTransitionManager" import { canUseDOM, getConfirmation, supportsGoWithoutReloadUsingHash -} from './DOMUtils' +} from "./DOMUtils" -const HashChangeEvent = 'hashchange' +const HashChangeEvent = "hashchange" const HashPathCoders = { hashbang: { - encodePath: (path) => path.charAt(0) === '!' ? path : '!/' + stripLeadingSlash(path), - decodePath: (path) => path.charAt(0) === '!' ? path.substr(1) : path + encodePath: path => + path.charAt(0) === "!" ? path : "!/" + stripLeadingSlash(path), + decodePath: path => (path.charAt(0) === "!" ? path.substr(1) : path) }, noslash: { encodePath: stripLeadingSlash, @@ -37,35 +38,30 @@ const getHashPath = () => { // We can't use window.location.hash here because it's not // consistent across browsers - Firefox will pre-decode it! const href = window.location.href - const hashIndex = href.indexOf('#') - return hashIndex === -1 ? '' : href.substring(hashIndex + 1) + const hashIndex = href.indexOf("#") + return hashIndex === -1 ? "" : href.substring(hashIndex + 1) } -const pushHashPath = (path) => - window.location.hash = path +const pushHashPath = path => (window.location.hash = path) -const replaceHashPath = (path) => { - const hashIndex = window.location.href.indexOf('#') +const replaceHashPath = path => { + const hashIndex = window.location.href.indexOf("#") window.location.replace( - window.location.href.slice(0, hashIndex >= 0 ? hashIndex : 0) + '#' + path + window.location.href.slice(0, hashIndex >= 0 ? hashIndex : 0) + "#" + path ) } const createHashHistory = (props = {}) => { - invariant( - canUseDOM, - 'Hash history needs a DOM' - ) + invariant(canUseDOM, "Hash history needs a DOM") const globalHistory = window.history const canGoWithoutReload = supportsGoWithoutReloadUsingHash() - const { - getUserConfirmation = getConfirmation, - hashType = 'slash' - } = props - const basename = props.basename ? stripTrailingSlash(addLeadingSlash(props.basename)) : '' + const { getUserConfirmation = getConfirmation, hashType = "slash" } = props + const basename = props.basename + ? stripTrailingSlash(addLeadingSlash(props.basename)) + : "" const { encodePath, decodePath } = HashPathCoders[hashType] @@ -73,28 +69,28 @@ const createHashHistory = (props = {}) => { let path = decodePath(getHashPath()) warning( - (!basename || hasBasename(path, basename)), - 'You are attempting to use a basename on a page whose URL path does not begin ' + - 'with the basename. Expected path "' + path + '" to begin with "' + basename + '".' + !basename || hasBasename(path, basename), + "You are attempting to use a basename on a page whose URL path does not begin " + + 'with the basename. Expected path "' + + path + + '" to begin with "' + + basename + + '".' ) - if (basename) - path = stripBasename(path, basename) + if (basename) path = stripBasename(path, basename) return createLocation(path) } const transitionManager = createTransitionManager() - const setState = (nextState) => { + const setState = nextState => { Object.assign(history, nextState) history.length = globalHistory.length - transitionManager.notifyListeners( - history.location, - history.action - ) + transitionManager.notifyListeners(history.location, history.action) } let forceNextPop = false @@ -111,11 +107,9 @@ const createHashHistory = (props = {}) => { const location = getDOMLocation() const prevLocation = history.location - if (!forceNextPop && locationsAreEqual(prevLocation, location)) - return // A hashchange doesn't always == location change. + if (!forceNextPop && locationsAreEqual(prevLocation, location)) return // A hashchange doesn't always == location change. - if (ignorePath === createPath(location)) - return // Ignore this change; we already setState in push/replace. + if (ignorePath === createPath(location)) return // Ignore this change; we already setState in push/replace. ignorePath = null @@ -123,24 +117,29 @@ const createHashHistory = (props = {}) => { } } - const handlePop = (location) => { + const handlePop = location => { if (forceNextPop) { forceNextPop = false setState() } else { - const action = 'POP' - - transitionManager.confirmTransitionTo(location, action, getUserConfirmation, (ok) => { - if (ok) { - setState({ action, location }) - } else { - revertPop(location) + const action = "POP" + + transitionManager.confirmTransitionTo( + location, + action, + getUserConfirmation, + ok => { + if (ok) { + setState({ action, location }) + } else { + revertPop(location) + } } - }) + ) } } - const revertPop = (fromLocation) => { + const revertPop = fromLocation => { const toLocation = history.location // TODO: We could probably make this more reliable by @@ -149,13 +148,11 @@ const createHashHistory = (props = {}) => { let toIndex = allPaths.lastIndexOf(createPath(toLocation)) - if (toIndex === -1) - toIndex = 0 + if (toIndex === -1) toIndex = 0 let fromIndex = allPaths.lastIndexOf(createPath(fromLocation)) - if (fromIndex === -1) - fromIndex = 0 + if (fromIndex === -1) fromIndex = 0 const delta = toIndex - fromIndex @@ -169,111 +166,128 @@ const createHashHistory = (props = {}) => { const path = getHashPath() const encodedPath = encodePath(path) - if (path !== encodedPath) - replaceHashPath(encodedPath) + if (path !== encodedPath) replaceHashPath(encodedPath) const initialLocation = getDOMLocation() - let allPaths = [ createPath(initialLocation) ] + let allPaths = [createPath(initialLocation)] // Public interface - const createHref = (location) => - '#' + encodePath(basename + createPath(location)) + const createHref = location => + "#" + encodePath(basename + createPath(location)) const push = (path, state) => { warning( state === undefined, - 'Hash history cannot push state; it is ignored' + "Hash history cannot push state; it is ignored" ) - const action = 'PUSH' - const location = createLocation(path, undefined, undefined, history.location) - - transitionManager.confirmTransitionTo(location, action, getUserConfirmation, (ok) => { - if (!ok) - return - - const path = createPath(location) - const encodedPath = encodePath(basename + path) - const hashChanged = getHashPath() !== encodedPath - - if (hashChanged) { - // We cannot tell if a hashchange was caused by a PUSH, so we'd - // rather setState here and ignore the hashchange. The caveat here - // is that other hash histories in the page will consider it a POP. - ignorePath = path - pushHashPath(encodedPath) - - const prevIndex = allPaths.lastIndexOf(createPath(history.location)) - const nextPaths = allPaths.slice(0, prevIndex === -1 ? 0 : prevIndex + 1) + const action = "PUSH" + const location = createLocation( + path, + undefined, + undefined, + history.location + ) - nextPaths.push(path) - allPaths = nextPaths + transitionManager.confirmTransitionTo( + location, + action, + getUserConfirmation, + ok => { + if (!ok) return + + const path = createPath(location) + const encodedPath = encodePath(basename + path) + const hashChanged = getHashPath() !== encodedPath + + if (hashChanged) { + // We cannot tell if a hashchange was caused by a PUSH, so we'd + // rather setState here and ignore the hashchange. The caveat here + // is that other hash histories in the page will consider it a POP. + ignorePath = path + pushHashPath(encodedPath) + + const prevIndex = allPaths.lastIndexOf(createPath(history.location)) + const nextPaths = allPaths.slice( + 0, + prevIndex === -1 ? 0 : prevIndex + 1 + ) + + nextPaths.push(path) + allPaths = nextPaths - setState({ action, location }) - } else { - warning( - false, - 'Hash history cannot PUSH the same path; a new entry will not be added to the history stack' - ) + setState({ action, location }) + } else { + warning( + false, + "Hash history cannot PUSH the same path; a new entry will not be added to the history stack" + ) - setState() + setState() + } } - }) + ) } const replace = (path, state) => { warning( state === undefined, - 'Hash history cannot replace state; it is ignored' + "Hash history cannot replace state; it is ignored" ) - const action = 'REPLACE' - const location = createLocation(path, undefined, undefined, history.location) - - transitionManager.confirmTransitionTo(location, action, getUserConfirmation, (ok) => { - if (!ok) - return - - const path = createPath(location) - const encodedPath = encodePath(basename + path) - const hashChanged = getHashPath() !== encodedPath + const action = "REPLACE" + const location = createLocation( + path, + undefined, + undefined, + history.location + ) - if (hashChanged) { - // We cannot tell if a hashchange was caused by a REPLACE, so we'd - // rather setState here and ignore the hashchange. The caveat here - // is that other hash histories in the page will consider it a POP. - ignorePath = path - replaceHashPath(encodedPath) - } + transitionManager.confirmTransitionTo( + location, + action, + getUserConfirmation, + ok => { + if (!ok) return + + const path = createPath(location) + const encodedPath = encodePath(basename + path) + const hashChanged = getHashPath() !== encodedPath + + if (hashChanged) { + // We cannot tell if a hashchange was caused by a REPLACE, so we'd + // rather setState here and ignore the hashchange. The caveat here + // is that other hash histories in the page will consider it a POP. + ignorePath = path + replaceHashPath(encodedPath) + } - const prevIndex = allPaths.indexOf(createPath(history.location)) + const prevIndex = allPaths.indexOf(createPath(history.location)) - if (prevIndex !== -1) - allPaths[prevIndex] = path + if (prevIndex !== -1) allPaths[prevIndex] = path - setState({ action, location }) - }) + setState({ action, location }) + } + ) } - const go = (n) => { + const go = n => { warning( canGoWithoutReload, - 'Hash history go(n) causes a full page reload in this browser' + "Hash history go(n) causes a full page reload in this browser" ) globalHistory.go(n) } - const goBack = () => - go(-1) + const goBack = () => go(-1) - const goForward = () => - go(1) + const goForward = () => go(1) let listenerCount = 0 - const checkDOMListeners = (delta) => { + const checkDOMListeners = delta => { listenerCount += delta if (listenerCount === 1) { @@ -303,7 +317,7 @@ const createHashHistory = (props = {}) => { } } - const listen = (listener) => { + const listen = listener => { const unlisten = transitionManager.appendListener(listener) checkDOMListeners(1) @@ -315,7 +329,7 @@ const createHashHistory = (props = {}) => { const history = { length: globalHistory.length, - action: 'POP', + action: "POP", location: initialLocation, createHref, push, diff --git a/modules/createMemoryHistory.js b/modules/createMemoryHistory.js index 7780dd367..6bab07896 100644 --- a/modules/createMemoryHistory.js +++ b/modules/createMemoryHistory.js @@ -1,7 +1,7 @@ -import warning from 'warning' -import { createPath } from './PathUtils' -import { createLocation } from './LocationUtils' -import createTransitionManager from './createTransitionManager' +import warning from "warning" +import { createPath } from "./PathUtils" +import { createLocation } from "./LocationUtils" +import createTransitionManager from "./createTransitionManager" const clamp = (n, lowerBound, upperBound) => Math.min(Math.max(n, lowerBound), upperBound) @@ -12,33 +12,33 @@ const clamp = (n, lowerBound, upperBound) => const createMemoryHistory = (props = {}) => { const { getUserConfirmation, - initialEntries = [ '/' ], + initialEntries = ["/"], initialIndex = 0, keyLength = 6 } = props const transitionManager = createTransitionManager() - const setState = (nextState) => { + const setState = nextState => { Object.assign(history, nextState) history.length = history.entries.length - transitionManager.notifyListeners( - history.location, - history.action - ) + transitionManager.notifyListeners(history.location, history.action) } const createKey = () => - Math.random().toString(36).substr(2, keyLength) + Math.random() + .toString(36) + .substr(2, keyLength) const index = clamp(initialIndex, 0, initialEntries.length - 1) - const entries = initialEntries.map(entry => ( - typeof entry === 'string' - ? createLocation(entry, undefined, createKey()) - : createLocation(entry, undefined, entry.key || createKey()) - )) + const entries = initialEntries.map( + entry => + typeof entry === "string" + ? createLocation(entry, undefined, createKey()) + : createLocation(entry, undefined, entry.key || createKey()) + ) // Public interface @@ -46,98 +46,119 @@ const createMemoryHistory = (props = {}) => { const push = (path, state) => { warning( - !(typeof path === 'object' && path.state !== undefined && state !== undefined), - 'You should avoid providing a 2nd state argument to push when the 1st ' + - 'argument is a location-like object that already has state; it is ignored' + !( + typeof path === "object" && + path.state !== undefined && + state !== undefined + ), + "You should avoid providing a 2nd state argument to push when the 1st " + + "argument is a location-like object that already has state; it is ignored" ) - const action = 'PUSH' + const action = "PUSH" const location = createLocation(path, state, createKey(), history.location) - transitionManager.confirmTransitionTo(location, action, getUserConfirmation, (ok) => { - if (!ok) - return - - const prevIndex = history.index - const nextIndex = prevIndex + 1 + transitionManager.confirmTransitionTo( + location, + action, + getUserConfirmation, + ok => { + if (!ok) return + + const prevIndex = history.index + const nextIndex = prevIndex + 1 + + const nextEntries = history.entries.slice(0) + if (nextEntries.length > nextIndex) { + nextEntries.splice( + nextIndex, + nextEntries.length - nextIndex, + location + ) + } else { + nextEntries.push(location) + } - const nextEntries = history.entries.slice(0) - if (nextEntries.length > nextIndex) { - nextEntries.splice(nextIndex, nextEntries.length - nextIndex, location) - } else { - nextEntries.push(location) + setState({ + action, + location, + index: nextIndex, + entries: nextEntries + }) } - - setState({ - action, - location, - index: nextIndex, - entries: nextEntries - }) - }) + ) } const replace = (path, state) => { warning( - !(typeof path === 'object' && path.state !== undefined && state !== undefined), - 'You should avoid providing a 2nd state argument to replace when the 1st ' + - 'argument is a location-like object that already has state; it is ignored' + !( + typeof path === "object" && + path.state !== undefined && + state !== undefined + ), + "You should avoid providing a 2nd state argument to replace when the 1st " + + "argument is a location-like object that already has state; it is ignored" ) - const action = 'REPLACE' + const action = "REPLACE" const location = createLocation(path, state, createKey(), history.location) - transitionManager.confirmTransitionTo(location, action, getUserConfirmation, (ok) => { - if (!ok) - return + transitionManager.confirmTransitionTo( + location, + action, + getUserConfirmation, + ok => { + if (!ok) return - history.entries[history.index] = location + history.entries[history.index] = location - setState({ action, location }) - }) + setState({ action, location }) + } + ) } - const go = (n) => { + const go = n => { const nextIndex = clamp(history.index + n, 0, history.entries.length - 1) - const action = 'POP' + const action = "POP" const location = history.entries[nextIndex] - transitionManager.confirmTransitionTo(location, action, getUserConfirmation, (ok) => { - if (ok) { - setState({ - action, - location, - index: nextIndex - }) - } else { - // Mimic the behavior of DOM histories by - // causing a render after a cancelled POP. - setState() + transitionManager.confirmTransitionTo( + location, + action, + getUserConfirmation, + ok => { + if (ok) { + setState({ + action, + location, + index: nextIndex + }) + } else { + // Mimic the behavior of DOM histories by + // causing a render after a cancelled POP. + setState() + } } - }) + ) } - const goBack = () => - go(-1) + const goBack = () => go(-1) - const goForward = () => - go(1) + const goForward = () => go(1) - const canGo = (n) => { + const canGo = n => { const nextIndex = history.index + n return nextIndex >= 0 && nextIndex < history.entries.length } - const block = (prompt = false) => - transitionManager.setPrompt(prompt) + const block = (prompt = false) => transitionManager.setPrompt(prompt) - const listen = (listener) => - transitionManager.appendListener(listener) + const listen = listener => transitionManager.appendListener(listener) const history = { length: entries.length, - action: 'POP', + action: "POP", location: entries[index], index, entries, diff --git a/modules/createTransitionManager.js b/modules/createTransitionManager.js index a86edd445..474a62158 100644 --- a/modules/createTransitionManager.js +++ b/modules/createTransitionManager.js @@ -1,36 +1,38 @@ -import warning from 'warning' +import warning from "warning" const createTransitionManager = () => { let prompt = null - const setPrompt = (nextPrompt) => { - warning( - prompt == null, - 'A history supports only one prompt at a time' - ) + const setPrompt = nextPrompt => { + warning(prompt == null, "A history supports only one prompt at a time") prompt = nextPrompt return () => { - if (prompt === nextPrompt) - prompt = null + if (prompt === nextPrompt) prompt = null } } - const confirmTransitionTo = (location, action, getUserConfirmation, callback) => { + const confirmTransitionTo = ( + location, + action, + getUserConfirmation, + callback + ) => { // TODO: If another transition starts while we're still confirming // the previous one, we may end up in a weird state. Figure out the // best way to handle this. if (prompt != null) { - const result = typeof prompt === 'function' ? prompt(location, action) : prompt + const result = + typeof prompt === "function" ? prompt(location, action) : prompt - if (typeof result === 'string') { - if (typeof getUserConfirmation === 'function') { + if (typeof result === "string") { + if (typeof getUserConfirmation === "function") { getUserConfirmation(result, callback) } else { warning( false, - 'A history needs a getUserConfirmation function in order to use a prompt message' + "A history needs a getUserConfirmation function in order to use a prompt message" ) callback(true) @@ -46,12 +48,11 @@ const createTransitionManager = () => { let listeners = [] - const appendListener = (fn) => { + const appendListener = fn => { let isActive = true const listener = (...args) => { - if (isActive) - fn(...args) + if (isActive) fn(...args) } listeners.push(listener) diff --git a/modules/index.js b/modules/index.js index a68022e94..680fbb258 100644 --- a/modules/index.js +++ b/modules/index.js @@ -1,5 +1,5 @@ -export createBrowserHistory from './createBrowserHistory' -export createHashHistory from './createHashHistory' -export createMemoryHistory from './createMemoryHistory' -export { createLocation, locationsAreEqual } from './LocationUtils' -export { parsePath, createPath } from './PathUtils' +export createBrowserHistory from "./createBrowserHistory" +export createHashHistory from "./createHashHistory" +export createMemoryHistory from "./createMemoryHistory" +export { createLocation, locationsAreEqual } from "./LocationUtils" +export { parsePath, createPath } from "./PathUtils" diff --git a/package.json b/package.json index b03d59afb..f310ebf84 100644 --- a/package.json +++ b/package.json @@ -73,5 +73,8 @@ "keywords": [ "history", "location" - ] + ], + "prettier": { + "semi": false + } }