From cedac98b700efc6d1a38378e673626f07bff916d Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 16 Jun 2016 17:21:57 +0800 Subject: [PATCH] [web] promot reduce --- mitmproxy/web/static/app.js | 4 ++-- web/src/js/ducks/settings.js | 35 +++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/mitmproxy/web/static/app.js b/mitmproxy/web/static/app.js index 572ea373b..27f31b454 100644 --- a/mitmproxy/web/static/app.js +++ b/mitmproxy/web/static/app.js @@ -101,9 +101,9 @@ "use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(exports,"__esModule",{value:!0});var _redux=require("redux"),_eventLog=require("./eventLog"),_eventLog2=_interopRequireDefault(_eventLog),_websocket=require("./websocket"),_websocket2=_interopRequireDefault(_websocket),_flows=require("./flows"),_flows2=_interopRequireDefault(_flows),_settings=require("./settings"),_settings2=_interopRequireDefault(_settings),_ui=require("./ui"),_ui2=_interopRequireDefault(_ui),rootReducer=(0,_redux.combineReducers)({eventLog:_eventLog2["default"],websocket:_websocket2["default"],flows:_flows2["default"],settings:_settings2["default"],ui:_ui2["default"]});exports["default"]=rootReducer; },{"./eventLog":32,"./flows":33,"./settings":35,"./ui":36,"./websocket":39,"redux":"redux"}],35:[function(require,module,exports){ -"use strict";function reduceData(e,t){switch(t.cmd){case WS_MSG_CMD_RESET:return t.data||{};case WS_MSG_CMD_UPDATE:return _.merge({},e.settings,t.data);default:return e}}function reduce(){var e=arguments.length<=0||void 0===arguments[0]?defaultState:arguments[0],t=arguments[1];switch(t.type){case BEGIN_FETCH:return _extends({},e,{pendings:[],req:t.req});case FETCH_SETTINGS:var r=e.pendings||[];return _extends({},e,{pendings:null,settings:r.reduce(reduceData,data)});case RECV_WS_MSG:return e.pendings?_extends({},e,{pendings:e.pendings.concat(t)}):_extends({},e,{settings:reduceData(e.settings,t)});default:return e}}function fetch(){var e=this;return function(t){var r=$.getJSON("/"+e.type).done(function(e){return t(reset(e.data))}).fail(function(e){return t(handleFetchError(e))});return t({type:BEGIN_FETCH,req:r}),r}}function handleWsMsg(e){return function(t,r){if(e.cmd!==STORE_CMDS_RESET)return t({type:RECV_WS_MSG,cmd:e.cmd,data:e.data});var n=r().settings.req;n&&n.abort(),t(reset(e.data))}}function reset(e){return{type:FETCH_SETTINGS,data:e}}function handleFetchError(e){return console.error(e),{type:FETCH_ERROR,error:e}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.RECV_WS_MSG=exports.FETCH_ERROR=exports.FETCH_SETTINGS=exports.BEGIN_FETCH=exports.WS_MSG_CMD_UPDATE=exports.WS_MSG_CMD_RESET=exports.WS_MSG_TYPE=void 0;var _extends=Object.assign||function(e){for(var t=1;t { const req = $.getJSON('/' + this.type) @@ -76,6 +77,8 @@ export function reset(data) { } export function handleFetchError(error) { - console.error(error) - return { type: FETCH_ERROR, error } + return (dispatch, getState) => { + dispatch(addLogEntry(error.stack || error.message || error)) + dispatch({ type: FETCH_ERROR, error }) + } }