Guest User

Untitled

a guest
Jan 22nd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. class List extends Component {
  2. render() {
  3.  
  4. //code
  5. }
  6. return(
  7. <Aux>
  8. <Button
  9. type="button"
  10. click={() => this.props.addNew(data)}
  11. btnType="add" >
  12. Add
  13. </Button>
  14. <Button
  15. type="button"
  16. click={() => this.props.deleteB(id, type)}
  17. btnType="Delete" >
  18. Delete
  19. </Button>
  20. <Button
  21. type="button"
  22. click={() => this.props.editStart(id)}
  23. btnType="edit" >
  24. Edit
  25. </Button>
  26. <Button
  27. type="button"
  28. click={() => this.props.editSave(data, type)}
  29. btnType="save" >
  30. save
  31. </Button>
  32. </Aux>
  33. )
  34. }
  35.  
  36. const mapStateToProps = state => {
  37. return {
  38. editing: state.list.editing
  39. };
  40. };
  41.  
  42. const mapDispatchtoProps = dispatch => {
  43. return {
  44. deleteB: (id, type) => {dispatch(actions.deleteB(id, type))},
  45. editStart: (id) => {dispatch(actions.editStart(id))},
  46. editSave: (data, type) => {dispatch(actions.editSave(data, type))},
  47. addNew: (data) => dispatch(actions.addNew(data))
  48. };
  49. };
  50.  
  51. export default connect(mapStateToProps, mapDispatchtoProps)(List);
  52.  
  53. const addNew = ( state, action ) => {
  54. //immutable state
  55. //add new
  56. //return updated state
  57. };
  58.  
  59. const deleteB = ( state, action ) => {
  60. //immutable state
  61. //delete
  62. //return updated state
  63. };
  64.  
  65. const editStart = ( state, action ) => {
  66. //immutable state
  67. //update editing to true
  68. //return updated state
  69. };
  70.  
  71. const editSave = ( state, action ) => {
  72. //immutable state
  73. if(action.type === state.editing.type) {
  74. //update object with user data
  75. } else {
  76. //delete old data same code of deleteB
  77. //add data user like addNew
  78. //update editing to false
  79. }
  80. //return updated state
  81. };
  82.  
  83. const reducer = ( state = initialState, action ) => {
  84. //switch case
  85. };
  86.  
  87. export default reducer;
Add Comment
Please, Sign In to add comment