-
-
Save vasanthk/08d52f8709ee43fbb04a to your computer and use it in GitHub Desktop.
Succinct declaration of redux actions
This file contains 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
let addTask, | |
removeTask; | |
addTask = (data) => { | |
return { | |
type: 'ADD_TASK', | |
data: data | |
}; | |
}; | |
removeTask = (data) => { | |
return { | |
type: 'REMOVE_TASK', | |
data: data | |
} | |
}; | |
export { | |
addTask, | |
removeTask | |
}; |
This file contains 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
let actions; | |
actions.addTask = (data) => { | |
return { | |
type: 'ADD_TASK', | |
data: data | |
}; | |
}; | |
actions.removeTask = (data) => { | |
return { | |
type: 'REMOVE_TASK', | |
data: data | |
}; | |
}; | |
export default actions; |
This file contains 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
/** | |
* Hypothetical function that uses object key to derive type (addTask => ADD_TASK) | |
* and adds "type" property to the result of the function. | |
*/ | |
import giveType from './giveType'; | |
let actions; | |
actions.addTask = (data) => { | |
return { | |
data: data | |
}; | |
}; | |
actions.removeTask = (data) => { | |
return { | |
data: data | |
}; | |
}; | |
export default giveType(actions); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment