Skip to content

Commit

Permalink
Remove state argument from push/replace
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Oct 29, 2015
1 parent 0d97315 commit ee7bea7
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 123 deletions.
14 changes: 7 additions & 7 deletions modules/__tests__/describeBasename.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function describeBasename(createHistory) {
unlisten()
})

describe('in push', function () {
describe('in pushState', function () {
it('works', function (done) {
let steps = [
function (location) {
Expand All @@ -31,7 +31,7 @@ function describeBasename(createHistory) {
expect(location.state).toEqual(null)
expect(location.action).toEqual(POP)

history.push('/home', { the: 'state' })
history.pushState({ the: 'state' }, '/home')
},
function (location) {
expect(location.pathname).toEqual('/home')
Expand All @@ -45,7 +45,7 @@ function describeBasename(createHistory) {
})
})

describe('in pushState', function () {
describe('in push', function () {
it('works', function (done) {
let steps = [
function (location) {
Expand All @@ -54,12 +54,12 @@ function describeBasename(createHistory) {
expect(location.state).toEqual(null)
expect(location.action).toEqual(POP)

history.pushState({ the: 'state' }, '/home')
history.push('/home')
},
function (location) {
expect(location.pathname).toEqual('/home')
expect(location.search).toEqual('')
expect(location.state).toEqual({ the: 'state' })
expect(location.state).toEqual(null)
expect(location.action).toEqual(PUSH)
}
]
Expand Down Expand Up @@ -100,12 +100,12 @@ function describeBasename(createHistory) {
expect(location.state).toEqual(null)
expect(location.action).toEqual(POP)

history.replace('/home', { the: 'state' })
history.replace('/home')
},
function (location) {
expect(location.pathname).toEqual('/home')
expect(location.search).toEqual('')
expect(location.state).toEqual({ the: 'state' })
expect(location.state).toEqual(null)
expect(location.action).toEqual(REPLACE)
}
]
Expand Down
22 changes: 0 additions & 22 deletions modules/__tests__/describePush.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,6 @@ function describePush(createHistory) {
})

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.push('/home?the=query', { the: 'state' })
},
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('calls change listeners with the new location without state argument', function (done) {
let steps = [
function (location) {
expect(location.pathname).toEqual('/')
Expand All @@ -56,7 +35,6 @@ function describePush(createHistory) {

unlisten = history.listen(execSteps(steps, done))
})

})
}

Expand Down
50 changes: 0 additions & 50 deletions modules/__tests__/describeQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,6 @@ function describeQueries(createHistory) {
})
})

describe('in push', 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.push('/home', { the: 'query' }, { the: 'state' })
},
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 replaceState', function () {
it('works', function (done) {
let steps = [
Expand All @@ -102,31 +77,6 @@ function describeQueries(createHistory) {
})
})

describe('in replace', 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.replace('/home', { the: 'query' }, { the: 'state' })
},
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 createPath', function () {
it('works', function () {
expect(
Expand Down
23 changes: 1 addition & 22 deletions modules/__tests__/describeReplace.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,6 @@ function describeReplace(createHistory) {
})

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.replace('/home?the=query', { the: 'state' })
},
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))
})

it('calls change listeners with the new location without state argument', function (done) {
let steps = [
function (location) {
expect(location.pathname).toEqual('/')
Expand All @@ -49,7 +28,7 @@ function describeReplace(createHistory) {
function (location) {
expect(location.pathname).toEqual('/home')
expect(location.search).toEqual('?the=query')
expect(location.state).toEqual(null)
expect(location.state).toEqual()
expect(location.action).toEqual(REPLACE)
}
]
Expand Down
12 changes: 6 additions & 6 deletions modules/createHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,18 @@ function createHistory(options={}) {
)
}

function push(path) {
pushState(null, path)
}

function replaceState(state, path) {
transitionTo(
createLocation(path, state, REPLACE, createKey())
)
}

function push(path, state) {
pushState(state, path)
}

function replace(path, state) {
replaceState(state, path)
function replace(path) {
replaceState(null, path)
}

function goBack() {
Expand Down
12 changes: 6 additions & 6 deletions modules/useBasename.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ function useBasename(createHistory) {
history.pushState(state, prependBasename(path))
}

function replaceState(state, path) {
history.replaceState(state, prependBasename(path))
function push(path) {
pushState(null, path)
}

function push(path, state) {
pushState(state, path)
function replaceState(state, path) {
history.replaceState(state, prependBasename(path))
}

function replace(path, state) {
replaceState(state, path)
function replace(path) {
replaceState(null, path)
}

function createPath(path) {
Expand Down
10 changes: 0 additions & 10 deletions modules/useQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,6 @@ function useQueries(createHistory) {
return history.replaceState(state, appendQuery(path, query))
}

function push(path, query, state) {
return history.push(appendQuery(path, query), state)
}

function replace(path, query, state) {
return history.replace(appendQuery(path, query), state)
}

function createPath(path, query) {
return history.createPath(appendQuery(path, query))
}
Expand All @@ -96,8 +88,6 @@ function useQueries(createHistory) {
listen,
pushState,
replaceState,
push,
replace,

This comment has been minimized.

Copy link
@th0r

th0r Nov 1, 2015

@mjackson Won't push and replace support second query argument?

This comment has been minimized.

Copy link
@taion

taion Nov 1, 2015

Contributor

👍, I think they should support query as well.

This comment has been minimized.

Copy link
@robyoder

robyoder Nov 19, 2015

Documentation says they support query argument. Looks like this broke that. :/

This comment has been minimized.

Copy link
@th0r

This comment has been minimized.

Copy link
@robyoder

robyoder Nov 19, 2015

Opened #144 to track this

createPath,
createHref,
createLocation
Expand Down

0 comments on commit ee7bea7

Please sign in to comment.