Skip to content

Commit 621e261

Browse files
refactor console reducers and actions using redux toolkit
1 parent ae8f517 commit 621e261

File tree

3 files changed

+15
-27
lines changed

3 files changed

+15
-27
lines changed

client/constants.js

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

56-
export const CONSOLE_EVENT = 'CONSOLE_EVENT';
57-
export const CLEAR_CONSOLE = 'CLEAR_CONSOLE';
5856
export const EXPAND_CONSOLE = 'EXPAND_CONSOLE';
5957
export const COLLAPSE_CONSOLE = 'COLLAPSE_CONSOLE';
6058

client/modules/IDE/actions/console.js

+2-13
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
import * as ActionTypes from '../../../constants';
1+
import { consoleActions } from '../reducers/console';
22

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-
}
3+
export const { dispatchConsoleEvent, clearConsole } = consoleActions;
+13-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
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.event];
1112
return state.concat(messages).slice(-consoleMax);
12-
case ActionTypes.CLEAR_CONSOLE:
13-
return [];
14-
default:
15-
return state;
13+
},
14+
clearConsole: (state, action) => []
1615
}
17-
};
16+
});
1817

19-
export default console;
18+
export const consoleActions = consoleSlice.actions;
19+
20+
export default consoleSlice.reducer;

0 commit comments

Comments
 (0)