Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions build/createLogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
}

Expand Down
13 changes: 8 additions & 5 deletions src/createLogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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);
}

Expand Down