Skip to content

Commit 3c66821

Browse files
committed
Add action creator generator helper as a lib
1 parent 0387464 commit 3c66821

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* Generates an action creator.
2+
* @param type [String] The action type as a constant, e.g. ADD_TODO
3+
* @param [...propNames] [String] The string name of each action property as arguments
4+
* @return [Object] The action creator.
5+
* @example
6+
*/
7+
8+
export default function generateActionCreator(type, ...propNames) {
9+
return function actionCreator(...args) {
10+
const actionProps = {};
11+
12+
propNames.forEach((prop, idx) => {
13+
actionProps[prop] = args[idx];
14+
});
15+
16+
return { type, ...actionProps };
17+
};
18+
}

0 commit comments

Comments
 (0)