1 | import warning from './utils/warning';
|
2 |
|
3 | function bindActionCreator(actionCreator, dispatch) {
|
4 | return function () {
|
5 | return dispatch(actionCreator.apply(undefined, arguments));
|
6 | };
|
7 | }
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | export default function bindActionCreators(actionCreators, dispatch) {
|
31 | if (typeof actionCreators === 'function') {
|
32 | return bindActionCreator(actionCreators, dispatch);
|
33 | }
|
34 |
|
35 | if (typeof actionCreators !== 'object' || actionCreators === null) {
|
36 | throw new Error('bindActionCreators expected an object or a function, instead received ' + (actionCreators === null ? 'null' : typeof actionCreators) + '. ' + 'Did you write "import ActionCreators from" instead of "import * as ActionCreators from"?');
|
37 | }
|
38 |
|
39 | var keys = Object.keys(actionCreators);
|
40 | var boundActionCreators = {};
|
41 | for (var i = 0; i < keys.length; i++) {
|
42 | var key = keys[i];
|
43 | var actionCreator = actionCreators[key];
|
44 | if (typeof actionCreator === 'function') {
|
45 | boundActionCreators[key] = bindActionCreator(actionCreator, dispatch);
|
46 | } else {
|
47 | warning('bindActionCreators expected a function actionCreator for key \'' + key + '\', instead received type \'' + typeof actionCreator + '\'.');
|
48 | }
|
49 | }
|
50 | return boundActionCreators;
|
51 | } |
\ | No newline at end of file |