Skip to content

Commit 9c41dfc

Browse files
fix open and close action problems in reducer.js
(they was mutating current state)
1 parent b1a7feb commit 9c41dfc

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/utils/stateManagement/reducer.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ export default function reducer(state, action) {
66
{
77
const { openTabIDs: arr } = state, removedItemIndex = arr.indexOf(action.tabId);
88
if (removedItemIndex >= 0) {
9-
arr.splice(removedItemIndex, 1);
10-
return helper.getCopyState(state);
9+
const newArr = arr.slice();
10+
newArr.splice(removedItemIndex, 1);
11+
return { selectedTabID: state.selectedTabID, openTabIDs: newArr };
1112
}
1213
return state;
1314
}
1415
case actions.open:
1516
{
1617
const arr = state.openTabIDs, tabId = action.tabId;
1718
if (arr.indexOf(tabId) === -1) {
18-
arr.push(tabId);
19-
return helper.getCopyState(state);
19+
const newArr = arr.slice();
20+
newArr.push(tabId);
21+
return { selectedTabID: state.selectedTabID, openTabIDs: newArr };
2022
}
2123
return state;
2224
}

0 commit comments

Comments
 (0)