Commit c4381067 authored by Filipa Lacerda's avatar Filipa Lacerda

[ci skip] Improve performance of getting last note

parent 3e0a76da
import _ from 'underscore';
export const notes = state => state.notes; export const notes = state => state.notes;
export const targetNoteHash = state => state.targetNoteHash; export const targetNoteHash = state => state.targetNoteHash;
...@@ -16,15 +18,11 @@ export const notesById = state => state.notes.reduce((acc, note) => { ...@@ -16,15 +18,11 @@ export const notesById = state => state.notes.reduce((acc, note) => {
}, {}); }, {});
const reverseNotes = array => array.slice(0).reverse(); const reverseNotes = array => array.slice(0).reverse();
const isLastNote = (note, userId) => !note.system && note.author.id === userId; const isLastNote = (note, state) => !note.system && note.author.id === state.userData.id;
export const getCurrentUserLastNote = state => userId => reverseNotes(state.notes)
.reduce((acc, note) => {
acc.push(reverseNotes(note.notes).find(el => isLastNote(el, userId)));
return acc;
}, []).filter(el => el !== undefined)[0];
// eslint-disable-next-line no-unused-vars export const getCurrentUserLastNote = state => _.flatten(reverseNotes(state.notes)
export const getDiscussionLastNote = state => (discussion, userId) => reverseNotes(discussion.notes) .map(note => note.notes))
.find(el => isLastNote(el, userId)); .find(el => isLastNote(el, state));
export const getDiscussionLastNote = state => discussion => reverseNotes(discussion.notes)
.find(el => isLastNote(el, state));
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