UNPKG

@paprika/seducer

Version:

Seducer (simple reducer) is a wrapper on top of React.useReducer, making it easier to use

41 lines (35 loc) 1.75 kB
"use strict"; var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property"); _Object$defineProperty(exports, "__esModule", { value: true }); exports["default"] = logger; /** * Summary: Prints the current processing action via the dev console, with it's previous state and the next state after passing inside the reducer. * * @param {{}} prevState The current state of the store * @param {{}} nextState The next state after being pass through the reducer * @param {{ type: string, payload: any }} action The actions that has being dispatched by the consumer * @param {boolean} isFromInterceptor Let the consoler knowns if the actions is an original or has been override by the interceptors * * @return {{}} The next state */ function logger(prevState, nextState, action) { var isFromInterceptor = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; console.groupCollapsed("".concat(isFromInterceptor ? "⇢" : "", " action: ").concat(action.type, " @ ").concat(new Date().toLocaleTimeString())); // we don't want to showcase payload if it's undefined // eslint-disable-next-line no-param-reassign if (typeof action.payload === "undefined") delete action.payload; console.log("%c\u2219 prev state", styles.prev, prevState); console.log("%c\u2219 action", styles.action, action); console.log("%c\u2726 next state", styles.next, nextState); console.log("%c\u2219 finished @ ".concat(new Date().toLocaleTimeString()), styles.finished); console.groupEnd(); return nextState; } var styles = { prev: "color: #F312A7;", action: "color: #A5DE5D;", next: "color: #25D8FF; font-weight:bold;", finished: "color: #BEBEBE;" }; //# sourceMappingURL=logger.js.map