[web] ws methods

This commit is contained in:
Jason 2016-06-23 23:56:24 +08:00
parent 84683e7abb
commit bd4cf8fef2
2 changed files with 42 additions and 20 deletions

View File

@ -5,14 +5,13 @@ import * as websocketActions from './websocket'
export const WS_MSG_TYPE = 'UPDATE_LOG'
export const TOGGLE_VISIBILITY = 'EVENTLOG_TOGGLE_VISIBILITY'
export const TOGGLE_FILTER = 'EVENTLOG_TOGGLE_FILTER'
export const ADD = 'EVENTLOG_ADD'
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 TOGGLE_VISIBILITY = 'EVENTLOG_TOGGLE_VISIBILITY'
export const TOGGLE_FILTER = 'EVENTLOG_TOGGLE_FILTER'
export const UNKNOWN_CMD = 'EVENTLOG_UNKNOWN_CMD'
export const FETCH_ERROR = 'EVENTLOG_FETCH_ERROR'
const defaultState = {
logId: 0,
@ -26,7 +25,10 @@ export default function reduce(state = defaultState, action) {
switch (action.type) {
case TOGGLE_VISIBILITY:
return { ...state, visible: !state.visible }
return {
...state,
visible: !state.visible
}
case TOGGLE_FILTER:
const filters = { ...state.filters, [action.filter]: !state.filters[action.filter] }

View File

@ -10,10 +10,9 @@ export const UPDATE = 'FLOWS_UPDATE'
export const REMOVE = 'FLOWS_REMOVE'
export const REQUEST = 'FLOWS_REQUEST'
export const RECEIVE = 'FLOWS_RECEIVE'
export const WS_MSG = 'FLOWS_WS_MSG'
export const REQUEST_ACTION = 'FLOWS_REQUEST_ACTION'
export const FETCH_ERROR = 'FLOWS_FETCH_ERROR'
export const UNKNOWN_CMD = 'FLOWS_UNKNOWN_CMD'
export const FETCH_ERROR = 'FLOWS_FETCH_ERROR'
const defaultState = {
list: null,
@ -33,8 +32,8 @@ export default function reduce(state = defaultState, action) {
case UPDATE:
return {
...state,
list: reduceList(state.list, listActions.update(action.item.id, action.item)),
views: reduceViews(state.views, viewsActions.update(action.item.id, action.item)),
list: reduceList(state.list, listActions.update(action.id, action.item)),
views: reduceViews(state.views, viewsActions.update(action.id, action.item)),
}
case REMOVE:
@ -188,6 +187,27 @@ export function fetchData() {
}
}
/**
* @private
*/
export function add(item) {
return { type: ADD, item }
}
/**
* @private
*/
export function update(id, item) {
return { type: UPDATE, id, item }
}
/**
* @private
*/
export function remove(id) {
return { type: REMOVE, id }
}
/**
* @private
*/