diff options
author | Matthew Shao <me@matshao.com> | 2017-07-17 15:28:06 +0800 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2017-07-17 13:59:25 +0200 |
commit | ec5061327f56c8154a0a5e2ab169a1f371ec62b7 (patch) | |
tree | cc0809dcda0ca73742323e3630362ca5ccbf5ac5 /web/src | |
parent | 6be1c2efb9f477c4cbe05edd5010e78186c8e748 (diff) | |
download | mitmproxy-ec5061327f56c8154a0a5e2ab169a1f371ec62b7.tar.gz mitmproxy-ec5061327f56c8154a0a5e2ab169a1f371ec62b7.tar.bz2 mitmproxy-ec5061327f56c8154a0a5e2ab169a1f371ec62b7.zip |
[web] Add reducer and actions for option editor.
Diffstat (limited to 'web/src')
-rw-r--r-- | web/src/js/ducks/ui/index.js | 4 | ||||
-rw-r--r-- | web/src/js/ducks/ui/option.js | 39 |
2 files changed, 42 insertions, 1 deletions
diff --git a/web/src/js/ducks/ui/index.js b/web/src/js/ducks/ui/index.js index 741671b2..cdee7ebb 100644 --- a/web/src/js/ducks/ui/index.js +++ b/web/src/js/ducks/ui/index.js @@ -2,10 +2,12 @@ import { combineReducers } from 'redux' import flow from './flow' import header from './header' import modal from './modal' +import option from './option' // TODO: Just move ducks/ui/* into ducks/? export default combineReducers({ flow, header, - modal + modal, + option, }) diff --git a/web/src/js/ducks/ui/option.js b/web/src/js/ducks/ui/option.js new file mode 100644 index 00000000..6aba4998 --- /dev/null +++ b/web/src/js/ducks/ui/option.js @@ -0,0 +1,39 @@ +export const OPTION_UPDATE_START = 'UI_OPTION_UPDATE_START' +export const OPTION_UPDATE_SUCCESS = 'UI_OPTION_UPDATE_SUCCESS' +export const OPTION_UPDATE_ERROR = 'UI_OPTION_UPDATE_ERROR' + +const defaultState = { + /* optionName -> {isUpdating, value (client-side), error} */ +} + +export default function reducer(state = defaultState, action) { + switch (action.type) { + case OPTION_UPDATE_START: + return { + ...state, + [action.option]: { + isUpdate: true, + value: action.value, + error: false, + } + } + + case OPTION_UPDATE_SUCCESS: + let s = {...state} + delete s[action.option] + return s + + case OPTION_UPDATE_ERROR: + return { + ...state, + [action.option]: { + ...state[action.option], + isUpdating: false, + error: action.error + } + } + + default: + return state + } +} |