Skip to content

Commit

Permalink
refactor(makeactioncreator): set actionCreator's data under 'payload'…
Browse files Browse the repository at this point in the history
… property

improves #35
  • Loading branch information
aneurysmjs committed Sep 26, 2019
1 parent 0c1e9c3 commit 80606c9
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/app/store/helpers/makeActionCreator/makeActionCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ type ActionCreatorType = <T>(T | Array<T>) => ActionType;
function makeActionCreator(type: string, ...argNames: Array<string>): ActionCreatorType {
return function actionCreator(...args) {
const action = { type };
argNames.forEach((arg, index) => {
action[argNames[index]] = args[index];
});
return action;
return argNames.reduce((current, arg, index) => {
const currentAction = {
...current,
payload: {
[argNames[index]]: args[index],
},
};
return currentAction;
}, action);
};
}

Expand Down

0 comments on commit 80606c9

Please sign in to comment.