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

Commit

Permalink
Support any number of args on action creators.
Browse files Browse the repository at this point in the history
Fixes #187
  • Loading branch information
timdorr committed Jan 31, 2016
1 parent 0f85508 commit 524898b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export const UPDATE_LOCATION = '@@router/UPDATE_LOCATION'
const SELECT_LOCATION = state => state.routing.location

function transition(method) {
return arg => ({
return (...args) => ({
type: TRANSITION,
payload: { method, arg }
payload: { method, args }
})
}

Expand Down Expand Up @@ -65,8 +65,8 @@ export function syncHistory(history) {
return next(action)
}

const { payload: { method, arg } } = action
history[method](arg)
const { payload: { method, args } } = action
history[method](...args)
}
}

Expand Down
26 changes: 17 additions & 9 deletions test/createTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,26 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
type: TRANSITION,
payload: {
method: 'push',
arg: '/foo'
args: [ '/foo' ]
}
})

expect(push({ pathname: '/foo', state: { the: 'state' } })).toEqual({
type: TRANSITION,
payload: {
method: 'push',
arg: {
args: [ {
pathname: '/foo',
state: { the: 'state' }
}
} ]
}
})

expect(push('/foo', 'baz', 123)).toEqual({
type: TRANSITION,
payload: {
method: 'push',
args: [ '/foo' , 'baz', 123 ]
}
})
})
Expand All @@ -81,18 +89,18 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
type: TRANSITION,
payload: {
method: 'replace',
arg: '/foo'
args: [ '/foo' ]
}
})

expect(replace({ pathname: '/foo', state: { the: 'state' } })).toEqual({
type: TRANSITION,
payload: {
method: 'replace',
arg: {
args: [ {
pathname: '/foo',
state: { the: 'state' }
}
} ]
}
})
})
Expand All @@ -104,7 +112,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
type: TRANSITION,
payload: {
method: 'go',
arg: 1
args: [ 1 ]
}
})
})
Expand All @@ -116,7 +124,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
type: TRANSITION,
payload: {
method: 'goBack',
arg: undefined
args: []
}
})
})
Expand All @@ -128,7 +136,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
type: TRANSITION,
payload: {
method: 'goForward',
arg: undefined
args: []
}
})
})
Expand Down

0 comments on commit 524898b

Please sign in to comment.