diff options
author | Matthew Shao <me@matshao.com> | 2017-07-17 15:28:06 +0800 |
---|---|---|
committer | Matthew Shao <me@matshao.com> | 2017-07-17 15:28:06 +0800 |
commit | c19a184ba2e0327a8df0c2a4631f81f4f40e939b (patch) | |
tree | bcc1553b5c20ff5f52a7cf627df8d8cb6745d387 /web/src/js/ducks/ui/option.js | |
parent | 80091c859a5ce5c209eba3eda351daf62c776593 (diff) | |
download | mitmproxy-c19a184ba2e0327a8df0c2a4631f81f4f40e939b.tar.gz mitmproxy-c19a184ba2e0327a8df0c2a4631f81f4f40e939b.tar.bz2 mitmproxy-c19a184ba2e0327a8df0c2a4631f81f4f40e939b.zip |
[web] Add reducer and actions for option editor.
Diffstat (limited to 'web/src/js/ducks/ui/option.js')
-rw-r--r-- | web/src/js/ducks/ui/option.js | 39 |
1 files changed, 39 insertions, 0 deletions
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 + } +} |