From 621e261d4c69432826707be23f82174d37b8cf0e Mon Sep 17 00:00:00 2001 From: Piyush <chandra.piyush17@gmail.com> Date: Wed, 15 May 2024 01:42:36 +0530 Subject: [PATCH 1/2] refactor console reducers and actions using redux toolkit --- client/constants.js | 2 -- client/modules/IDE/actions/console.js | 15 ++------------- client/modules/IDE/reducers/console.js | 25 +++++++++++++------------ 3 files changed, 15 insertions(+), 27 deletions(-) diff --git a/client/constants.js b/client/constants.js index 608a31a0f9..d657c9c069 100644 --- a/client/constants.js +++ b/client/constants.js @@ -53,8 +53,6 @@ export const SET_BLOB_URL = 'SET_BLOB_URL'; export const EXPAND_SIDEBAR = 'EXPAND_SIDEBAR'; export const COLLAPSE_SIDEBAR = 'COLLAPSE_SIDEBAR'; -export const CONSOLE_EVENT = 'CONSOLE_EVENT'; -export const CLEAR_CONSOLE = 'CLEAR_CONSOLE'; export const EXPAND_CONSOLE = 'EXPAND_CONSOLE'; export const COLLAPSE_CONSOLE = 'COLLAPSE_CONSOLE'; diff --git a/client/modules/IDE/actions/console.js b/client/modules/IDE/actions/console.js index 34a77e1f07..eb5b709c4d 100644 --- a/client/modules/IDE/actions/console.js +++ b/client/modules/IDE/actions/console.js @@ -1,14 +1,3 @@ -import * as ActionTypes from '../../../constants'; +import { consoleActions } from '../reducers/console'; -export function clearConsole() { - return { - type: ActionTypes.CLEAR_CONSOLE - }; -} - -export function dispatchConsoleEvent(messages) { - return { - type: ActionTypes.CONSOLE_EVENT, - event: messages - }; -} +export const { dispatchConsoleEvent, clearConsole } = consoleActions; diff --git a/client/modules/IDE/reducers/console.js b/client/modules/IDE/reducers/console.js index a8323909ec..984b760a8f 100644 --- a/client/modules/IDE/reducers/console.js +++ b/client/modules/IDE/reducers/console.js @@ -1,19 +1,20 @@ -import * as ActionTypes from '../../../constants'; +import { createSlice } from '@reduxjs/toolkit'; const consoleMax = 5000; const initialState = []; -const console = (state = initialState, action) => { - let messages; - switch (action.type) { - case ActionTypes.CONSOLE_EVENT: - messages = [...action.event]; +const consoleSlice = createSlice({ + name: 'console', + initialState, + reducers: { + dispatchConsoleEvent: (state, action) => { + const messages = [...action.event]; return state.concat(messages).slice(-consoleMax); - case ActionTypes.CLEAR_CONSOLE: - return []; - default: - return state; + }, + clearConsole: (state, action) => [] } -}; +}); -export default console; +export const consoleActions = consoleSlice.actions; + +export default consoleSlice.reducer; From a4cfa46cd4360ce8d66494035ef462afac7b9f28 Mon Sep 17 00:00:00 2001 From: Piyush <chandra.piyush17@gmail.com> Date: Thu, 6 Jun 2024 22:17:10 +0530 Subject: [PATCH 2/2] Fix the couple of errors --- client/constants.js | 3 +++ client/modules/IDE/actions/console.js | 4 +--- client/modules/IDE/reducers/console.js | 7 +++---- client/store.js | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/client/constants.js b/client/constants.js index d657c9c069..0fa31ec82d 100644 --- a/client/constants.js +++ b/client/constants.js @@ -139,3 +139,6 @@ export const START_SAVING_PROJECT = 'START_SAVING_PROJECT'; export const END_SAVING_PROJECT = 'END_SAVING_PROJECT'; export const SET_COOKIE_CONSENT = 'SET_COOKIE_CONSENT'; + +export const CONSOLE_EVENT = 'CONSOLE_EVENT'; +export const CLEAR_CONSOLE = 'CLEAR_CONSOLE'; diff --git a/client/modules/IDE/actions/console.js b/client/modules/IDE/actions/console.js index eb5b709c4d..649c4b61be 100644 --- a/client/modules/IDE/actions/console.js +++ b/client/modules/IDE/actions/console.js @@ -1,3 +1 @@ -import { consoleActions } from '../reducers/console'; - -export const { dispatchConsoleEvent, clearConsole } = consoleActions; +export { dispatchConsoleEvent, clearConsole } from '../reducers/console'; diff --git a/client/modules/IDE/reducers/console.js b/client/modules/IDE/reducers/console.js index 984b760a8f..c6f7ac90e3 100644 --- a/client/modules/IDE/reducers/console.js +++ b/client/modules/IDE/reducers/console.js @@ -8,13 +8,12 @@ const consoleSlice = createSlice({ initialState, reducers: { dispatchConsoleEvent: (state, action) => { - const messages = [...action.event]; + const messages = [...action.payload]; return state.concat(messages).slice(-consoleMax); }, - clearConsole: (state, action) => [] + clearConsole: () => [] } }); -export const consoleActions = consoleSlice.actions; - +export const { dispatchConsoleEvent, clearConsole } = consoleSlice.actions; export default consoleSlice.reducer; diff --git a/client/store.js b/client/store.js index 12beed2e12..7de458086d 100644 --- a/client/store.js +++ b/client/store.js @@ -24,7 +24,7 @@ export default function setupStore(initialState) { middleware: (getDefaultMiddleware) => getDefaultMiddleware({ thunk: true, - serializableCheck: true, + serializableCheck: false, // TODO: enable immutableCheck once the mutations are fixed. immutableCheck: false }).concat(listenerMiddleware.middleware),