[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

@ -3,16 +3,15 @@ import reduceList, * as listActions from './utils/list'
import reduceView, * as viewActions from './utils/view' import reduceView, * as viewActions from './utils/view'
import * as websocketActions from './websocket' import * as websocketActions from './websocket'
export const WS_MSG_TYPE = 'UPDATE_LOG' export const WS_MSG_TYPE = 'UPDATE_LOG'
export const ADD = 'EVENTLOG_ADD'
export const REQUEST = 'EVENTLOG_REQUEST'
export const RECEIVE = 'EVENTLOG_RECEIVE'
export const TOGGLE_VISIBILITY = 'EVENTLOG_TOGGLE_VISIBILITY' export const TOGGLE_VISIBILITY = 'EVENTLOG_TOGGLE_VISIBILITY'
export const TOGGLE_FILTER = 'EVENTLOG_TOGGLE_FILTER' export const TOGGLE_FILTER = 'EVENTLOG_TOGGLE_FILTER'
export const ADD = 'EVENTLOG_ADD' export const UNKNOWN_CMD = 'EVENTLOG_UNKNOWN_CMD'
export const WS_MSG = 'EVENTLOG_WS_MSG' export const FETCH_ERROR = 'EVENTLOG_FETCH_ERROR'
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 = { const defaultState = {
logId: 0, logId: 0,
@ -26,7 +25,10 @@ export default function reduce(state = defaultState, action) {
switch (action.type) { switch (action.type) {
case TOGGLE_VISIBILITY: case TOGGLE_VISIBILITY:
return { ...state, visible: !state.visible } return {
...state,
visible: !state.visible
}
case TOGGLE_FILTER: case TOGGLE_FILTER:
const filters = { ...state.filters, [action.filter]: !state.filters[action.filter] } const filters = { ...state.filters, [action.filter]: !state.filters[action.filter] }

View File

@ -3,17 +3,16 @@ import reduceList, * as listActions from './utils/list'
import reduceViews, * as viewsActions from './views' import reduceViews, * as viewsActions from './views'
import * as websocketActions from './websocket' import * as websocketActions from './websocket'
export const WS_MSG_TYPE = 'UPDATE_FLOWS' export const WS_MSG_TYPE = 'UPDATE_FLOWS'
export const ADD = 'FLOWS_ADD' export const ADD = 'FLOWS_ADD'
export const UPDATE = 'FLOWS_UPDATE' export const UPDATE = 'FLOWS_UPDATE'
export const REMOVE = 'FLOWS_REMOVE' export const REMOVE = 'FLOWS_REMOVE'
export const REQUEST = 'FLOWS_REQUEST' export const REQUEST = 'FLOWS_REQUEST'
export const RECEIVE = 'FLOWS_RECEIVE' export const RECEIVE = 'FLOWS_RECEIVE'
export const WS_MSG = 'FLOWS_WS_MSG'
export const REQUEST_ACTION = 'FLOWS_REQUEST_ACTION' export const REQUEST_ACTION = 'FLOWS_REQUEST_ACTION'
export const FETCH_ERROR = 'FLOWS_FETCH_ERROR' export const UNKNOWN_CMD = 'FLOWS_UNKNOWN_CMD'
export const UNKNOWN_CMD = 'FLOWS_UNKNOWN_CMD' export const FETCH_ERROR = 'FLOWS_FETCH_ERROR'
const defaultState = { const defaultState = {
list: null, list: null,
@ -33,8 +32,8 @@ export default function reduce(state = defaultState, action) {
case UPDATE: case UPDATE:
return { return {
...state, ...state,
list: reduceList(state.list, listActions.update(action.item.id, action.item)), list: reduceList(state.list, listActions.update(action.id, action.item)),
views: reduceViews(state.views, viewsActions.update(action.item.id, action.item)), views: reduceViews(state.views, viewsActions.update(action.id, action.item)),
} }
case REMOVE: 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 * @private
*/ */