[web] store ws object in symbol property

This commit is contained in:
Jason 2016-06-22 00:51:45 +08:00
parent 0cab9ef1fa
commit 9a7415a58d
2 changed files with 10 additions and 31 deletions

File diff suppressed because one or more lines are too long

View File

@ -4,6 +4,8 @@ import * as eventLogActions from './eventLog'
import * as flowsActions from './flows' import * as flowsActions from './flows'
import * as settingsActions from './settings' import * as settingsActions from './settings'
export const SYM_SOCKET = Symbol('WEBSOCKET_SYM_SOCKET')
export const CONNECT = 'WEBSOCKET_CONNECT' export const CONNECT = 'WEBSOCKET_CONNECT'
export const CONNECTED = 'WEBSOCKET_CONNECTED' export const CONNECTED = 'WEBSOCKET_CONNECTED'
export const DISCONNECT = 'WEBSOCKET_DISCONNECT' export const DISCONNECT = 'WEBSOCKET_DISCONNECT'
@ -18,7 +20,7 @@ export default function reduce(state = defaultState, action) {
switch (action.type) { switch (action.type) {
case CONNECT: case CONNECT:
return { ...state, socket: action.socket } return { ...state, [SYM_SOCKET]: action.socket }
case CONNECTED: case CONNECTED:
return { ...state, connected: true } return { ...state, connected: true }
@ -27,7 +29,7 @@ export default function reduce(state = defaultState, action) {
return { ...state, connected: false } return { ...state, connected: false }
case DISCONNECTED: case DISCONNECTED:
return { ...state, socket: null } return { ...state, [SYM_SOCKET]: null }
default: default:
return state return state
@ -54,7 +56,7 @@ export function connect() {
export function disconnect() { export function disconnect() {
return (dispatch, getState) => { return (dispatch, getState) => {
getState().settings.socket.close() getState().settings[SYM_SOCKET].close()
dispatch({ type: DISCONNECT }) dispatch({ type: DISCONNECT })
} }
} }