diff --git a/src/index.js b/src/index.js index ee5902a..6222d72 100644 --- a/src/index.js +++ b/src/index.js @@ -1,9 +1,14 @@ -export default function thunkMiddleware({ dispatch, getState }) { - return next => action => { +function createThunkMiddleware(extraArgument) { + return ({ dispatch, getState }) => next => action => { if (typeof action === 'function') { - return action(dispatch, getState); + return action(dispatch, getState, extraArgument); } return next(action); }; } + +const thunk = createThunkMiddleware(); +thunk.withExtraArgument = createThunkMiddleware; + +export default thunk; diff --git a/test/index.js b/test/index.js index 76bab4c..7185d12 100644 --- a/test/index.js +++ b/test/index.js @@ -76,4 +76,19 @@ describe('thunk middleware', () => { } }); }); + + describe('withExtraArgument', () => { + it('must pass the third argument', done => { + const extraArg = { lol: true }; + thunkMiddleware.withExtraArgument(extraArg)({ + dispatch: doDispatch, + getState: doGetState, + })()((dispatch, getState, arg) => { + chai.assert.strictEqual(dispatch, doDispatch); + chai.assert.strictEqual(getState, doGetState); + chai.assert.strictEqual(arg, extraArg); + done(); + }); + }); + }); });