2017-01-09 23:09:23 +00:00
|
|
|
import * as ActionTypes from '../../../constants';
|
|
|
|
|
|
|
|
const consoleMax = 200;
|
|
|
|
const initialState = [];
|
2017-02-22 19:29:35 +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];
|
|
|
|
messages.forEach((message) => {
|
|
|
|
message.id = messageId;
|
|
|
|
messageId += 1;
|
|
|
|
});
|
|
|
|
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;
|