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

Commit 37e95e7

Browse files
committed
Merge pull request #208 from SimenB/patch-1
Make UPDATE_LOCATION follow FSA
2 parents 8691686 + 2e00f61 commit 37e95e7

File tree

2 files changed

+38
-24
lines changed

2 files changed

+38
-24
lines changed

src/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const SELECT_STATE = state => state.routing
88
function transition(method) {
99
return arg => ({
1010
type: TRANSITION,
11-
method, arg
11+
payload: { method, arg }
1212
})
1313
}
1414

@@ -23,7 +23,7 @@ export const routeActions = {
2323
function updateLocation(location) {
2424
return {
2525
type: UPDATE_LOCATION,
26-
location
26+
payload: location
2727
}
2828
}
2929

@@ -33,7 +33,7 @@ const initialState = {
3333
location: undefined
3434
}
3535

36-
export function routeReducer(state = initialState, { type, location }) {
36+
export function routeReducer(state = initialState, { type, payload: location }) {
3737
if (type !== UPDATE_LOCATION) {
3838
return state
3939
}
@@ -65,7 +65,7 @@ export function syncHistory(history) {
6565
return next(action)
6666
}
6767

68-
const { method, arg } = action
68+
const { payload: { method, arg } } = action
6969
history[method](arg)
7070
}
7171
}

test/createTests.js

+34-20
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,20 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
5555
it('creates actions', () => {
5656
expect(push('/foo')).toEqual({
5757
type: TRANSITION,
58-
method: 'push',
59-
arg: '/foo'
58+
payload: {
59+
method: 'push',
60+
arg: '/foo'
61+
}
6062
})
6163

6264
expect(push({ pathname: '/foo', state: { the: 'state' } })).toEqual({
6365
type: TRANSITION,
64-
method: 'push',
65-
arg: {
66-
pathname: '/foo',
67-
state: { the: 'state' }
66+
payload: {
67+
method: 'push',
68+
arg: {
69+
pathname: '/foo',
70+
state: { the: 'state' }
71+
}
6872
}
6973
})
7074
})
@@ -74,16 +78,20 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
7478
it('creates actions', () => {
7579
expect(replace('/foo')).toEqual({
7680
type: TRANSITION,
77-
method: 'replace',
78-
arg: '/foo'
81+
payload: {
82+
method: 'replace',
83+
arg: '/foo'
84+
}
7985
})
8086

8187
expect(replace({ pathname: '/foo', state: { the: 'state' } })).toEqual({
8288
type: TRANSITION,
83-
method: 'replace',
84-
arg: {
85-
pathname: '/foo',
86-
state: { the: 'state' }
89+
payload: {
90+
method: 'replace',
91+
arg: {
92+
pathname: '/foo',
93+
state: { the: 'state' }
94+
}
8795
}
8896
})
8997
})
@@ -93,8 +101,10 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
93101
it('creates actions', () => {
94102
expect(go(1)).toEqual({
95103
type: TRANSITION,
96-
method: 'go',
97-
arg: 1
104+
payload: {
105+
method: 'go',
106+
arg: 1
107+
}
98108
})
99109
})
100110
})
@@ -103,8 +113,10 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
103113
it('creates actions', () => {
104114
expect(goBack()).toEqual({
105115
type: TRANSITION,
106-
method: 'goBack',
107-
arg: undefined
116+
payload: {
117+
method: 'goBack',
118+
arg: undefined
119+
}
108120
})
109121
})
110122
})
@@ -113,8 +125,10 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
113125
it('creates actions', () => {
114126
expect(goForward()).toEqual({
115127
type: TRANSITION,
116-
method: 'goForward',
117-
arg: undefined
128+
payload: {
129+
method: 'goForward',
130+
arg: undefined
131+
}
118132
})
119133
})
120134
})
@@ -132,7 +146,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
132146
it('updates the path', () => {
133147
expect(routeReducer(state, {
134148
type: UPDATE_LOCATION,
135-
location: {
149+
payload: {
136150
path: '/bar',
137151
action: 'PUSH'
138152
}
@@ -147,7 +161,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
147161
it('respects replace', () => {
148162
expect(routeReducer(state, {
149163
type: UPDATE_LOCATION,
150-
location: {
164+
payload: {
151165
path: '/bar',
152166
action: 'REPLACE'
153167
}

0 commit comments

Comments
 (0)