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

Make UPDATE_LOCATION follow FSA #208

Merged
merged 1 commit into from
Jan 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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