Commit 2b6443ba authored by Florie Guibert's avatar Florie Guibert

Roadmap - Refactor VueX action/mutation to improve performance

parent 13ee246a
......@@ -81,6 +81,7 @@ export const receiveEpicsSuccess = (
{ commit, dispatch, state, getters },
{ rawEpics, newEpic, timeframeExtended },
) => {
const epicIds = [];
const epics = rawEpics.reduce((filteredEpics, epic) => {
const formattedEpic = roadmapItemUtils.formatRoadmapItemDetails(
epic,
......@@ -100,11 +101,13 @@ export const receiveEpicsSuccess = (
newEpic,
});
filteredEpics.push(formattedEpic);
commit(types.UPDATE_EPIC_IDS, formattedEpic.id);
epicIds.push(formattedEpic.id);
}
return filteredEpics;
}, []);
commit(types.UPDATE_EPIC_IDS, epicIds);
if (timeframeExtended) {
const updatedEpics = state.epics.concat(epics);
sortEpics(updatedEpics, state.sortedBy);
......
......@@ -11,8 +11,8 @@ export default {
state.epics = epics;
},
[types.UPDATE_EPIC_IDS](state, epicId) {
state.epicIds.push(epicId);
[types.UPDATE_EPIC_IDS](state, epicIds) {
state.epicIds.push(...epicIds);
},
[types.REQUEST_EPICS](state) {
......
......@@ -94,7 +94,7 @@ describe('Roadmap Vuex Actions', () => {
},
state,
[
{ type: types.UPDATE_EPIC_IDS, payload: mockRawEpic.id },
{ type: types.UPDATE_EPIC_IDS, payload: [mockRawEpic.id] },
{
type: types.RECEIVE_EPICS_SUCCESS,
payload: [
......@@ -149,7 +149,7 @@ describe('Roadmap Vuex Actions', () => {
},
state,
[
{ type: types.UPDATE_EPIC_IDS, payload: mockRawEpic.id },
{ type: types.UPDATE_EPIC_IDS, payload: [mockRawEpic.id] },
{
type: types.RECEIVE_EPICS_FOR_TIMEFRAME_SUCCESS,
payload: [{ ...mockFormattedEpic, newEpic: true }],
......
......@@ -49,7 +49,7 @@ describe('Roadmap Store Mutations', () => {
describe('UPDATE_EPIC_IDS', () => {
it('Should insert provided epicId to epicIds array in state', () => {
mutations[types.UPDATE_EPIC_IDS](state, 22);
mutations[types.UPDATE_EPIC_IDS](state, [22]);
expect(state.epicIds).toHaveLength(1);
expect(state.epicIds[0]).toBe(22);
......
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