This reducer is too heavy. It is responsible for 3 different entities: boards, lists and…
- User
This reducer is too heavy. It is responsible for 3 different entities: boards, lists and tasks Please try to create one reducer per entity import { style } from '@vanilla-extract/css';
export const modalOverlay = style({ position: 'fixed', top: 0, left: 0, width: '100%', height: '100%', backgroundColor: 'rgba(0, 0, 0, 0.5)', display: 'flex', alignItems: 'center', justifyContent: 'center', zIndex: 1000 });
export const modalContent = style({ backgroundColor: '#fff', padding: '20px', width: '500px', borderRadius: '4px', position: 'relative', boxSizing: 'border-box' });
export const closeButton = style({ position: 'absolute', top: '10px', right: '10px', background: 'none', border: 'none', fontSize: '24px', cursor: 'pointer' });
export const modalTitle = style({ marginBottom: '15px', fontSize: '18px', fontWeight: 'bold' });
export const descriptionInput = style({ width: '100%', height: '150px', padding: '10px', fontSize: '14px', marginBottom: '15px', border: '1px solid #ccc', borderRadius: '3px', boxSizing: 'border-box', resize: 'vertical' });
export const saveButton = style({ backgroundColor: '#5aac44', color: '#fff', border: 'none', padding: '10px 15px', cursor: 'pointer', borderRadius: '3px', fontSize: '14px', selectors: { '&:hover': { backgroundColor: '#519839' } } });
- Assistant
To separate the responsibilities into different reducers for
boards,lists, andtasks, you can create individual reducers for each entity and then combine them usingcombineReducersfrom Redux. Below is an example of how you can organize these reducers:Step 1: Create Individual Reducers
-
Board Reducer:
// reducers/boardReducer.js const initialState = { boards: [] }; const boardReducer = (state = initialState, action) => { switch (action.type) { case 'ADD_BOARD': return { ...state, boards: [...state.boards, action.payload] }; // Add more board-specific actions here default: return state; } }; export default boardReducer; -
List Reducer:
// reducers/listReducer.js const initialState = { lists: [] }; const listReducer = (state = initialState, action) => { switch (action.type) { case 'ADD_LIST': return { ...state, lists: [...state.lists, action.payload] }; // Add more list-specific actions here default: return state; } }; export default listReducer; -
Task Reducer:
// reducers/taskReducer.js const initialState = { tasks: [] }; const taskReducer = (state = initialState, action) => { switch (action.type) { case 'ADD_TASK': return { ...state, tasks: [...state.tasks, action.payload] }; // Add more task-specific actions here default: return state; } }; export default taskReducer;
Step 2: Combine Reducers
After creating each specific reducer, combine them into a root reducer:
// reducers/index.js import { combineReducers } from 'redux'; import boardReducer from './boardReducer'; import listReducer from './listReducer'; import taskReducer from './taskReducer'; const rootReducer = combineReducers({ boards: boardReducer, lists: listReducer, tasks: taskReducer }); export default rootReducer;Step 3: Configure the Store
Use the combined reducer in your Redux store configuration:
// store.js import { createStore } from 'redux'; import rootReducer from './reducers'; const store = createStore(rootReducer); export default store;By structuring your reducers in this way, you've made your codebase cleaner and more maintainable, which allows for easier scaling and testing. Each reducer now manages its own slice of the state related to its entity (
boards,lists, andtasks). -