Skip to content

Commit 934fb07

Browse files
authored
Merge pull request #3119 from PiyushChandra17/piyush/refactor-console-redux-toolkit
refactor console reducers and actions using redux toolkit
2 parents 298c51d + a2e5959 commit 934fb07

File tree

4 files changed

+17
-29
lines changed

4 files changed

+17
-29
lines changed

client/constants.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ export const SET_BLOB_URL = 'SET_BLOB_URL';
5252
export const EXPAND_SIDEBAR = 'EXPAND_SIDEBAR';
5353
export const COLLAPSE_SIDEBAR = 'COLLAPSE_SIDEBAR';
5454

55-
export const CONSOLE_EVENT = 'CONSOLE_EVENT';
56-
export const CLEAR_CONSOLE = 'CLEAR_CONSOLE';
5755
export const EXPAND_CONSOLE = 'EXPAND_CONSOLE';
5856
export const COLLAPSE_CONSOLE = 'COLLAPSE_CONSOLE';
5957

@@ -140,3 +138,6 @@ export const START_SAVING_PROJECT = 'START_SAVING_PROJECT';
140138
export const END_SAVING_PROJECT = 'END_SAVING_PROJECT';
141139

142140
export const SET_COOKIE_CONSENT = 'SET_COOKIE_CONSENT';
141+
142+
export const CONSOLE_EVENT = 'CONSOLE_EVENT';
143+
export const CLEAR_CONSOLE = 'CLEAR_CONSOLE';

client/modules/IDE/actions/console.js

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1 @@
1-
import * as ActionTypes from '../../../constants';
2-
3-
export function clearConsole() {
4-
return {
5-
type: ActionTypes.CLEAR_CONSOLE
6-
};
7-
}
8-
9-
export function dispatchConsoleEvent(messages) {
10-
return {
11-
type: ActionTypes.CONSOLE_EVENT,
12-
event: messages
13-
};
14-
}
1+
export { dispatchConsoleEvent, clearConsole } from '../reducers/console';
+12-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import * as ActionTypes from '../../../constants';
1+
import { createSlice } from '@reduxjs/toolkit';
22

33
const consoleMax = 5000;
44
const initialState = [];
55

6-
const console = (state = initialState, action) => {
7-
let messages;
8-
switch (action.type) {
9-
case ActionTypes.CONSOLE_EVENT:
10-
messages = [...action.event];
6+
const consoleSlice = createSlice({
7+
name: 'console',
8+
initialState,
9+
reducers: {
10+
dispatchConsoleEvent: (state, action) => {
11+
const messages = [...action.payload];
1112
return state.concat(messages).slice(-consoleMax);
12-
case ActionTypes.CLEAR_CONSOLE:
13-
return [];
14-
default:
15-
return state;
13+
},
14+
clearConsole: () => []
1615
}
17-
};
16+
});
1817

19-
export default console;
18+
export const { dispatchConsoleEvent, clearConsole } = consoleSlice.actions;
19+
export default consoleSlice.reducer;

client/store.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default function setupStore(initialState) {
2424
middleware: (getDefaultMiddleware) =>
2525
getDefaultMiddleware({
2626
thunk: true,
27-
serializableCheck: true,
27+
serializableCheck: false,
2828
// TODO: enable immutableCheck once the mutations are fixed.
2929
immutableCheck: false
3030
}).concat(listenerMiddleware.middleware),

0 commit comments

Comments
 (0)