diff options
Diffstat (limited to 'web/src/js')
| -rw-r--r-- | web/src/js/ducks/settings.js | 44 | 
1 files changed, 8 insertions, 36 deletions
| diff --git a/web/src/js/ducks/settings.js b/web/src/js/ducks/settings.js index 37ff04de..6de1c2af 100644 --- a/web/src/js/ducks/settings.js +++ b/web/src/js/ducks/settings.js @@ -1,31 +1,24 @@ -import { StoreCmds } from '../actions'  import { addLogEntry } from './eventLog'  export const WS_MSG_TYPE = 'settings' -export const WS_MSG_CMD_RESET = 'reset'  export const WS_MSG_CMD_UPDATE = 'update'  export const BEGIN_FETCH = 'SETTINGS_BEGIN_FETCH'  export const FETCHED = 'SETTINGS_FETCHED' -export const RESET = 'SETTINGS_RESET' -export const FETCH_ERROR = 'SETTINGS_FETCH_ERROR'  export const RECV_WS_MSG = 'SETTINGS_RECV_WS_MSG' -const defaultState = { settings: {}, pendings: null, req: null } +const defaultState = { settings: {}, pendings: null }  export default function reduce(state = defaultState, action) {      switch (action.type) {          case BEGIN_FETCH: -            return { ...state, pendings: [], req: action.req } +            return { ...state, pendings: [] }          case FETCHED:              const pendings = state.pendings || []              return { ...state, pendings: null, settings: pendings.reduce(reduceData, action.data) } -        case RESET: -            return { ...state, pendings: null, settings: action.data || {} } -          case RECV_WS_MSG:              if (state.pendings) {                  return { ...state, pendings: state.pendings.concat(action) } @@ -40,11 +33,8 @@ export default function reduce(state = defaultState, action) {  function reduceData(data, action) {      switch (action.cmd) { -        case WS_MSG_CMD_RESET: -            return action.data || {} -          case WS_MSG_CMD_UPDATE: -            return _.merge({}, data, action.data) +            return { ...data, ...action.data }          default:              return data @@ -53,40 +43,22 @@ function reduceData(data, action) {  export function fetch() {      return dispatch => { -        const req = $.getJSON('/settings') +        dispatch({ type: BEGIN_FETCH }) +        return $.getJSON('/settings')              .done(msg => dispatch(handleFetchResponse(msg.data)))              .fail(error => dispatch(handleFetchError(error))); - -        dispatch({ type: BEGIN_FETCH, req }) - -        return req      }  }  export function handleWsMsg(msg) { -    return (dispatch, getState) => { -        if (msg.cmd !== StoreCmds.RESET) { -            return dispatch({ type: RECV_WS_MSG, cmd: msg.cmd, data: msg.data }) -        } -        const req = getState().settings.req -        if (req) { -            req.abort() -        } -        dispatch(reset(msg.data)) -    } +    return { type: RECV_WS_MSG, cmd: msg.cmd, data: msg.data }  }  export function handleFetchResponse(data) {      return { type: FETCHED, data }  } -export function reset(data) { -    return { type: RESET, data } -} -  export function handleFetchError(error) { -    return (dispatch, getState) => { -        dispatch(addLogEntry(error.stack || error.message || error)) -        dispatch({ type: FETCH_ERROR, error }) -    } +    // @todo let eventLog subscribe to SettingsActions.FETCH_ERROR +    return addLogEntry(error.stack || error.message || error)  } | 
