Skip to content

Commit 2f2be5f

Browse files
committed
refactor acc reducer to not alter the state
1 parent b123f4f commit 2f2be5f

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/context/reducers/accTestCaseReducer.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,27 +90,31 @@ export const accTestCaseReducer = (state, action) => {
9090
}
9191
case actionTypes.DELETE_DESCRIBE_BLOCK: {
9292
const { describeId } = action;
93+
const newDescById = { ...describeBlocks.byId };
94+
const newItById = { ...itStatements.byId };
95+
const newItAllIds = { ...itStatements.allIds };
9396

9497
// delete it from describeBlocks.byId
95-
delete describeBlocks.byId[describeId];
98+
delete newDescById[describeId];
9699
// delete it from describeBlocks.allIds
97-
const newAllIds = describeBlocks.allIds.filter((id) => id !== describeId);
100+
const newDescAllIds = describeBlocks.allIds.filter((id) => id !== describeId);
98101

99102
// delete from itStatements.byId
100103
itStatements.allIds[describeId].forEach((itId) => {
101-
delete itStatements.byId[itId];
104+
delete newItById[itId];
102105
});
103106
// delete from itStatements.allIds
104-
delete itStatements.allIds[describeId];
107+
delete newItAllIds[describeId];
105108

106109
return {
107110
...state,
108111
describeBlocks: {
109-
...describeBlocks,
110-
allIds: newAllIds,
112+
byIds: newDescById,
113+
allIds: newDescAllIds,
111114
},
112115
itStatements: {
113-
...itStatements,
116+
byIds: newItById,
117+
allIds: newItAllIds,
114118
},
115119
};
116120
}

0 commit comments

Comments
 (0)