Created
April 14, 2016 15:20
-
-
Save nitta-honoka/3a7b566f878ee84c7c54672b0b56a625 to your computer and use it in GitHub Desktop.
redux action creator 生成函数
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) { | |
| 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