Advertisement
Guest User

Comments

a guest
Mar 9th, 2018
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. export const state = {
  2. comments: []
  3. }
  4.  
  5. export const mutations = {
  6. ADD_COMMENTS (state, comments) {
  7. state.comments.push(...comments)
  8. },
  9. ADD_COMMENT (state, comment) {
  10. if(comment.reply) {
  11. let c = state.comments.find((c) => c.id === comment.reply)
  12. if(c.replies === undefined) {
  13. c.replies = []
  14. }
  15. c.replies.push(comment)
  16. }else{
  17. state.comments.push(comment)
  18. }
  19. },
  20. DELETE_COMMENT (state, comment) {
  21. if(comment.reply){
  22. let parent = state.comments.find((c) => c.id === comment.reply)
  23. let index = parent.replies.findIndex((c) => c.id === comment.id)
  24. parent.replies.splice(index, 1)
  25. }else{
  26. let index = state.comments.findIndex((c) => c.id === comment.id)
  27. state.comments.splice(index, 1)
  28. }
  29. }
  30. }
  31.  
  32. export default {
  33. state,
  34. mutations,
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement