Skip to content

Commit 1548dd5

Browse files
committed
fix: SET_FUNCTIONS reducer mutates state in-place (#335)
1 parent 8c67e34 commit 1548dd5

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/reducer/reducer.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,17 @@ const reducer = (state, action) => {
234234

235235
case T.SET_FUNCTIONS: {
236236
const newState = { ...state };
237-
newState.graphs[state.curGraphIndex].built = action.payload.built;
238-
newState.graphs[state.curGraphIndex].debugged = action.payload.debugged;
239-
newState.graphs[state.curGraphIndex].ran = action.payload.ran;
240-
newState.graphs[state.curGraphIndex].cleared = action.payload.cleared;
241-
newState.graphs[state.curGraphIndex].destroyed = action.payload.destroyed;
242-
newState.graphs[state.curGraphIndex].stopped = action.payload.stopped;
237+
newState.graphs = newState.graphs.map((g, index) => (
238+
index === state.curGraphIndex ? {
239+
...g,
240+
built: action.payload.built,
241+
debugged: action.payload.debugged,
242+
ran: action.payload.ran,
243+
cleared: action.payload.cleared,
244+
destroyed: action.payload.destroyed,
245+
stopped: action.payload.stopped,
246+
} : g
247+
));
243248
return { ...newState };
244249
}
245250

0 commit comments

Comments
 (0)