Skip to content

Commit 2f405ee

Browse files
committed
Merge pull request #70 from gaearon/with-extra-argument
Add withExtraArgument()
2 parents e0773ff + 41aefcc commit 2f405ee

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
export default function thunkMiddleware({ dispatch, getState }) {
2-
return next => action => {
1+
function createThunkMiddleware(extraArgument) {
2+
return ({ dispatch, getState }) => next => action => {
33
if (typeof action === 'function') {
4-
return action(dispatch, getState);
4+
return action(dispatch, getState, extraArgument);
55
}
66

77
return next(action);
88
};
99
}
10+
11+
const thunk = createThunkMiddleware();
12+
thunk.withExtraArgument = createThunkMiddleware;
13+
14+
export default thunk;

test/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,19 @@ describe('thunk middleware', () => {
7676
}
7777
});
7878
});
79+
80+
describe('withExtraArgument', () => {
81+
it('must pass the third argument', done => {
82+
const extraArg = { lol: true };
83+
thunkMiddleware.withExtraArgument(extraArg)({
84+
dispatch: doDispatch,
85+
getState: doGetState,
86+
})()((dispatch, getState, arg) => {
87+
chai.assert.strictEqual(dispatch, doDispatch);
88+
chai.assert.strictEqual(getState, doGetState);
89+
chai.assert.strictEqual(arg, extraArg);
90+
done();
91+
});
92+
});
93+
});
7994
});

0 commit comments

Comments
 (0)