2017-01-09 23:09:23 +00:00
|
|
|
import * as ActionTypes from '../../../constants';
|
|
|
|
|
2018-10-25 22:03:45 +00:00
|
|
|
const consoleMax = 500;
|
2017-01-09 23:09:23 +00:00
|
|
|
const initialState = [];
|
2018-11-15 20:55:02 +00:00
|
|
|
let messageId = 0;
|
2017-01-09 23:09:23 +00:00
|
|
|
|
|
|
|
const console = (state = initialState, action) => {
|
2017-02-22 19:29:35 +00:00
|
|
|
let messages;
|
2017-01-09 23:09:23 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case ActionTypes.CONSOLE_EVENT:
|
2017-02-22 19:29:35 +00:00
|
|
|
messages = [...action.event];
|
2018-11-15 20:55:02 +00:00
|
|
|
messages.forEach((message) => {
|
|
|
|
message.id = messageId;
|
|
|
|
messageId += 1;
|
|
|
|
});
|
2017-02-22 19:29:35 +00:00
|
|
|
return state.concat(messages).slice(-consoleMax);
|
2017-01-09 23:09:23 +00:00
|
|
|
case ActionTypes.CLEAR_CONSOLE:
|
|
|
|
return [];
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default console;
|