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

Commit 524898b

Browse files
committed
Support any number of args on action creators.
Fixes #187
1 parent 0f85508 commit 524898b

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

src/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ export const UPDATE_LOCATION = '@@router/UPDATE_LOCATION'
66
const SELECT_LOCATION = state => state.routing.location
77

88
function transition(method) {
9-
return arg => ({
9+
return (...args) => ({
1010
type: TRANSITION,
11-
payload: { method, arg }
11+
payload: { method, args }
1212
})
1313
}
1414

@@ -65,8 +65,8 @@ export function syncHistory(history) {
6565
return next(action)
6666
}
6767

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

test/createTests.js

+17-9
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,26 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
5858
type: TRANSITION,
5959
payload: {
6060
method: 'push',
61-
arg: '/foo'
61+
args: [ '/foo' ]
6262
}
6363
})
6464

6565
expect(push({ pathname: '/foo', state: { the: 'state' } })).toEqual({
6666
type: TRANSITION,
6767
payload: {
6868
method: 'push',
69-
arg: {
69+
args: [ {
7070
pathname: '/foo',
7171
state: { the: 'state' }
72-
}
72+
} ]
73+
}
74+
})
75+
76+
expect(push('/foo', 'baz', 123)).toEqual({
77+
type: TRANSITION,
78+
payload: {
79+
method: 'push',
80+
args: [ '/foo' , 'baz', 123 ]
7381
}
7482
})
7583
})
@@ -81,18 +89,18 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
8189
type: TRANSITION,
8290
payload: {
8391
method: 'replace',
84-
arg: '/foo'
92+
args: [ '/foo' ]
8593
}
8694
})
8795

8896
expect(replace({ pathname: '/foo', state: { the: 'state' } })).toEqual({
8997
type: TRANSITION,
9098
payload: {
9199
method: 'replace',
92-
arg: {
100+
args: [ {
93101
pathname: '/foo',
94102
state: { the: 'state' }
95-
}
103+
} ]
96104
}
97105
})
98106
})
@@ -104,7 +112,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
104112
type: TRANSITION,
105113
payload: {
106114
method: 'go',
107-
arg: 1
115+
args: [ 1 ]
108116
}
109117
})
110118
})
@@ -116,7 +124,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
116124
type: TRANSITION,
117125
payload: {
118126
method: 'goBack',
119-
arg: undefined
127+
args: []
120128
}
121129
})
122130
})
@@ -128,7 +136,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
128136
type: TRANSITION,
129137
payload: {
130138
method: 'goForward',
131-
arg: undefined
139+
args: []
132140
}
133141
})
134142
})

0 commit comments

Comments
 (0)