We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0387464 commit 3c66821Copy full SHA for 3c66821
common/js/lib/generateActionCreator.js
@@ -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