From 524898b50cc4c4f1395eba9c3b3cf81b24bc7214 Mon Sep 17 00:00:00 2001 From: Tim Dorr Date: Sat, 30 Jan 2016 20:40:04 -0500 Subject: [PATCH] Support any number of args on action creators. Fixes #187 --- src/index.js | 8 ++++---- test/createTests.js | 26 +++++++++++++++++--------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/index.js b/src/index.js index 654b599..75bba7e 100644 --- a/src/index.js +++ b/src/index.js @@ -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 } }) } @@ -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) } } diff --git a/test/createTests.js b/test/createTests.js index d54fc6d..dcfbfad 100644 --- a/test/createTests.js +++ b/test/createTests.js @@ -58,7 +58,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) type: TRANSITION, payload: { method: 'push', - arg: '/foo' + args: [ '/foo' ] } }) @@ -66,10 +66,18 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) 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 ] } }) }) @@ -81,7 +89,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) type: TRANSITION, payload: { method: 'replace', - arg: '/foo' + args: [ '/foo' ] } }) @@ -89,10 +97,10 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) type: TRANSITION, payload: { method: 'replace', - arg: { + args: [ { pathname: '/foo', state: { the: 'state' } - } + } ] } }) }) @@ -104,7 +112,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) type: TRANSITION, payload: { method: 'go', - arg: 1 + args: [ 1 ] } }) }) @@ -116,7 +124,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) type: TRANSITION, payload: { method: 'goBack', - arg: undefined + args: [] } }) }) @@ -128,7 +136,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) type: TRANSITION, payload: { method: 'goForward', - arg: undefined + args: [] } }) })