-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathreducer.js
More file actions
40 lines (36 loc) · 950 Bytes
/
Copy pathreducer.js
File metadata and controls
40 lines (36 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* eslint-disable import/prefer-default-export */
// eslint-disable-next-line consistent-return
export const reducer = (state, action) => {
if (action.type === "CHANGE_CELL") {
const stateCells = state.cells.map((cell) => {
if (cell.id === action.payload.id) {
return action.payload;
}
return cell;
});
return {
...state,
cells: stateCells,
};
}
if (action.type === "ADD_CELL") {
const newCell = [...state.cells];
newCell.splice(action.currentId, 0, action.payload);
return {
...state,
cells: newCell,
};
}
if (action.type === "DELETE_CELL") {
if (state.cells.length > 1) {
const newCell = state.cells.filter((cell) => {
return cell.id !== action.payload;
});
return { ...state, cells: newCell };
}
return { ...state };
}
if (action.type === "LOAD_NOTE") {
return { ...state, cells: action.payload };
}
};