diff --git a/modules/__tests__/BrowserHistory-test.js b/modules/__tests__/BrowserHistory-test.js
index 15e8f1e78..a33397ac4 100644
--- a/modules/__tests__/BrowserHistory-test.js
+++ b/modules/__tests__/BrowserHistory-test.js
@@ -2,11 +2,9 @@ import { supportsHistory } from '../DOMUtils'
import createBrowserHistory from '../createBrowserHistory'
import describeInitialLocation from './describeInitialLocation'
import describeTransitions from './describeTransitions'
-import describePushState from './describePushState'
import describePush from './describePush'
-import describeReplaceState from './describeReplaceState'
import describeReplace from './describeReplace'
-import describePopState from './describePopState'
+import describePop from './describePop'
import describeHashSupport from './describeHashSupport'
import describeBasename from './describeBasename'
import describeQueries from './describeQueries'
@@ -20,11 +18,9 @@ describe('browser history', function () {
if (supportsHistory()) {
describeInitialLocation(createBrowserHistory)
describeTransitions(createBrowserHistory)
- describePushState(createBrowserHistory)
describePush(createBrowserHistory)
- describeReplaceState(createBrowserHistory)
describeReplace(createBrowserHistory)
- describePopState(createBrowserHistory)
+ describePop(createBrowserHistory)
describeHashSupport(createBrowserHistory)
describeBasename(createBrowserHistory)
describeQueries(createBrowserHistory)
@@ -33,11 +29,9 @@ describe('browser history', function () {
describe.skip(null, function () {
describeInitialLocation(createBrowserHistory)
describeTransitions(createBrowserHistory)
- describePushState(createBrowserHistory)
describePush(createBrowserHistory)
- describeReplaceState(createBrowserHistory)
describeReplace(createBrowserHistory)
- describePopState(createBrowserHistory)
+ describePop(createBrowserHistory)
describeHashSupport(createBrowserHistory)
describeBasename(createBrowserHistory)
describeQueries(createBrowserHistory)
diff --git a/modules/__tests__/HashHistory-test.js b/modules/__tests__/HashHistory-test.js
index 9483cc43f..0861fdcf6 100644
--- a/modules/__tests__/HashHistory-test.js
+++ b/modules/__tests__/HashHistory-test.js
@@ -3,11 +3,9 @@ import { supportsGoWithoutReloadUsingHash, supportsHistory } from '../DOMUtils'
import createHashHistory from '../createHashHistory'
import describeInitialLocation from './describeInitialLocation'
import describeTransitions from './describeTransitions'
-import describePushState from './describePushState'
import describePush from './describePush'
-import describeReplaceState from './describeReplaceState'
import describeReplace from './describeReplace'
-import describePopState from './describePopState'
+import describePop from './describePop'
import describeQueryKey from './describeQueryKey'
import describeBasename from './describeBasename'
import describeQueries from './describeQueries'
@@ -21,18 +19,16 @@ describe('hash history', function () {
describeInitialLocation(createHashHistory)
describeTransitions(createHashHistory)
- describePushState(createHashHistory)
describePush(createHashHistory)
- describeReplaceState(createHashHistory)
describeReplace(createHashHistory)
describeBasename(createHashHistory)
describeQueries(createHashHistory)
if (supportsHistory()) {
- describePopState(createHashHistory)
+ describePop(createHashHistory)
} else {
describe.skip(null, function () {
- describePopState(createHashHistory)
+ describePop(createHashHistory)
})
}
diff --git a/modules/__tests__/Location-test.js b/modules/__tests__/Location-test.js
index 0e210a2d3..d036375ab 100644
--- a/modules/__tests__/Location-test.js
+++ b/modules/__tests__/Location-test.js
@@ -5,43 +5,43 @@ import { POP } from '../Actions'
describe('a location', function () {
it('knows its pathname', function () {
- let location = createLocation('/home?the=query#the-hash')
+ const location = createLocation('/home?the=query#the-hash')
expect(location.pathname).toEqual('/home')
})
it('knows its search string', function () {
- let location = createLocation('/home?the=query#the-hash')
+ const location = createLocation('/home?the=query#the-hash')
expect(location.search).toEqual('?the=query')
})
it('knows its hash', function () {
- let location = createLocation('/home?the=query#the-hash')
+ const location = createLocation('/home?the=query#the-hash')
expect(location.hash).toEqual('#the-hash')
})
it('compensates if the location is fully qualified', function () {
- let location = createLocation('https://example.com/home')
+ const location = createLocation('https://example.com/home')
expect(location.pathname).toEqual('/home')
})
it('does not strip URL-like strings in the query', function () {
- let location = createLocation('/home?redirect=https://example.com/')
+ const location = createLocation('/home?redirect=https://example.com/')
expect(location.pathname).toEqual('/home')
expect(location.search).toEqual('?redirect=https://example.com/')
})
it('has null state by default', function () {
- let location = createLocation()
+ const location = createLocation()
expect(location.state).toBe(null)
})
it('uses pop navigation by default', function () {
- let location = createLocation()
+ const location = createLocation()
expect(location.action).toBe(POP)
})
it('has a null key by default', function () {
- let location = createLocation()
+ const location = createLocation()
expect(location.key).toBe(null)
})
@@ -52,7 +52,7 @@ describe('a location', function () {
})
it('has a key by default', function () {
- let location = history.createLocation()
+ const location = history.createLocation()
expect(location.key).toExist()
})
})
@@ -60,7 +60,7 @@ describe('a location', function () {
describe('creating a location with an object', function () {
it('puts the pathname, search, and hash in the proper order', function () {
- let location = createLocation({
+ const location = createLocation({
pathname: '/the/path',
search: '?the=query',
hash: '#the-hash'
diff --git a/modules/__tests__/MemoryHistory-test.js b/modules/__tests__/MemoryHistory-test.js
index 830725f45..e0508a181 100644
--- a/modules/__tests__/MemoryHistory-test.js
+++ b/modules/__tests__/MemoryHistory-test.js
@@ -2,9 +2,7 @@ import expect from 'expect'
import createMemoryHistory from '../createMemoryHistory'
import describeInitialLocation from './describeInitialLocation'
import describeTransitions from './describeTransitions'
-import describePushState from './describePushState'
import describePush from './describePush'
-import describeReplaceState from './describeReplaceState'
import describeReplace from './describeReplace'
import describeBasename from './describeBasename'
import describeQueries from './describeQueries'
@@ -13,9 +11,7 @@ import describeGo from './describeGo'
describe('memory history', function () {
describeInitialLocation(createMemoryHistory)
describeTransitions(createMemoryHistory)
- describePushState(createMemoryHistory)
describePush(createMemoryHistory)
- describeReplaceState(createMemoryHistory)
describeReplace(createMemoryHistory)
describeBasename(createMemoryHistory)
describeQueries(createMemoryHistory)
diff --git a/modules/__tests__/describeBasename.js b/modules/__tests__/describeBasename.js
index 7fc1c1ec2..d4bbbaec2 100644
--- a/modules/__tests__/describeBasename.js
+++ b/modules/__tests__/describeBasename.js
@@ -21,34 +21,9 @@ function describeBasename(createHistory) {
unlisten()
})
- describe('in pushState', function () {
- it('works', function (done) {
- let steps = [
- function (location) {
- expect(location.pathname).toEqual('/')
- expect(location.search).toEqual('')
- expect(location.state).toEqual(null)
- expect(location.action).toEqual(POP)
- expect(location.basename).toEqual('')
-
- history.pushState({ the: 'state' }, '/home')
- },
- function (location) {
- expect(location.pathname).toEqual('/home')
- expect(location.search).toEqual('')
- expect(location.state).toEqual({ the: 'state' })
- expect(location.action).toEqual(PUSH)
- expect(location.basename).toEqual('/base/url')
- }
- ]
-
- unlisten = history.listen(execSteps(steps, done))
- })
- })
-
describe('in push', function () {
it('works with string', function (done) {
- let steps = [
+ const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
@@ -71,7 +46,7 @@ function describeBasename(createHistory) {
})
it('works with object', function (done) {
- let steps = [
+ const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
@@ -109,34 +84,9 @@ function describeBasename(createHistory) {
})
})
- describe('in replaceState', function () {
- it('works', function (done) {
- let steps = [
- function (location) {
- expect(location.pathname).toEqual('/')
- expect(location.search).toEqual('')
- expect(location.state).toEqual(null)
- expect(location.action).toEqual(POP)
- expect(location.basename).toEqual('')
-
- history.replaceState({ the: 'state' }, '/home')
- },
- function (location) {
- expect(location.pathname).toEqual('/home')
- expect(location.search).toEqual('')
- expect(location.state).toEqual({ the: 'state' })
- expect(location.action).toEqual(REPLACE)
- expect(location.basename).toEqual('/base/url')
- }
- ]
-
- unlisten = history.listen(execSteps(steps, done))
- })
- })
-
describe('in replace', function () {
it('works with string', function (done) {
- let steps = [
+ const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
@@ -159,7 +109,7 @@ function describeBasename(createHistory) {
})
it('works with object', function (done) {
- let steps = [
+ const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
@@ -214,10 +164,10 @@ function describeBasename(createHistory) {
})
})
- describe('basename through ', () => {
+ describe('basename through ', function () {
let history, unlisten, base
- before('add base element', () => {
+ before('add base element', function () {
base = document.createElement('base')
base.href = '/base/url'
document.head.appendChild(base)
@@ -227,7 +177,7 @@ function describeBasename(createHistory) {
history = useBasename(createHistory)()
})
- describe('in createPath', () => {
+ describe('in createPath', function () {
it('works', function () {
expect(
history.createPath('/the/path')
@@ -235,7 +185,7 @@ function describeBasename(createHistory) {
})
})
- describe('in createHref', () => {
+ describe('in createHref', function () {
it('works', function () {
expect(
stripHash(history.createHref('/the/path'))
@@ -243,9 +193,9 @@ function describeBasename(createHistory) {
})
})
- describe('in push', () => {
+ describe('in push', function () {
it('works', function (done) {
- let steps = [
+ const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
@@ -271,12 +221,12 @@ function describeBasename(createHistory) {
})
})
- afterEach(() => {
+ afterEach(function () {
if (unlisten)
unlisten()
})
- after(() => {
+ after(function () {
document.head.removeChild(base)
})
diff --git a/modules/__tests__/describeGo.js b/modules/__tests__/describeGo.js
index a67b8e665..aac43bb67 100644
--- a/modules/__tests__/describeGo.js
+++ b/modules/__tests__/describeGo.js
@@ -16,7 +16,7 @@ function describeGo(createHistory) {
describe('back', function () {
it('calls change listeners with the previous location', function (done) {
- let steps = [
+ const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
@@ -51,7 +51,7 @@ function describeGo(createHistory) {
describe('forward', function () {
it('calls change listeners with the next location', function (done) {
- let steps = [
+ const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
diff --git a/modules/__tests__/describePop.js b/modules/__tests__/describePop.js
new file mode 100644
index 000000000..671008be0
--- /dev/null
+++ b/modules/__tests__/describePop.js
@@ -0,0 +1,25 @@
+function describePop(createHistory) {
+ describe('when a listenBefore hook is added', function () {
+ let history, unlisten
+
+ beforeEach(function () {
+ history = createHistory()
+ history.push('/home')
+ })
+
+ afterEach(function () {
+ if (unlisten)
+ unlisten()
+ })
+
+ it('is called when browser navigation is used', function (done) {
+ unlisten = history.listenBefore(function () {
+ done()
+ })
+
+ window.history.back()
+ })
+ })
+}
+
+export default describePop
diff --git a/modules/__tests__/describePopState.js b/modules/__tests__/describePopState.js
deleted file mode 100644
index ec8e118b1..000000000
--- a/modules/__tests__/describePopState.js
+++ /dev/null
@@ -1,48 +0,0 @@
-function describePopState(createHistory) {
- describe('when a listenBefore hook is added', function () {
- let history, unlisten
-
- beforeEach(function () {
- history = createHistory()
- history.push('/home')
- })
-
- afterEach(function () {
- if (unlisten)
- unlisten()
- })
-
- it('is called when browser navigation is used', function (done) {
- unlisten = history.listenBefore(function () {
- done()
- })
-
- window.history.back()
- })
- })
-
- describe('when a deprecated transition hook is added', function () {
- let history, listener
-
- beforeEach(function () {
- history = createHistory()
- history.push('/home')
- })
-
- afterEach(function () {
- history.unregisterTransitionHook(listener)
- })
-
- it('is called when browser navigation is used', function (done) {
- listener = function () {
- done()
- }
-
- history.registerTransitionHook(listener)
-
- window.history.back()
- })
- })
-}
-
-export default describePopState
diff --git a/modules/__tests__/describePush.js b/modules/__tests__/describePush.js
index 7dfb6bfa8..4fa41384f 100644
--- a/modules/__tests__/describePush.js
+++ b/modules/__tests__/describePush.js
@@ -16,7 +16,7 @@ function describePush(createHistory) {
describe('with a path string', function () {
it('calls change listeners with the new location', function (done) {
- let steps = [
+ const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
@@ -39,7 +39,7 @@ function describePush(createHistory) {
describe('with a path object', function () {
it('calls change listeners with the new location', function (done) {
- let steps = [
+ const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
@@ -66,7 +66,7 @@ function describePush(createHistory) {
it('correctly merges with old location', function (done) {
let oldLocation
- let steps = [
+ const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
@@ -94,7 +94,7 @@ function describePush(createHistory) {
})
it('becomes a REPLACE if path is unchanged', function (done) {
- let steps = [
+ const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
diff --git a/modules/__tests__/describePushState.js b/modules/__tests__/describePushState.js
deleted file mode 100644
index 99b15973c..000000000
--- a/modules/__tests__/describePushState.js
+++ /dev/null
@@ -1,69 +0,0 @@
-import expect from 'expect'
-import { PUSH, POP, REPLACE } from '../Actions'
-import execSteps from './execSteps'
-
-function describePushState(createHistory) {
- describe('pushState', function () {
- let history, unlisten
- beforeEach(function () {
- history = createHistory()
- })
-
- afterEach(function () {
- if (unlisten)
- unlisten()
- })
-
- it('calls change listeners with the new location', function (done) {
- let steps = [
- function (location) {
- expect(location.pathname).toEqual('/')
- expect(location.search).toEqual('')
- expect(location.state).toEqual(null)
- expect(location.action).toEqual(POP)
-
- history.pushState({ the: 'state' }, '/home?the=query')
- },
- function (location) {
- expect(location.pathname).toEqual('/home')
- expect(location.search).toEqual('?the=query')
- expect(location.state).toEqual({ the: 'state' })
- expect(location.action).toEqual(PUSH)
- }
- ]
-
- unlisten = history.listen(execSteps(steps, done))
- })
-
- it('becomes a REPLACE if path is unchanged', function (done) {
- let steps = [
- function (location) {
- expect(location.pathname).toEqual('/')
- expect(location.search).toEqual('')
- expect(location.state).toEqual(null)
- expect(location.action).toEqual(POP)
-
- history.pushState({ the: 'state' }, '/home?the=query')
- },
- function (location) {
- expect(location.pathname).toEqual('/home')
- expect(location.search).toEqual('?the=query')
- expect(location.state).toEqual({ the: 'state' })
- expect(location.action).toEqual(PUSH)
-
- history.pushState({ different: 'state' }, '/home?the=query')
- },
- function (location) {
- expect(location.pathname).toEqual('/home')
- expect(location.search).toEqual('?the=query')
- expect(location.state).toEqual({ different: 'state' })
- expect(location.action).toEqual(REPLACE)
- }
- ]
-
- unlisten = history.listen(execSteps(steps, done))
- })
- })
-}
-
-export default describePushState
diff --git a/modules/__tests__/describeQueries.js b/modules/__tests__/describeQueries.js
index c3d78fad1..308c61058 100644
--- a/modules/__tests__/describeQueries.js
+++ b/modules/__tests__/describeQueries.js
@@ -19,34 +19,9 @@ function describeQueries(createHistory) {
unlisten()
})
- describe('in pushState', function () {
- it('works', function (done) {
- let steps = [
- function (location) {
- expect(location.pathname).toEqual('/')
- expect(location.search).toEqual('')
- expect(location.query).toEqual({})
- expect(location.state).toEqual(null)
- expect(location.action).toEqual(POP)
-
- history.pushState({ the: 'state' }, '/home', { the: 'query value' })
- },
- function (location) {
- expect(location.pathname).toEqual('/home')
- expect(location.search).toEqual('?the=query+value')
- expect(location.query).toEqual({ the: 'query value' })
- expect(location.state).toEqual({ the: 'state' })
- expect(location.action).toEqual(PUSH)
- }
- ]
-
- unlisten = history.listen(execSteps(steps, done))
- })
- })
-
describe('in push', function () {
it('works', function (done) {
- let steps = [
+ const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
@@ -86,34 +61,9 @@ function describeQueries(createHistory) {
})
})
- describe('in replaceState', function () {
- it('works', function (done) {
- let steps = [
- function (location) {
- expect(location.pathname).toEqual('/')
- expect(location.search).toEqual('')
- expect(location.query).toEqual({})
- expect(location.state).toEqual(null)
- expect(location.action).toEqual(POP)
-
- history.replaceState({ the: 'state' }, '/home', { the: 'query value' })
- },
- function (location) {
- expect(location.pathname).toEqual('/home')
- expect(location.search).toEqual('?the=query+value')
- expect(location.query).toEqual({ the: 'query value' })
- expect(location.state).toEqual({ the: 'state' })
- expect(location.action).toEqual(REPLACE)
- }
- ]
-
- unlisten = history.listen(execSteps(steps, done))
- })
- })
-
describe('in replace', function () {
it('works', function (done) {
- let steps = [
+ const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
@@ -172,12 +122,6 @@ function describeQueries(createHistory) {
).toEqual('/the/path/?the=query+value')
})
- it('works with deprecated query arg', function () {
- expect(
- history.createPath('/the/path', { the: 'query value' })
- ).toEqual('/the/path?the=query+value')
- })
-
describe('when the path contains a hash', function () {
it('puts the query before the hash', function () {
expect(
@@ -189,18 +133,6 @@ function describeQueries(createHistory) {
).toEqual('/the/path?the=query+value#the-hash')
})
})
-
- describe('when there is already an existing search', function () {
- it('preserves the existing search', function () {
- expect(
- history.createPath({
- pathname: '/the/path',
- search: '?a=one',
- query: { the: 'query value' }
- })
- ).toEqual('/the/path?a=one&the=query+value')
- })
- })
})
describe('in createHref', function () {
@@ -212,12 +144,6 @@ function describeQueries(createHistory) {
}))
).toEqual('/the/path?the=query+value')
})
-
- it('works with deprecated query arg', function () {
- expect(
- stripHash(history.createHref('/the/path', { the: 'query value' }))
- ).toEqual('/the/path?the=query+value')
- })
})
})
@@ -239,34 +165,9 @@ function describeQueries(createHistory) {
unlisten()
})
- describe('in pushState', function () {
- it('works', function (done) {
- let steps = [
- function (location) {
- expect(location.pathname).toEqual('/')
- expect(location.search).toEqual('')
- expect(location.query).toEqual('PARSE_QUERY_STRING')
- expect(location.state).toEqual(null)
- expect(location.action).toEqual(POP)
-
- history.pushState({ the: 'state' }, '/home', { the: 'query' })
- },
- function (location) {
- expect(location.pathname).toEqual('/home')
- expect(location.search).toEqual('?STRINGIFY_QUERY')
- expect(location.query).toEqual('PARSE_QUERY_STRING')
- expect(location.state).toEqual({ the: 'state' })
- expect(location.action).toEqual(PUSH)
- }
- ]
-
- unlisten = history.listen(execSteps(steps, done))
- })
- })
-
describe('in push', function () {
it('works', function (done) {
- let steps = [
+ const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
@@ -293,34 +194,9 @@ function describeQueries(createHistory) {
})
})
- describe('in replaceState', function () {
- it('works', function (done) {
- let steps = [
- function (location) {
- expect(location.pathname).toEqual('/')
- expect(location.search).toEqual('')
- expect(location.query).toEqual('PARSE_QUERY_STRING')
- expect(location.state).toEqual(null)
- expect(location.action).toEqual(POP)
-
- history.replaceState({ the: 'state' }, '/home', { the: 'query' })
- },
- function (location) {
- expect(location.pathname).toEqual('/home')
- expect(location.search).toEqual('?STRINGIFY_QUERY')
- expect(location.query).toEqual('PARSE_QUERY_STRING')
- expect(location.state).toEqual({ the: 'state' })
- expect(location.action).toEqual(REPLACE)
- }
- ]
-
- unlisten = history.listen(execSteps(steps, done))
- })
- })
-
describe('in replace', function () {
it('works', function (done) {
- let steps = [
+ const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
@@ -377,18 +253,6 @@ function describeQueries(createHistory) {
).toEqual('/the/path?STRINGIFY_QUERY#the-hash')
})
})
-
- describe('when there is already an existing search', function () {
- it('preserves the existing search', function () {
- expect(
- history.createPath({
- pathname: '/the/path',
- search: '?a=one',
- query: { the: 'query' }
- })
- ).toEqual('/the/path?a=one&STRINGIFY_QUERY')
- })
- })
})
describe('in createHref', function () {
diff --git a/modules/__tests__/describeReplace.js b/modules/__tests__/describeReplace.js
index 6b7368676..7d76d0271 100644
--- a/modules/__tests__/describeReplace.js
+++ b/modules/__tests__/describeReplace.js
@@ -16,7 +16,7 @@ function describeReplace(createHistory) {
describe('with a path string', function () {
it('calls change listeners with the new location', function (done) {
- let steps = [
+ const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
@@ -39,7 +39,7 @@ function describeReplace(createHistory) {
describe('with a path object', function () {
it('calls change listeners with the new location', function (done) {
- let steps = [
+ const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
@@ -66,7 +66,7 @@ function describeReplace(createHistory) {
it('correctly merges with old location', function (done) {
let oldLocation
- let steps = [
+ const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
diff --git a/modules/__tests__/describeReplaceState.js b/modules/__tests__/describeReplaceState.js
deleted file mode 100644
index 74ec96fd5..000000000
--- a/modules/__tests__/describeReplaceState.js
+++ /dev/null
@@ -1,40 +0,0 @@
-import expect from 'expect'
-import { REPLACE, POP } from '../Actions'
-import execSteps from './execSteps'
-
-function describeReplaceState(createHistory) {
- describe('replaceState', function () {
- let history, unlisten
- beforeEach(function () {
- history = createHistory()
- })
-
- afterEach(function () {
- if (unlisten)
- unlisten()
- })
-
- it('calls change listeners with the new location', function (done) {
- let steps = [
- function (location) {
- expect(location.pathname).toEqual('/')
- expect(location.search).toEqual('')
- expect(location.state).toEqual(null)
- expect(location.action).toEqual(POP)
-
- history.replaceState({ the: 'state' }, '/home?the=query')
- },
- function (location) {
- expect(location.pathname).toEqual('/home')
- expect(location.search).toEqual('?the=query')
- expect(location.state).toEqual({ the: 'state' })
- expect(location.action).toEqual(REPLACE)
- }
- ]
-
- unlisten = history.listen(execSteps(steps, done))
- })
- })
-}
-
-export default describeReplaceState
diff --git a/modules/__tests__/describeTransitions.js b/modules/__tests__/describeTransitions.js
index c759942e4..4125542f0 100644
--- a/modules/__tests__/describeTransitions.js
+++ b/modules/__tests__/describeTransitions.js
@@ -19,7 +19,7 @@ function describeTransitions(createHistory) {
})
it('receives the next location', function (done) {
- let steps = [
+ const steps = [
function () {
history.push({
pathname: '/home',
@@ -56,7 +56,7 @@ function describeTransitions(createHistory) {
})
it('receives the next location', function (done) {
- let steps = [
+ const steps = [
function () {
history.push({
pathname: '/home',
diff --git a/modules/createBrowserHistory.js b/modules/createBrowserHistory.js
index b028657a3..81d06829d 100644
--- a/modules/createBrowserHistory.js
+++ b/modules/createBrowserHistory.js
@@ -21,14 +21,14 @@ function createBrowserHistory(options={}) {
'Browser history needs a DOM'
)
- let { forceRefresh } = options
- let isSupported = supportsHistory()
- let useRefresh = !isSupported || forceRefresh
+ const { forceRefresh, ...historyOptions } = options
+ const isSupported = supportsHistory()
+ const useRefresh = !isSupported || forceRefresh
function getCurrentLocation(historyState) {
historyState = historyState || window.history.state || {}
- let path = getWindowPath()
+ const path = getWindowPath()
let { key } = historyState
let state
@@ -94,11 +94,10 @@ function createBrowserHistory(options={}) {
}
}
- let history = createDOMHistory({
- ...options,
+ const history = createDOMHistory({
+ ...historyOptions,
getCurrentLocation,
- finishTransition,
- saveState
+ finishTransition
})
let listenerCount = 0, stopPopStateListener
@@ -131,28 +130,10 @@ function createBrowserHistory(options={}) {
}
}
- // deprecated
- function registerTransitionHook(hook) {
- if (++listenerCount === 1)
- stopPopStateListener = startPopStateListener(history)
-
- history.registerTransitionHook(hook)
- }
-
- // deprecated
- function unregisterTransitionHook(hook) {
- history.unregisterTransitionHook(hook)
-
- if (--listenerCount === 0)
- stopPopStateListener()
- }
-
return {
...history,
listenBefore,
- listen,
- registerTransitionHook,
- unregisterTransitionHook
+ listen
}
}
diff --git a/modules/createHashHistory.js b/modules/createHashHistory.js
index 64988f22a..ebac41d99 100644
--- a/modules/createHashHistory.js
+++ b/modules/createHashHistory.js
@@ -43,7 +43,7 @@ function createHashHistory(options={}) {
'Hash history needs a DOM'
)
- let { queryKey } = options
+ let { queryKey, ...historyOptions } = options
if (queryKey === undefined || !!queryKey)
queryKey = typeof queryKey === 'string' ? queryKey : DefaultQueryKey
@@ -122,11 +122,10 @@ function createHashHistory(options={}) {
}
}
- let history = createDOMHistory({
- ...options,
+ const history = createDOMHistory({
+ ...historyOptions,
getCurrentLocation,
- finishTransition,
- saveState
+ finishTransition
})
let listenerCount = 0, stopHashChangeListener
@@ -192,42 +191,6 @@ function createHashHistory(options={}) {
return '#' + history.createHref(path)
}
- // deprecated
- function registerTransitionHook(hook) {
- if (++listenerCount === 1)
- stopHashChangeListener = startHashChangeListener(history)
-
- history.registerTransitionHook(hook)
- }
-
- // deprecated
- function unregisterTransitionHook(hook) {
- history.unregisterTransitionHook(hook)
-
- if (--listenerCount === 0)
- stopHashChangeListener()
- }
-
- // deprecated
- function pushState(state, path) {
- warning(
- queryKey || state == null,
- 'You cannot use state without a queryKey it will be dropped'
- )
-
- history.pushState(state, path)
- }
-
- // deprecated
- function replaceState(state, path) {
- warning(
- queryKey || state == null,
- 'You cannot use state without a queryKey it will be dropped'
- )
-
- history.replaceState(state, path)
- }
-
return {
...history,
listenBefore,
@@ -235,12 +198,7 @@ function createHashHistory(options={}) {
push,
replace,
go,
- createHref,
-
- registerTransitionHook, // deprecated - warning is in createHistory
- unregisterTransitionHook, // deprecated - warning is in createHistory
- pushState, // deprecated - warning is in createHistory
- replaceState // deprecated - warning is in createHistory
+ createHref
}
}
diff --git a/modules/createHistory.js b/modules/createHistory.js
index 2998993dc..f9c397861 100644
--- a/modules/createHistory.js
+++ b/modules/createHistory.js
@@ -2,10 +2,8 @@
import deepEqual from 'deep-equal'
import { loopAsync } from './AsyncUtils'
import { PUSH, REPLACE, POP } from './Actions'
-import _createLocation from './createLocation'
import runTransitionHook from './runTransitionHook'
-import parsePath from './parsePath'
-import deprecate from './deprecate'
+import _createLocation from './createLocation'
function createRandomKey(length) {
return Math.random().toString(36).substr(2, length)
@@ -22,7 +20,7 @@ function locationsAreEqual(a, b) {
const DefaultKeyLength = 6
function createHistory(options={}) {
- let { getCurrentLocation, finishTransition, saveState, go, keyLength, getUserConfirmation } = options
+ let { getCurrentLocation, finishTransition, go, keyLength, getUserConfirmation } = options
if (typeof keyLength !== 'number')
keyLength = DefaultKeyLength
@@ -128,8 +126,8 @@ function createHistory(options={}) {
if (finishTransition(nextLocation) !== false)
updateLocation(nextLocation)
} else if (location && nextLocation.action === POP) {
- let prevIndex = allKeys.indexOf(location.key)
- let nextIndex = allKeys.indexOf(nextLocation.key)
+ const prevIndex = allKeys.indexOf(location.key)
+ const nextIndex = allKeys.indexOf(nextLocation.key)
if (prevIndex !== -1 && nextIndex !== -1)
go(prevIndex - nextIndex) // Restore the URL.
@@ -166,7 +164,6 @@ function createHistory(options={}) {
return location
const { pathname, search, hash } = location
-
let result = pathname
if (search)
@@ -183,67 +180,9 @@ function createHistory(options={}) {
}
function createLocation(location, action, key=createKey()) {
- if (typeof action === 'object') {
- //warning(
- // false,
- // 'The state (2nd) argument to history.createLocation is deprecated; use a ' +
- // 'location descriptor instead'
- //)
-
- if (typeof location === 'string')
- location = parsePath(location)
-
- location = { ...location, state: action }
-
- action = key
- key = arguments[3] || createKey()
- }
-
return _createLocation(location, action, key)
}
- // deprecated
- function setState(state) {
- if (location) {
- updateLocationState(location, state)
- updateLocation(location)
- } else {
- updateLocationState(getCurrentLocation(), state)
- }
- }
-
- function updateLocationState(location, state) {
- location.state = { ...location.state, ...state }
- saveState(location.key, location.state)
- }
-
- // deprecated
- function registerTransitionHook(hook) {
- if (transitionHooks.indexOf(hook) === -1)
- transitionHooks.push(hook)
- }
-
- // deprecated
- function unregisterTransitionHook(hook) {
- transitionHooks = transitionHooks.filter(item => item !== hook)
- }
-
- // deprecated
- function pushState(state, path) {
- if (typeof path === 'string')
- path = parsePath(path)
-
- push({ state, ...path })
- }
-
- // deprecated
- function replaceState(state, path) {
- if (typeof path === 'string')
- path = parsePath(path)
-
- replace({ state, ...path })
- }
-
return {
listenBefore,
listen,
@@ -256,28 +195,7 @@ function createHistory(options={}) {
createKey,
createPath,
createHref,
- createLocation,
-
- setState: deprecate(
- setState,
- 'setState is deprecated; use location.key to save state instead'
- ),
- registerTransitionHook: deprecate(
- registerTransitionHook,
- 'registerTransitionHook is deprecated; use listenBefore instead'
- ),
- unregisterTransitionHook: deprecate(
- unregisterTransitionHook,
- 'unregisterTransitionHook is deprecated; use the callback returned from listenBefore instead'
- ),
- pushState: deprecate(
- pushState,
- 'pushState is deprecated; use push instead'
- ),
- replaceState: deprecate(
- replaceState,
- 'replaceState is deprecated; use replace instead'
- )
+ createLocation
}
}
diff --git a/modules/createLocation.js b/modules/createLocation.js
index 4eb8fa9bb..c8525c22b 100644
--- a/modules/createLocation.js
+++ b/modules/createLocation.js
@@ -2,23 +2,10 @@
import { POP } from './Actions'
import parsePath from './parsePath'
-function createLocation(location='/', action=POP, key=null, _fourthArg=null) {
+function createLocation(location='/', action=POP, key=null) {
if (typeof location === 'string')
location = parsePath(location)
- if (typeof action === 'object') {
- //warning(
- // false,
- // 'The state (2nd) argument to createLocation is deprecated; use a ' +
- // 'location descriptor instead'
- //)
-
- location = { ...location, state: action }
-
- action = key || POP
- key = _fourthArg
- }
-
const pathname = location.pathname || '/'
const search = location.search || ''
const hash = location.hash || ''
diff --git a/modules/createMemoryHistory.js b/modules/createMemoryHistory.js
index 0cac8d75f..aef2eebca 100644
--- a/modules/createMemoryHistory.js
+++ b/modules/createMemoryHistory.js
@@ -4,15 +4,6 @@ import { PUSH, REPLACE, POP } from './Actions'
import createHistory from './createHistory'
import parsePath from './parsePath'
-function createStateStorage(entries) {
- return entries
- .filter(entry => entry.state)
- .reduce((memo, entry) => {
- memo[entry.key] = entry.state
- return memo
- }, {})
-}
-
function createMemoryHistory(options={}) {
if (Array.isArray(options)) {
options = { entries: options }
@@ -20,15 +11,7 @@ function createMemoryHistory(options={}) {
options = { entries: [ options ] }
}
- let history = createHistory({
- ...options,
- getCurrentLocation,
- finishTransition,
- saveState,
- go
- })
-
- let { entries, current } = options
+ let { entries, current, ...historyOptions } = options
if (typeof entries === 'string') {
entries = [ entries ]
@@ -36,20 +19,28 @@ function createMemoryHistory(options={}) {
entries = [ '/' ]
}
- entries = entries.map(function (entry) {
- let key = history.createKey()
+ const history = createHistory({
+ ...historyOptions,
+ getCurrentLocation,
+ finishTransition,
+ go
+ })
+ // Make sure entries all are valid.
+ entries = entries.map(function (entry) {
if (typeof entry === 'string')
- return { pathname: entry, key }
-
- if (typeof entry === 'object' && entry)
- return { ...entry, key }
+ entry = parsePath(entry)
invariant(
- false,
+ entry && typeof entry === 'object',
'Unable to create history entry from %s',
entry
)
+
+ return {
+ ...entry,
+ key: history.createKey()
+ }
})
if (current == null) {
@@ -62,37 +53,31 @@ function createMemoryHistory(options={}) {
)
}
- let storage = createStateStorage(entries)
-
- function saveState(key, state) {
- storage[key] = state
- }
-
- function readState(key) {
- return storage[key]
+ function getCurrentLocation() {
+ const { key, ...location } = entries[current]
+ return history.createLocation(location, undefined, key)
}
- function getCurrentLocation() {
- let entry = entries[current]
- let { key, basename, pathname, search } = entry
- let path = (basename || '') + pathname + (search || '')
-
- let state
- if (key) {
- state = readState(key)
- } else {
- state = null
- key = history.createKey()
- entry.key = key
- }
+ function finishTransition(location) {
+ switch (location.action) {
+ case PUSH:
+ current += 1
- const location = parsePath(path)
+ // If we are not on the top of stack
+ // remove rest and push a new entry.
+ if (current < entries.length)
+ entries.splice(current)
- return history.createLocation({ ...location, state }, undefined, key)
+ entries.push(location)
+ break
+ case REPLACE:
+ entries[current] = location
+ break
+ }
}
function canGo(n) {
- let index = current + n
+ const index = current + n
return index >= 0 && index < entries.length
}
@@ -109,33 +94,13 @@ function createMemoryHistory(options={}) {
current += n
- let currentLocation = getCurrentLocation()
+ const currentLocation = getCurrentLocation()
// change action to POP
history.transitionTo({ ...currentLocation, action: POP })
}
}
- function finishTransition(location) {
- switch (location.action) {
- case PUSH:
- current += 1
-
- // if we are not on the top of stack
- // remove rest and push new
- if (current < entries.length)
- entries.splice(current)
-
- entries.push(location)
- saveState(location.key, location.state)
- break
- case REPLACE:
- entries[current] = location
- saveState(location.key, location.state)
- break
- }
- }
-
return history
}
diff --git a/modules/deprecate.js b/modules/deprecate.js
deleted file mode 100644
index b4b1cbc07..000000000
--- a/modules/deprecate.js
+++ /dev/null
@@ -1,11 +0,0 @@
-//import warning from 'warning'
-
-function deprecate(fn) {
- return fn
- //return function () {
- // warning(false, '[history] ' + message)
- // return fn.apply(this, arguments)
- //}
-}
-
-export default deprecate
diff --git a/modules/enableBeforeUnload.js b/modules/enableBeforeUnload.js
deleted file mode 100644
index fefb4a855..000000000
--- a/modules/enableBeforeUnload.js
+++ /dev/null
@@ -1,7 +0,0 @@
-import deprecate from './deprecate'
-import useBeforeUnload from './useBeforeUnload'
-
-export default deprecate(
- useBeforeUnload,
- 'enableBeforeUnload is deprecated, use useBeforeUnload instead'
-)
diff --git a/modules/enableQueries.js b/modules/enableQueries.js
deleted file mode 100644
index 24c548306..000000000
--- a/modules/enableQueries.js
+++ /dev/null
@@ -1,7 +0,0 @@
-import deprecate from './deprecate'
-import useQueries from './useQueries'
-
-export default deprecate(
- useQueries,
- 'enableQueries is deprecated, use useQueries instead'
-)
diff --git a/modules/index.js b/modules/index.js
index 3c00785d3..9fb5a3132 100644
--- a/modules/index.js
+++ b/modules/index.js
@@ -7,14 +7,3 @@ export useBeforeUnload from './useBeforeUnload'
export useQueries from './useQueries'
export Actions from './Actions'
-
-// deprecated
-export enableBeforeUnload from './enableBeforeUnload'
-export enableQueries from './enableQueries'
-
-import deprecate from './deprecate'
-import _createLocation from './createLocation'
-export const createLocation = deprecate(
- _createLocation,
- 'Using createLocation without a history instance is deprecated; please use history.createLocation instead'
-)
diff --git a/modules/parsePath.js b/modules/parsePath.js
index bab2e2064..a8ba29547 100644
--- a/modules/parsePath.js
+++ b/modules/parsePath.js
@@ -12,13 +12,13 @@ function parsePath(path) {
path
)
- let hashIndex = pathname.indexOf('#')
+ const hashIndex = pathname.indexOf('#')
if (hashIndex !== -1) {
hash = pathname.substring(hashIndex)
pathname = pathname.substring(0, hashIndex)
}
- let searchIndex = pathname.indexOf('?')
+ const searchIndex = pathname.indexOf('?')
if (searchIndex !== -1) {
search = pathname.substring(searchIndex)
pathname = pathname.substring(0, searchIndex)
diff --git a/modules/useBasename.js b/modules/useBasename.js
index dc93cc474..1fde9e888 100644
--- a/modules/useBasename.js
+++ b/modules/useBasename.js
@@ -2,22 +2,22 @@ import { canUseDOM } from './ExecutionEnvironment'
import runTransitionHook from './runTransitionHook'
import extractPath from './extractPath'
import parsePath from './parsePath'
-import deprecate from './deprecate'
function useBasename(createHistory) {
return function (options={}) {
let { basename, ...historyOptions } = options
- let history = createHistory(historyOptions)
// Automatically use the value of in HTML
// documents as basename if it's not explicitly given.
if (basename == null && canUseDOM) {
- let base = document.getElementsByTagName('base')[0]
+ const base = document.getElementsByTagName('base')[0]
if (base)
basename = extractPath(base.href)
}
+ const history = createHistory(historyOptions)
+
function addBasename(location) {
if (basename && location.basename == null) {
if (location.pathname.indexOf(basename) === 0) {
@@ -65,7 +65,7 @@ function useBasename(createHistory) {
})
}
- // Override all write methods with basename-aware versions.
+ // Override all write/create methods with basename-aware versions.
function push(location) {
history.push(prependBasename(location))
}
@@ -86,22 +86,6 @@ function useBasename(createHistory) {
return addBasename(history.createLocation.apply(history, arguments))
}
- // deprecated
- function pushState(state, path) {
- if (typeof path === 'string')
- path = parsePath(path)
-
- push({ state, ...path })
- }
-
- // deprecated
- function replaceState(state, path) {
- if (typeof path === 'string')
- path = parsePath(path)
-
- replace({ state, ...path })
- }
-
return {
...history,
listenBefore,
@@ -110,16 +94,7 @@ function useBasename(createHistory) {
replace,
createPath,
createHref,
- createLocation,
-
- pushState: deprecate(
- pushState,
- 'pushState is deprecated; use push instead'
- ),
- replaceState: deprecate(
- replaceState,
- 'replaceState is deprecated; use replace instead'
- )
+ createLocation
}
}
}
diff --git a/modules/useBeforeUnload.js b/modules/useBeforeUnload.js
index 2d33fd849..3d59e6527 100644
--- a/modules/useBeforeUnload.js
+++ b/modules/useBeforeUnload.js
@@ -1,7 +1,6 @@
import warning from 'warning'
import { canUseDOM } from './ExecutionEnvironment'
import { addEventListener, removeEventListener } from './DOMUtils'
-import deprecate from './deprecate'
function startBeforeUnloadListener(getBeforeUnloadPromptMessage) {
function listener(event) {
@@ -27,7 +26,7 @@ function startBeforeUnloadListener(getBeforeUnloadPromptMessage) {
*/
function useBeforeUnload(createHistory) {
return function (options) {
- let history = createHistory(options)
+ const history = createHistory(options)
let stopBeforeUnloadListener
let beforeUnloadHooks = []
@@ -65,38 +64,9 @@ function useBeforeUnload(createHistory) {
}
}
- // deprecated
- function registerBeforeUnloadHook(hook) {
- if (canUseDOM && beforeUnloadHooks.indexOf(hook) === -1) {
- beforeUnloadHooks.push(hook)
-
- if (beforeUnloadHooks.length === 1)
- stopBeforeUnloadListener = startBeforeUnloadListener(getBeforeUnloadPromptMessage)
- }
- }
-
- // deprecated
- function unregisterBeforeUnloadHook(hook) {
- if (beforeUnloadHooks.length > 0) {
- beforeUnloadHooks = beforeUnloadHooks.filter(item => item !== hook)
-
- if (beforeUnloadHooks.length === 0)
- stopBeforeUnloadListener()
- }
- }
-
return {
...history,
- listenBeforeUnload,
-
- registerBeforeUnloadHook: deprecate(
- registerBeforeUnloadHook,
- 'registerBeforeUnloadHook is deprecated; use listenBeforeUnload instead'
- ),
- unregisterBeforeUnloadHook: deprecate(
- unregisterBeforeUnloadHook,
- 'unregisterBeforeUnloadHook is deprecated; use the callback returned from listenBeforeUnload instead'
- )
+ listenBeforeUnload
}
}
}
diff --git a/modules/useQueries.js b/modules/useQueries.js
index 1c7935e95..e2a8678c5 100644
--- a/modules/useQueries.js
+++ b/modules/useQueries.js
@@ -1,10 +1,6 @@
import warning from 'warning'
import { parse, stringify } from 'query-string'
import runTransitionHook from './runTransitionHook'
-import parsePath from './parsePath'
-import deprecate from './deprecate'
-
-const SEARCH_BASE_KEY = '$searchBase'
function defaultStringifyQuery(query) {
return stringify(query).replace(/%20/g, '+')
@@ -30,7 +26,6 @@ function isNestedObject(object) {
function useQueries(createHistory) {
return function (options={}) {
let { stringifyQuery, parseQueryString, ...historyOptions } = options
- let history = createHistory(historyOptions)
if (typeof stringifyQuery !== 'function')
stringifyQuery = defaultStringifyQuery
@@ -38,23 +33,24 @@ function useQueries(createHistory) {
if (typeof parseQueryString !== 'function')
parseQueryString = defaultParseQueryString
- function addQuery(location) {
- if (location.query == null) {
- const { search } = location
- location.query = parseQueryString(search.substring(1))
- location[SEARCH_BASE_KEY] = { search, searchBase: '' }
- }
+ const history = createHistory(historyOptions)
- // TODO: Instead of all the book-keeping here, this should just strip the
- // stringified query from the search.
+ function decodeQuery(location) {
+ if (location.query == null)
+ location.query = parseQueryString(location.search.substring(1))
return location
}
- function appendQuery(location, query) {
+ function encodeQuery(location) {
+ if (typeof location === 'string')
+ return location
+
+ const { query, ...rest } = location
+
let queryString
if (!query || (queryString = stringifyQuery(query)) === '')
- return location
+ return rest
warning(
stringifyQuery !== defaultStringifyQuery || !isNestedObject(query),
@@ -62,82 +58,46 @@ function useQueries(createHistory) {
'use a custom stringifyQuery function'
)
- if (typeof location === 'string')
- location = parsePath(location)
-
- const searchBaseSpec = location[SEARCH_BASE_KEY]
- let searchBase
- if (searchBaseSpec && location.search === searchBaseSpec.search) {
- searchBase = searchBaseSpec.searchBase
- } else {
- searchBase = location.search || ''
- }
-
- const search = searchBase + (searchBase ? '&' : '?') + queryString
+ const search = '?' + queryString
return {
- ...location,
- search,
- [SEARCH_BASE_KEY]: { search, searchBase }
+ ...rest,
+ search
}
}
// Override all read methods with query-aware versions.
function listenBefore(hook) {
return history.listenBefore(function (location, callback) {
- runTransitionHook(hook, addQuery(location), callback)
+ runTransitionHook(hook, decodeQuery(location), callback)
})
}
function listen(listener) {
return history.listen(function (location) {
- listener(addQuery(location))
+ listener(decodeQuery(location))
})
}
- // Override all write methods with query-aware versions.
+ // Override all write/create methods with query-aware versions.
function push(location) {
- history.push(appendQuery(location, location.query))
+ history.push(encodeQuery(location))
}
function replace(location) {
- history.replace(appendQuery(location, location.query))
+ history.replace(encodeQuery(location))
}
- function createPath(location, query) {
- //warning(
- // !query,
- // 'the query argument to createPath is deprecated; use a location descriptor instead'
- //)
- return history.createPath(appendQuery(location, query || location.query))
+ function createPath(location) {
+ return history.createPath(encodeQuery(location))
}
- function createHref(location, query) {
- //warning(
- // !query,
- // 'the query argument to createHref is deprecated; use a location descriptor instead'
- //)
- return history.createHref(appendQuery(location, query || location.query))
+ function createHref(location) {
+ return history.createHref(encodeQuery(location))
}
function createLocation() {
- return addQuery(history.createLocation.apply(history, arguments))
- }
-
- // deprecated
- function pushState(state, path, query) {
- if (typeof path === 'string')
- path = parsePath(path)
-
- push({ state, ...path, query })
- }
-
- // deprecated
- function replaceState(state, path, query) {
- if (typeof path === 'string')
- path = parsePath(path)
-
- replace({ state, ...path, query })
+ return decodeQuery(history.createLocation.apply(history, arguments))
}
return {
@@ -148,16 +108,7 @@ function useQueries(createHistory) {
replace,
createPath,
createHref,
- createLocation,
-
- pushState: deprecate(
- pushState,
- 'pushState is deprecated; use push instead'
- ),
- replaceState: deprecate(
- replaceState,
- 'replaceState is deprecated; use replace instead'
- )
+ createLocation
}
}
}