Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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;
15 changes: 15 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
});