Skip to content
This repository has been archived by the owner on Oct 26, 2018. It is now read-only.

Commit

Permalink
Merge pull request #208 from SimenB/patch-1
Browse files Browse the repository at this point in the history
Make UPDATE_LOCATION follow FSA
  • Loading branch information
timdorr committed Jan 17, 2016
2 parents 8691686 + 2e00f61 commit 37e95e7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const SELECT_STATE = state => state.routing
function transition(method) {
return arg => ({
type: TRANSITION,
method, arg
payload: { method, arg }
})
}

Expand All @@ -23,7 +23,7 @@ export const routeActions = {
function updateLocation(location) {
return {
type: UPDATE_LOCATION,
location
payload: location
}
}

Expand All @@ -33,7 +33,7 @@ const initialState = {
location: undefined
}

export function routeReducer(state = initialState, { type, location }) {
export function routeReducer(state = initialState, { type, payload: location }) {
if (type !== UPDATE_LOCATION) {
return state
}
Expand Down Expand Up @@ -65,7 +65,7 @@ export function syncHistory(history) {
return next(action)
}

const { method, arg } = action
const { payload: { method, arg } } = action
history[method](arg)
}
}
Expand Down
54 changes: 34 additions & 20 deletions test/createTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,20 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
it('creates actions', () => {
expect(push('/foo')).toEqual({
type: TRANSITION,
method: 'push',
arg: '/foo'
payload: {
method: 'push',
arg: '/foo'
}
})

expect(push({ pathname: '/foo', state: { the: 'state' } })).toEqual({
type: TRANSITION,
method: 'push',
arg: {
pathname: '/foo',
state: { the: 'state' }
payload: {
method: 'push',
arg: {
pathname: '/foo',
state: { the: 'state' }
}
}
})
})
Expand All @@ -74,16 +78,20 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
it('creates actions', () => {
expect(replace('/foo')).toEqual({
type: TRANSITION,
method: 'replace',
arg: '/foo'
payload: {
method: 'replace',
arg: '/foo'
}
})

expect(replace({ pathname: '/foo', state: { the: 'state' } })).toEqual({
type: TRANSITION,
method: 'replace',
arg: {
pathname: '/foo',
state: { the: 'state' }
payload: {
method: 'replace',
arg: {
pathname: '/foo',
state: { the: 'state' }
}
}
})
})
Expand All @@ -93,8 +101,10 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
it('creates actions', () => {
expect(go(1)).toEqual({
type: TRANSITION,
method: 'go',
arg: 1
payload: {
method: 'go',
arg: 1
}
})
})
})
Expand All @@ -103,8 +113,10 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
it('creates actions', () => {
expect(goBack()).toEqual({
type: TRANSITION,
method: 'goBack',
arg: undefined
payload: {
method: 'goBack',
arg: undefined
}
})
})
})
Expand All @@ -113,8 +125,10 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
it('creates actions', () => {
expect(goForward()).toEqual({
type: TRANSITION,
method: 'goForward',
arg: undefined
payload: {
method: 'goForward',
arg: undefined
}
})
})
})
Expand All @@ -132,7 +146,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
it('updates the path', () => {
expect(routeReducer(state, {
type: UPDATE_LOCATION,
location: {
payload: {
path: '/bar',
action: 'PUSH'
}
Expand All @@ -147,7 +161,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
it('respects replace', () => {
expect(routeReducer(state, {
type: UPDATE_LOCATION,
location: {
payload: {
path: '/bar',
action: 'REPLACE'
}
Expand Down

0 comments on commit 37e95e7

Please sign in to comment.