Created
July 26, 2019 11:20
-
-
Save asherccohen/72b18b976330b7929af5cb826aef1cd7 to your computer and use it in GitHub Desktop.
actionCreator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function makeActionCreator(type, ...argNames) { | |
return function(...args) { | |
const action = { type } | |
argNames.forEach((arg, index) => { | |
action[argNames[index]] = args[index] | |
}) | |
return action | |
} | |
} | |
const ADD_TODO = 'ADD_TODO' | |
const EDIT_TODO = 'EDIT_TODO' | |
const REMOVE_TODO = 'REMOVE_TODO' | |
export const addTodo = makeActionCreator(ADD_TODO, 'text') | |
export const editTodo = makeActionCreator(EDIT_TODO, 'id', 'text') | |
export const removeTodo = makeActionCreator(REMOVE_TODO, 'id') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment