Skip to content

Instantly share code, notes, and snippets.

@nitta-honoka
Created April 14, 2016 15:20
Show Gist options
  • Select an option

  • Save nitta-honoka/3a7b566f878ee84c7c54672b0b56a625 to your computer and use it in GitHub Desktop.

Select an option

Save nitta-honoka/3a7b566f878ee84c7c54672b0b56a625 to your computer and use it in GitHub Desktop.
redux action creator 生成函数
function makeActionCreator(type, ...argNames) {
return function(...args) {
let 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, 'todo')
export const editTodo = makeActionCreator(EDIT_TODO, 'id', 'todo')
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