Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. ## Change one property
  2.  
  3. ES6
  4.  
  5. ```js
  6. return {
  7. ...state,
  8. [productId]: (state[productId] || 0) + 1
  9. }
  10. ```
  11.  
  12. SI
  13.  
  14. ```js
  15. return state.merge({
  16. [productId]: (state[productId] || 0) + 1
  17. })
  18. ```
  19.  
  20. ## Change one prop of object in array
  21.  
  22. ES6
  23.  
  24. ```js
  25. case EDIT_TODO:
  26. return state.map(todo =>
  27. todo.id === action.id ?
  28. Object.assign({}, todo, { text: action.text }) :
  29. todo
  30. )
  31. ```
  32.  
  33. SI
  34. ```js
  35. case EDIT_TODO:
  36. return state.map(todo =>
  37. todo.id === action.id ?
  38. todo.merge(text: action.text) :
  39. todo
  40. )
  41. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement