aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/ducks/eventLog.js
diff options
context:
space:
mode:
authorJason <jason.daurus@gmail.com>2016-06-23 23:44:53 +0800
committerJason <jason.daurus@gmail.com>2016-06-23 23:44:53 +0800
commitf50dc62249f8873d3704738c82580b9cf2369750 (patch)
treee1d91483d226ebe2a7d0522ea9d2dab7f0508f83 /web/src/js/ducks/eventLog.js
parent5adb7a54fd689f69d5734d64fea0d3de43f4ce6d (diff)
downloadmitmproxy-f50dc62249f8873d3704738c82580b9cf2369750.tar.gz
mitmproxy-f50dc62249f8873d3704738c82580b9cf2369750.tar.bz2
mitmproxy-f50dc62249f8873d3704738c82580b9cf2369750.zip
[web] fix eventLog ducks
Diffstat (limited to 'web/src/js/ducks/eventLog.js')
-rw-r--r--web/src/js/ducks/eventLog.js54
1 files changed, 31 insertions, 23 deletions
diff --git a/web/src/js/ducks/eventLog.js b/web/src/js/ducks/eventLog.js
index 61b5882f..aa472592 100644
--- a/web/src/js/ducks/eventLog.js
+++ b/web/src/js/ducks/eventLog.js
@@ -1,6 +1,7 @@
-import { fetchApi as fetch } from '../utils'
-import { CMD_RESET as WS_CMD_RESET } from './websocket'
+import { fetchApi } from '../utils'
import reduceList, * as listActions from './utils/list'
+import reduceView, * as viewActions from './utils/view'
+import * as websocketActions from './websocket'
export const WS_MSG_TYPE = 'UPDATE_LOG'
@@ -11,13 +12,14 @@ export const WS_MSG = 'EVENTLOG_WS_MSG'
export const REQUEST = 'EVENTLOG_REQUEST'
export const RECEIVE = 'EVENTLOG_RECEIVE'
export const FETCH_ERROR = 'EVENTLOG_FETCH_ERROR'
+export const UNKNOWN_CMD = 'EVENTLOG_UNKNOWN_CMD'
const defaultState = {
logId: 0,
visible: false,
filters: { debug: false, info: true, web: true },
- list: reduceList(undefined, { type: Symbol('EVENTLOG_INIT_LIST') }),
- view: reduceView(undefined, viewActions.init([]))
+ list: null,
+ view: null,
}
export default function reduce(state = defaultState, action) {
@@ -31,40 +33,39 @@ export default function reduce(state = defaultState, action) {
return {
...state,
filters,
- view: reduceView(state.list, listActions.updateFilter(e => filters[e.level], state.list))
+ view: reduceView(state.view, viewActions.updateFilter(state.list, log => filters[log.level])),
}
case ADD:
- return {
- ...state,
- logId: state.logId + 1,
- list: reduceList(state.list, listActions.add({
- id: `log-${state.logId}`,
- message: action.message,
- level: action.level,
- }))
+ const item = {
+ id: `log-${state.logId}`,
+ message: action.message,
+ level: action.level,
}
-
- case WS_MSG:
return {
...state,
- list: reduceList(state.list, listActions.handleWsMsg(action.msg))
+ logId: state.logId + 1,
+ list: reduceList(state.list, listActions.add(item)),
+ view: reduceView(state.view, viewActions.add(item, log => state.filters[log.level])),
}
case REQUEST:
return {
...state,
- list: reduceList(state.list, listActions.request())
+ list: reduceList(state.list, listActions.request()),
}
case RECEIVE:
return {
...state,
- list: reduceList(state.list, listActions.receive(action.list))
+ list: reduceList(state.list, listActions.receive(action.list)),
}
default:
- return state
+ return {
+ ...state,
+ list: reduceList(state.list, action),
+ }
}
}
@@ -97,10 +98,17 @@ export function add(message, level = 'web') {
* @public websocket
*/
export function handleWsMsg(msg) {
- if (msg.cmd === WS_CMD_RESET) {
- return fetchData()
+ switch (msg.cmd) {
+
+ case websocketActions.CMD_ADD:
+ return add(msg.data.message, msg.data.level)
+
+ case websocketActions.CMD_RESET:
+ return fetchData()
+
+ default:
+ return { type: UNKNOWN_CMD, msg }
}
- return { type: WS_MSG, msg }
}
/**
@@ -110,7 +118,7 @@ export function fetchData() {
return dispatch => {
dispatch(request())
- return fetch('/events')
+ return fetchApi('/events')
.then(res => res.json())
.then(json => dispatch(receive(json.data)))
.catch(error => dispatch(fetchError(error)))