Commit a3dcc968 authored by Alexander Turinske's avatar Alexander Turinske

Refactor code to be more readable

- rename discussionLookup to discussonDictionary
- rename noteLookup to noteDictionary
parent 4c9b0bd7
...@@ -43,13 +43,13 @@ export default { ...@@ -43,13 +43,13 @@ export default {
}), }),
computed: { computed: {
discussionLookup() { discussionDictionary() {
return this.discussions.reduce((acc, discussion) => { return this.discussions.reduce((acc, discussion) => {
acc[discussion.id] = discussion; acc[discussion.id] = discussion;
return acc; return acc;
}, {}); }, {});
}, },
noteLookup() { noteDictionary() {
return this.discussions return this.discussions
.flatMap(x => x.notes) .flatMap(x => x.notes)
.reduce((acc, note) => { .reduce((acc, note) => {
...@@ -126,12 +126,12 @@ export default { ...@@ -126,12 +126,12 @@ export default {
updateNotes(notes) { updateNotes(notes) {
notes.forEach(note => { notes.forEach(note => {
// If the note exists, update it. // If the note exists, update it.
if (this.noteLookup[note.id]) { if (this.noteDictionary[note.id]) {
Object.assign(this.noteLookup[note.id], note); Object.assign(this.noteDictionary[note.id], note);
} }
// If the note doesn't exist, but the discussion does, add the note to the discussion. // If the note doesn't exist, but the discussion does, add the note to the discussion.
else if (this.discussionLookup[note.discussion_id]) { else if (this.discussionDictionary[note.discussion_id]) {
this.discussionLookup[note.discussion_id].notes.push(note); this.discussionDictionary[note.discussion_id].notes.push(note);
} }
// If the discussion doesn't exist, create it. // If the discussion doesn't exist, create it.
else { else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment