From ec83df258c49bb953810d29eb2239811bad97975 Mon Sep 17 00:00:00 2001 From: Andy Edwards Date: Tue, 22 Sep 2015 13:05:23 -0500 Subject: [PATCH] implement action-transformer --- build/createLogger.js | 13 +++++++++---- src/createLogger.js | 13 ++++++++----- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/build/createLogger.js b/build/createLogger.js index 4728a41..f670a34 100644 --- a/build/createLogger.js +++ b/build/createLogger.js @@ -35,6 +35,10 @@ function createLogger() { var transformer = _options$transformer === undefined ? function (state) { return state; } : _options$transformer; + var _options$actionTransformer = options.actionTransformer; + var actionTransformer = _options$actionTransformer === undefined ? function (xAction) { + return xAction; + } : _options$actionTransformer; var _options$timestamp = options.timestamp; var timestamp = _options$timestamp === undefined ? true : _options$timestamp; var _options$duration = options.duration; @@ -66,10 +70,11 @@ function createLogger() { if (duration) { formattedDuration = ' in ' + took.toFixed(2) + ' ms'; } + var xAction = actionTransformer(action); var actionType = String(action.type); - var message = 'action ' + actionType + formattedTime + formattedDuration; + var message = 'xAction ' + actionType + formattedTime + formattedDuration; - var isCollapsed = typeof collapsed === 'function' ? collapsed(getState, action) : collapsed; + var isCollapsed = typeof collapsed === 'function' ? collapsed(getState, xAction) : collapsed; if (isCollapsed) { try { @@ -87,11 +92,11 @@ function createLogger() { if (level) { console[level]('%c prev state', 'color: #9E9E9E; font-weight: bold', prevState); - console[level]('%c action', 'color: #03A9F4; font-weight: bold', action); + console[level]('%c xAction', 'color: #03A9F4; font-weight: bold', xAction); console[level]('%c next state', 'color: #4CAF50; font-weight: bold', nextState); } else { console.log('%c prev state', 'color: #9E9E9E; font-weight: bold', prevState); - console.log('%c action', 'color: #03A9F4; font-weight: bold', action); + console.log('%c xAction', 'color: #03A9F4; font-weight: bold', xAction); console.log('%c next state', 'color: #4CAF50; font-weight: bold', nextState); } diff --git a/src/createLogger.js b/src/createLogger.js index 32335f5..2b7de43 100644 --- a/src/createLogger.js +++ b/src/createLogger.js @@ -15,7 +15,9 @@ const timer = typeof performance !== 'undefined' && typeof performance.now === ' function createLogger(options = {}) { return ({ getState }) => (next) => (action) => { - const { level, collapsed, predicate, logger, transformer = state => state, timestamp = true, duration = false } = options; + const { level, collapsed, predicate, logger, transformer = state => state, + actionTransformer = xAction => xAction, timestamp = true, + duration = false } = options; const console = logger || window.console; // exit if console undefined @@ -42,11 +44,12 @@ function createLogger(options = {}) { if (duration) { formattedDuration = ` in ${took.toFixed(2)} ms`; } + const xAction = actionTransformer(action); const actionType = String(action.type); - const message = `action ${actionType}${formattedTime}${formattedDuration}`; + const message = `xAction ${actionType}${formattedTime}${formattedDuration}`; const isCollapsed = (typeof collapsed === 'function') ? - collapsed(getState, action) : + collapsed(getState, xAction) : collapsed; if (isCollapsed) { @@ -65,11 +68,11 @@ function createLogger(options = {}) { if (level) { console[level](`%c prev state`, `color: #9E9E9E; font-weight: bold`, prevState); - console[level](`%c action`, `color: #03A9F4; font-weight: bold`, action); + console[level](`%c xAction`, `color: #03A9F4; font-weight: bold`, xAction); console[level](`%c next state`, `color: #4CAF50; font-weight: bold`, nextState); } else { console.log(`%c prev state`, `color: #9E9E9E; font-weight: bold`, prevState); - console.log(`%c action`, `color: #03A9F4; font-weight: bold`, action); + console.log(`%c xAction`, `color: #03A9F4; font-weight: bold`, xAction); console.log(`%c next state`, `color: #4CAF50; font-weight: bold`, nextState); }