Skip to content

Instantly share code, notes, and snippets.

@asherccohen
Created July 26, 2019 11:20
Show Gist options
  • Save asherccohen/72b18b976330b7929af5cb826aef1cd7 to your computer and use it in GitHub Desktop.
Save asherccohen/72b18b976330b7929af5cb826aef1cd7 to your computer and use it in GitHub Desktop.
actionCreator
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